Skip to content

Commit ecfa635

Browse files
russcamMpdreamz
authored andcommitted
Update documentation
1 parent d2eecfd commit ecfa635

File tree

38 files changed

+859
-102
lines changed

38 files changed

+859
-102
lines changed

docs/aggregations/bucket/date-histogram/date-histogram-aggregation-usage.asciidoc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,8 @@ A multi-bucket aggregation similar to the histogram except it can only be applie
2121
From a functionality perspective, this histogram supports the same features as the normal histogram.
2222
The main difference is that the interval can be specified by date/time expressions.
2323

24-
NOTE: When specifying a `format` **and** `extended_bounds`, in order for Elasticsearch to be able to parse
25-
the serialized `DateTime` of `extended_bounds` correctly, the `date_optional_time` format is included
24+
NOTE: When specifying a `format` **and** `extended_bounds` or `missing`, in order for Elasticsearch to be able to parse
25+
the serialized `DateTime` of `extended_bounds` or `missing` correctly, the `date_optional_time` format is included
2626
as part of the `format` value.
2727

2828
Be sure to read the Elasticsearch documentation on {ref_current}/search-aggregations-bucket-datehistogram-aggregation.html[Date Histogram Aggregation].

docs/aggregations/bucket/date-range/date-range-aggregation-usage.asciidoc

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ s => s
3838
r => r.To(DateMath.Now.Add(TimeSpan.FromDays(1)).Subtract("30m").RoundTo(TimeUnit.Hour)),
3939
r => r.From(DateMath.Anchored("2012-05-05").Add(TimeSpan.FromDays(1)).Subtract("1m"))
4040
)
41+
.TimeZone("CET")
4142
.Aggregations(childAggs => childAggs
4243
.Terms("project_tags", avg => avg.Field(p => p.Tags))
4344
)
@@ -60,6 +61,7 @@ new SearchRequest<Project>
6061
new DateRangeExpression { To = DateMath.Now.Add(TimeSpan.FromDays(1)).Subtract("30m").RoundTo(TimeUnit.Hour) },
6162
new DateRangeExpression { From = DateMath.Anchored("2012-05-05").Add(TimeSpan.FromDays(1)).Subtract("1m") }
6263
},
64+
TimeZone = "CET",
6365
Aggregations =
6466
new TermsAggregation("project_tags") { Field = Field<Project>(p => p.Tags) }
6567
}
@@ -85,7 +87,8 @@ new SearchRequest<Project>
8587
{
8688
"from": "2012-05-05||+1d-1m"
8789
}
88-
]
90+
],
91+
"time_zone": "CET"
8992
},
9093
"aggs": {
9194
"project_tags": {

docs/aggregations/bucket/geo-distance/geo-distance-aggregation-usage.asciidoc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ new SearchRequest<Project>
8989

9090
[source,csharp]
9191
----
92-
response.IsValid.Should().BeTrue();
92+
response.ShouldBeValid();
9393
var ringsAroundAmsterdam = response.Aggs.GeoDistance("rings_around_amsterdam");
9494
ringsAroundAmsterdam.Should().NotBeNull();
9595
ringsAroundAmsterdam.Buckets.FirstOrDefault(r => r.Key == "*-100.0").Should().NotBeNull();

docs/aggregations/bucket/histogram/histogram-aggregation-usage.asciidoc

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ s => s
2828
.Interval(100)
2929
.Missing(0)
3030
.Order(HistogramOrder.KeyDescending)
31+
.Offset(1.1)
3132
)
3233
)
3334
----
@@ -43,7 +44,8 @@ new SearchRequest<Project>
4344
Field = Field<Project>(p => p.NumberOfCommits),
4445
Interval = 100,
4546
Missing = 0,
46-
Order = HistogramOrder.KeyDescending
47+
Order = HistogramOrder.KeyDescending,
48+
Offset = 1.1
4749
}
4850
}
4951
----
@@ -60,7 +62,8 @@ new SearchRequest<Project>
6062
"missing": 0.0,
6163
"order": {
6264
"_key": "desc"
63-
}
65+
},
66+
"offset": 1.1
6467
}
6568
}
6669
}

docs/aggregations/bucket/sampler/sampler-aggregation-usage.asciidoc

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,5 +82,8 @@ var sample = response.Aggs.Sampler("sample");
8282
sample.Should().NotBeNull();
8383
var sigTags = sample.SignificantTerms("significant_names");
8484
sigTags.Should().NotBeNull();
85+
sigTags.DocCount.Should().BeGreaterThan(0);
86+
if (TestClient.VersionUnderTestSatisfiedBy(">=5.5.0"))
87+
sigTags.BgCount.Should().BeGreaterThan(0);
8588
----
8689

docs/aggregations/bucket/terms/terms-aggregation-usage.asciidoc

Lines changed: 18 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -60,15 +60,15 @@ new SearchRequest<Project>
6060
ShardSize = 100,
6161
ExecutionHint = TermsAggregationExecutionHint.Map,
6262
Missing = "n/a",
63-
Script = new InlineScript("'State of Being: '+_value") { Lang = "groovy" },
63+
Script = new InlineScript("'State of Being: '+_value") {Lang = "groovy"},
6464
Order = new List<TermsOrder>
6565
{
6666
TermsOrder.TermAscending,
6767
TermsOrder.CountDescending
6868
},
6969
Meta = new Dictionary<string, object>
7070
{
71-
{ "foo", "bar" }
71+
{"foo", "bar"}
7272
}
7373
}
7474
}
@@ -113,7 +113,7 @@ new SearchRequest<Project>
113113

114114
[source,csharp]
115115
----
116-
response.IsValid.Should().BeTrue();
116+
response.ShouldBeValid();
117117
var states = response.Aggs.Terms("states");
118118
states.Should().NotBeNull();
119119
states.DocCountErrorUpperBound.Should().HaveValue();
@@ -174,15 +174,15 @@ new SearchRequest<Project>
174174
ShardSize = 100,
175175
ExecutionHint = TermsAggregationExecutionHint.Map,
176176
Missing = "n/a",
177-
Include = new TermsIncludeExclude { Pattern = "(Stable|VeryActive)" },
177+
Include = new TermsIncludeExclude {Pattern = "(Stable|VeryActive)"},
178178
Order = new List<TermsOrder>
179179
{
180180
TermsOrder.TermAscending,
181181
TermsOrder.CountDescending
182182
},
183183
Meta = new Dictionary<string, object>
184184
{
185-
{ "foo", "bar" }
185+
{"foo", "bar"}
186186
}
187187
}
188188
}
@@ -224,7 +224,7 @@ new SearchRequest<Project>
224224

225225
[source,csharp]
226226
----
227-
response.IsValid.Should().BeTrue();
227+
response.ShouldBeValid();
228228
var states = response.Aggs.Terms("states");
229229
states.Should().NotBeNull();
230230
states.DocCountErrorUpperBound.Should().HaveValue();
@@ -260,7 +260,7 @@ s => s
260260
.ShardSize(100)
261261
.ExecutionHint(TermsAggregationExecutionHint.Map)
262262
.Missing("n/a")
263-
.Include(new [] { StateOfBeing.Stable.ToString(), StateOfBeing.VeryActive.ToString() })
263+
.Include(new[] {StateOfBeing.Stable.ToString(), StateOfBeing.VeryActive.ToString()})
264264
.Order(TermsOrder.TermAscending)
265265
.Order(TermsOrder.CountDescending)
266266
.Meta(m => m
@@ -285,15 +285,15 @@ new SearchRequest<Project>
285285
ShardSize = 100,
286286
ExecutionHint = TermsAggregationExecutionHint.Map,
287287
Missing = "n/a",
288-
Include = new TermsIncludeExclude { Values = new[] { StateOfBeing.Stable.ToString(), StateOfBeing.VeryActive.ToString() } },
288+
Include = new TermsIncludeExclude {Values = new[] {StateOfBeing.Stable.ToString(), StateOfBeing.VeryActive.ToString()}},
289289
Order = new List<TermsOrder>
290290
{
291291
TermsOrder.TermAscending,
292292
TermsOrder.CountDescending
293293
},
294294
Meta = new Dictionary<string, object>
295295
{
296-
{ "foo", "bar" }
296+
{"foo", "bar"}
297297
}
298298
}
299299
}
@@ -338,7 +338,7 @@ new SearchRequest<Project>
338338

339339
[source,csharp]
340340
----
341-
response.IsValid.Should().BeTrue();
341+
response.ShouldBeValid();
342342
var states = response.Aggs.Terms("states");
343343
states.Should().NotBeNull();
344344
states.DocCountErrorUpperBound.Should().HaveValue();
@@ -425,7 +425,7 @@ new SearchRequest<Project>
425425

426426
[source,csharp]
427427
----
428-
response.IsValid.Should().BeTrue();
428+
response.ShouldBeValid();
429429
var commits = response.Aggs.Terms<int>("commits");
430430
commits.Should().NotBeNull();
431431
commits.DocCountErrorUpperBound.Should().HaveValue();
@@ -453,6 +453,7 @@ s => s
453453
.Aggregations(a => a
454454
.Terms("commits", st => st
455455
.Field(p => p.NumberOfCommits)
456+
.ShowTermDocCountError()
456457
)
457458
)
458459
----
@@ -466,7 +467,8 @@ new SearchRequest<Project>
466467
Size = 0,
467468
Aggregations = new TermsAggregation("commits")
468469
{
469-
Field = Infer.Field<Project>(p => p.NumberOfCommits),
470+
Field = Field<Project>(p => p.NumberOfCommits),
471+
ShowTermDocCountError = true
470472
}
471473
}
472474
----
@@ -479,7 +481,8 @@ new SearchRequest<Project>
479481
"aggs": {
480482
"commits": {
481483
"terms": {
482-
"field": "numberOfCommits"
484+
"field": "numberOfCommits",
485+
"show_term_doc_count_error": true
483486
}
484487
}
485488
}
@@ -490,7 +493,7 @@ new SearchRequest<Project>
490493

491494
[source,csharp]
492495
----
493-
response.IsValid.Should().BeTrue();
496+
response.ShouldBeValid();
494497
var commits = response.Aggs.Terms<int>("commits");
495498
commits.Should().NotBeNull();
496499
commits.DocCountErrorUpperBound.Should().HaveValue();
@@ -502,5 +505,6 @@ foreach (var item in commits.Buckets)
502505
item.Key.Should().BeGreaterThan(0);
503506
item.DocCount.Should().BeGreaterOrEqualTo(1);
504507
}
508+
commits.Buckets.Should().Contain(b => b.DocCountErrorUpperBound.HasValue);
505509
----
506510

docs/aggregations/metric/extended-stats/extended-stats-aggregation-usage.asciidoc

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ s => s
2525
.Aggregations(a => a
2626
.ExtendedStats("commit_stats", es => es
2727
.Field(p => p.NumberOfCommits)
28+
.Sigma(1)
2829
)
2930
)
3031
----
@@ -35,7 +36,7 @@ s => s
3536
----
3637
new SearchRequest<Project>
3738
{
38-
Aggregations = new ExtendedStatsAggregation("commit_stats", Field<Project>(p => p.NumberOfCommits))
39+
Aggregations = new ExtendedStatsAggregation("commit_stats", Field<Project>(p => p.NumberOfCommits)) { Sigma = 1 }
3940
}
4041
----
4142

@@ -46,7 +47,8 @@ new SearchRequest<Project>
4647
"aggs": {
4748
"commit_stats": {
4849
"extended_stats": {
49-
"field": "numberOfCommits"
50+
"field": "numberOfCommits",
51+
"sigma": 1.0
5052
}
5153
}
5254
}

docs/aggregations/metric/geo-centroid/geo-centroid-aggregation-usage.asciidoc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ new SearchRequest<Project>
133133

134134
[source,csharp]
135135
----
136-
response.IsValid.Should().BeTrue();
136+
response.ShouldBeValid();
137137
138138
var projects = response.Aggs.Terms("projects");
139139

docs/aggregations/metric/scripted-metric/scripted-metric-aggregation-usage.asciidoc

Lines changed: 111 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,10 @@ please modify the original csharp file found at the link and submit the PR with
2424
s => s
2525
.Aggregations(a => a
2626
.ScriptedMetric("sum_the_hard_way", sm => sm
27-
.InitScript(ss=>ss.Inline("_agg['commits'] = []").Lang("groovy"))
28-
.MapScript(ss=>ss.Inline("if (doc['state'].value == \"Stable\") { _agg.commits.add(doc['numberOfCommits']) }").Lang("groovy"))
29-
.CombineScript(ss=>ss.Inline("sum = 0; for (c in _agg.commits) { sum += c }; return sum").Lang("groovy"))
30-
.ReduceScript(ss=>ss.Inline("sum = 0; for (a in _aggs) { sum += a }; return sum").Lang("groovy"))
27+
.InitScript(ss => ss.Inline("_agg['commits'] = []").Lang("groovy"))
28+
.MapScript(ss => ss.Inline("if (doc['state'].value == \"Stable\") { _agg.commits.add(doc['numberOfCommits']) }").Lang("groovy"))
29+
.CombineScript(ss => ss.Inline("sum = 0; for (c in _agg.commits) { sum += c }; return sum").Lang("groovy"))
30+
.ReduceScript(ss => ss.Inline("sum = 0; for (a in _aggs) { sum += a }; return sum").Lang("groovy"))
3131
)
3232
)
3333
----
@@ -40,10 +40,10 @@ new SearchRequest<Project>
4040
{
4141
Aggregations = new ScriptedMetricAggregation("sum_the_hard_way")
4242
{
43-
InitScript = new InlineScript("_agg['commits'] = []") { Lang = "groovy" },
44-
MapScript = new InlineScript("if (doc['state'].value == \"Stable\") { _agg.commits.add(doc['numberOfCommits']) }"){ Lang = "groovy" },
45-
CombineScript = new InlineScript("sum = 0; for (c in _agg.commits) { sum += c }; return sum"){ Lang = "groovy" },
46-
ReduceScript = new InlineScript("sum = 0; for (a in _aggs) { sum += a }; return sum"){ Lang = "groovy" }
43+
InitScript = new InlineScript("_agg['commits'] = []") {Lang = "groovy"},
44+
MapScript = new InlineScript("if (doc['state'].value == \"Stable\") { _agg.commits.add(doc['numberOfCommits']) }") {Lang = "groovy"},
45+
CombineScript = new InlineScript("sum = 0; for (c in _agg.commits) { sum += c }; return sum") {Lang = "groovy"},
46+
ReduceScript = new InlineScript("sum = 0; for (a in _aggs) { sum += a }; return sum") {Lang = "groovy"}
4747
}
4848
}
4949
----
@@ -87,3 +87,106 @@ sumTheHardWay.Should().NotBeNull();
8787
sumTheHardWay.Value<int>().Should().BeGreaterThan(0);
8888
----
8989

90+
==== Fluent DSL example
91+
92+
[source,csharp]
93+
----
94+
s => s
95+
.Aggregations(a => a
96+
.ScriptedMetric("by_state_total", sm => sm
97+
.InitScript(ss => ss.Inline(First.Init).Lang(First.Language))
98+
.MapScript(ss => ss.Inline(First.Map).Lang(First.Language))
99+
.ReduceScript(ss => ss.Inline(First.Reduce).Lang(First.Language))
100+
)
101+
.ScriptedMetric("total_commits", sm => sm
102+
.InitScript(ss => ss.Inline(Second.Init).Lang(Second.Language))
103+
.MapScript(ss => ss.Inline(Second.Map).Lang(Second.Language))
104+
.CombineScript(ss => ss.Inline(Second.Combine).Lang(Second.Language))
105+
.ReduceScript(ss => ss.Inline(Second.Reduce).Lang(Second.Language))
106+
)
107+
)
108+
----
109+
110+
==== Object Initializer syntax example
111+
112+
[source,csharp]
113+
----
114+
new SearchRequest<Project>
115+
{
116+
Aggregations =
117+
new ScriptedMetricAggregation("by_state_total")
118+
{
119+
InitScript = new InlineScript(First.Init) {Lang = First.Language},
120+
MapScript = new InlineScript(First.Map) {Lang = First.Language},
121+
ReduceScript = new InlineScript(First.Reduce) {Lang = First.Language}
122+
} &&
123+
new ScriptedMetricAggregation("total_commits")
124+
{
125+
InitScript = new InlineScript(Second.Init) {Lang = Second.Language},
126+
MapScript = new InlineScript(Second.Map) {Lang = Second.Language},
127+
CombineScript = new InlineScript(Second.Combine) {Lang = Second.Language},
128+
ReduceScript = new InlineScript(Second.Reduce) {Lang = Second.Language}
129+
}
130+
}
131+
----
132+
133+
[source,javascript]
134+
.Example json output
135+
----
136+
{
137+
"aggs": {
138+
"by_state_total": {
139+
"scripted_metric": {
140+
"init_script": {
141+
"inline": "params._agg.map = [:]",
142+
"lang": "painless"
143+
},
144+
"map_script": {
145+
"inline": "if (params._agg.map.containsKey(doc['state'].value)) params._agg.map[doc['state'].value] += 1 else params._agg.map[doc['state'].value] = 1;",
146+
"lang": "painless"
147+
},
148+
"reduce_script": {
149+
"inline": "def reduce = [:]; for (agg in params._aggs) { for (entry in agg.map.entrySet()) { if (reduce.containsKey(entry.getKey())) reduce[entry.getKey()] += entry.getValue(); else reduce[entry.getKey()] = entry.getValue(); } } return reduce;",
150+
"lang": "painless"
151+
}
152+
}
153+
},
154+
"total_commits": {
155+
"scripted_metric": {
156+
"init_script": {
157+
"inline": "params._agg.commits = []",
158+
"lang": "painless"
159+
},
160+
"map_script": {
161+
"inline": "if (doc['state'].value == \"Stable\") { params._agg.commits.add(doc['numberOfCommits'].value) }",
162+
"lang": "painless"
163+
},
164+
"combine_script": {
165+
"inline": "def sum = 0.0; for (c in params._agg.commits) { sum += c } return sum",
166+
"lang": "painless"
167+
},
168+
"reduce_script": {
169+
"inline": "def sum = 0.0; for (a in params._aggs) { sum += a } return sum",
170+
"lang": "painless"
171+
}
172+
}
173+
}
174+
}
175+
}
176+
----
177+
178+
==== Handling Responses
179+
180+
[source,csharp]
181+
----
182+
response.ShouldBeValid();
183+
var by_state_total = response.Aggs.ScriptedMetric("by_state_total");
184+
var total_commits = response.Aggs.ScriptedMetric("total_commits");
185+
186+
by_state_total.Should().NotBeNull();
187+
total_commits.Should().NotBeNull();
188+
189+
by_state_total.Value<IDictionary<string, int>>().Should().NotBeNull();
190+
total_commits.Value<int>().Should().BeGreaterThan(0);
191+
----
192+

0 commit comments

Comments
 (0)