Skip to content

Commit 83f2eaf

Browse files
committed
Re-add Aggregation usage examples (#3075)
* Re-add Aggregation usage examples This commit re-adds aggregation usage examples back into the documentation. Refactoring as part of 6.0 introduced aggregation related fluent, initializer and expectjson properties which are not picked up by the Usages Roslyn walker/visitor. * Regenerate documentation (cherry picked from commit f998ef7)
1 parent 6ad1e04 commit 83f2eaf

File tree

72 files changed

+3525
-83
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

72 files changed

+3525
-83
lines changed

.paket/Paket.Restore.targets

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,14 @@
1818
<PaketExePath Condition=" '$(PaketExePath)' == '' ">$(PaketToolsPath)paket.exe</PaketExePath>
1919
<PaketCommand Condition=" '$(OS)' == 'Windows_NT'">"$(PaketExePath)"</PaketCommand>
2020
<PaketCommand Condition=" '$(OS)' != 'Windows_NT' ">$(MonoPath) --runtime=v4.0.30319 "$(PaketExePath)"</PaketCommand>
21+
22+
<!-- .net core fdd -->
23+
<_PaketExeExtension>$([System.IO.Path]::GetExtension("$(PaketExePath)"))</_PaketExeExtension>
24+
<PaketCommand Condition=" '$(_PaketExeExtension)' == '.dll' ">dotnet "$(PaketExePath)"</PaketCommand>
25+
26+
<!-- no extension is a shell script -->
27+
<PaketCommand Condition=" '$(_PaketExeExtension)' == '' ">"$(PaketExePath)"</PaketCommand>
28+
2129
<PaketBootStrapperExePath Condition=" '$(PaketBootStrapperExePath)' == '' AND Exists('$(PaketRootPath)paket.bootstrapper.exe')">$(PaketRootPath)paket.bootstrapper.exe</PaketBootStrapperExePath>
2230
<PaketBootStrapperExePath Condition=" '$(PaketBootStrapperExePath)' == '' ">$(PaketToolsPath)paket.bootstrapper.exe</PaketBootStrapperExePath>
2331
<PaketBootStrapperCommand Condition=" '$(OS)' == 'Windows_NT'">"$(PaketBootStrapperExePath)"</PaketBootStrapperCommand>
@@ -140,9 +148,10 @@
140148
</DotNetCliToolReference>
141149
</ItemGroup>
142150

151+
<!-- Disabled for now until we know what to do with runtime deps - https://github.com/fsprojects/Paket/issues/2964
143152
<PropertyGroup>
144153
<RestoreConfigFile>$(MSBuildProjectDirectory)/obj/$(MSBuildProjectFile).NuGet.Config</RestoreConfigFile>
145-
</PropertyGroup>
154+
</PropertyGroup> -->
146155

147156
</Target>
148157

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
:ref_current: https://www.elastic.co/guide/en/elasticsearch/reference/6.1
2+
3+
:github: https://github.com/elastic/elasticsearch-net
4+
5+
:nuget: https://www.nuget.org/packages
6+
7+
////
8+
IMPORTANT NOTE
9+
==============
10+
This file has been generated from https://github.com/elastic/elasticsearch-net/tree/master/src/Tests/Aggregations/AggregationMetaUsageTests.cs.
11+
If you wish to submit a PR for any spelling mistakes, typos or grammatical errors for this file,
12+
please modify the original csharp file found at the link and submit the PR with that change. Thanks!
13+
////
14+
15+
[[aggregation-metadata]]
16+
=== Aggregation Metadata
17+
18+
Metadata can be provided per aggregation, and will be returned in the aggregation response
19+
20+
[source,csharp]
21+
----
22+
a => a
23+
.Min("min_last_activity", m => m
24+
.Field(p => p.LastActivity)
25+
.Meta(d => d
26+
.Add("meta_1", "value_1")
27+
.Add("meta_2", 2)
28+
.Add("meta_3", new { meta_3 = "value_3" })
29+
)
30+
)
31+
----
32+
33+
[source,csharp]
34+
----
35+
new MinAggregation("min_last_activity", Infer.Field<Project>(p => p.LastActivity))
36+
{
37+
Meta = new Dictionary<string,object>
38+
{
39+
{ "meta_1", "value_1" },
40+
{ "meta_2", 2 },
41+
{ "meta_3", new { meta_3 = "value_3" } }
42+
}
43+
}
44+
----
45+
46+
[source,javascript]
47+
.Example json output
48+
----
49+
{
50+
"min_last_activity": {
51+
"min": {
52+
"field": "lastActivity"
53+
},
54+
"meta": {
55+
"meta_1": "value_1",
56+
"meta_2": 2,
57+
"meta_3": {
58+
"meta_3": "value_3"
59+
}
60+
}
61+
}
62+
}
63+
----
64+
65+
==== Handling Responses
66+
67+
[source,csharp]
68+
----
69+
response.ShouldBeValid();
70+
var min = response.Aggregations.Min("min_last_activity");
71+
min.Meta.Should().NotBeNull().And.ContainKeys("meta_1", "meta_2", "meta_3");
72+
----
73+

docs/aggregations/bucket/adjacency-matrix/adjacency-matrix-usage.asciidoc

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,65 @@ please modify the original csharp file found at the link and submit the PR with
1515
[[adjacency-matrix-usage]]
1616
=== Adjacency Matrix Usage
1717

18+
[source,csharp]
19+
----
20+
a => a
21+
.AdjacencyMatrix("interactions", am => am
22+
.Filters(fs => fs
23+
.Filter("grpA", f => f.Term(p => p.State, StateOfBeing.BellyUp))
24+
.Filter("grpB", f => f.Term(p => p.State, StateOfBeing.Stable))
25+
.Filter("grpC", f => f.Term(p => p.State, StateOfBeing.VeryActive))
26+
)
27+
)
28+
----
29+
30+
[source,csharp]
31+
----
32+
new AdjacencyMatrixAggregation("interactions")
33+
{
34+
Filters = new NamedFiltersContainer
35+
{
36+
{"grpA", new TermQuery {Field = "state", Value = StateOfBeing.BellyUp}},
37+
{"grpB", new TermQuery {Field = "state", Value = StateOfBeing.Stable}},
38+
{"grpC", new TermQuery {Field = "state", Value = StateOfBeing.VeryActive}},
39+
}
40+
}
41+
----
42+
43+
[source,javascript]
44+
.Example json output
45+
----
46+
{
47+
"interactions": {
48+
"adjacency_matrix": {
49+
"filters": {
50+
"grpA": {
51+
"term": {
52+
"state": {
53+
"value": "BellyUp"
54+
}
55+
}
56+
},
57+
"grpB": {
58+
"term": {
59+
"state": {
60+
"value": "Stable"
61+
}
62+
}
63+
},
64+
"grpC": {
65+
"term": {
66+
"state": {
67+
"value": "VeryActive"
68+
}
69+
}
70+
}
71+
}
72+
}
73+
}
74+
}
75+
----
76+
1877
==== Handling Responses
1978

2079
[source,csharp]

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

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,3 +20,55 @@ buckets on child documents.
2020

2121
Be sure to read the Elasticsearch documentation on {ref_current}/search-aggregations-bucket-children-aggregation.html[Children Aggregation]
2222

23+
[source,csharp]
24+
----
25+
a => a
26+
.Children<CommitActivity>("name_of_child_agg", child => child
27+
.Aggregations(childAggs => childAggs
28+
.Average("average_per_child", avg => avg.Field(p => p.ConfidenceFactor))
29+
.Max("max_per_child", avg => avg.Field(p => p.ConfidenceFactor))
30+
.Min("min_per_child", avg => avg.Field(p => p.ConfidenceFactor))
31+
)
32+
)
33+
----
34+
35+
[source,csharp]
36+
----
37+
new ChildrenAggregation("name_of_child_agg", typeof(CommitActivity))
38+
{
39+
Aggregations =
40+
new AverageAggregation("average_per_child", "confidenceFactor")
41+
&& new MaxAggregation("max_per_child", "confidenceFactor")
42+
&& new MinAggregation("min_per_child", "confidenceFactor")
43+
}
44+
----
45+
46+
[source,javascript]
47+
.Example json output
48+
----
49+
{
50+
"name_of_child_agg": {
51+
"children": {
52+
"type": "commits"
53+
},
54+
"aggs": {
55+
"average_per_child": {
56+
"avg": {
57+
"field": "confidenceFactor"
58+
}
59+
},
60+
"max_per_child": {
61+
"max": {
62+
"field": "confidenceFactor"
63+
}
64+
},
65+
"min_per_child": {
66+
"min": {
67+
"field": "confidenceFactor"
68+
}
69+
}
70+
}
71+
}
72+
}
73+
----
74+

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

Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,91 @@ as part of the `format` value.
2525

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

28+
[source,csharp]
29+
----
30+
a => a
31+
.DateHistogram("projects_started_per_month", date => date
32+
.Field(p => p.StartedOn)
33+
.Interval(DateInterval.Month)
34+
.MinimumDocumentCount(2)
35+
.Format("yyyy-MM-dd'T'HH:mm:ss")
36+
.ExtendedBounds(FixedDate.AddYears(-1), FixedDate.AddYears(1))
37+
.Order(HistogramOrder.CountAscending)
38+
.Missing(FixedDate)
39+
.Aggregations(childAggs => childAggs
40+
.Nested("project_tags", n => n
41+
.Path(p => p.Tags)
42+
.Aggregations(nestedAggs => nestedAggs
43+
.Terms("tags", avg => avg.Field(p => p.Tags.First().Name))
44+
)
45+
)
46+
)
47+
)
48+
----
49+
50+
[source,csharp]
51+
----
52+
new DateHistogramAggregation("projects_started_per_month")
53+
{
54+
Field = Field<Project>(p => p.StartedOn),
55+
Interval = DateInterval.Month,
56+
MinimumDocumentCount = 2,
57+
Format = "yyyy-MM-dd'T'HH:mm:ss",
58+
ExtendedBounds = new ExtendedBounds<DateMath>
59+
{
60+
Minimum = FixedDate.AddYears(-1),
61+
Maximum = FixedDate.AddYears(1),
62+
},
63+
Order = HistogramOrder.CountAscending,
64+
Missing = FixedDate,
65+
Aggregations = new NestedAggregation("project_tags")
66+
{
67+
Path = Field<Project>(p => p.Tags),
68+
Aggregations = new TermsAggregation("tags")
69+
{
70+
Field = Field<Project>(p => p.Tags.First().Name)
71+
}
72+
}
73+
}
74+
----
75+
76+
[source,javascript]
77+
.Example json output
78+
----
79+
{
80+
"projects_started_per_month": {
81+
"date_histogram": {
82+
"field": "startedOn",
83+
"interval": "month",
84+
"min_doc_count": 2,
85+
"format": "yyyy-MM-dd'T'HH:mm:ss||date_optional_time",
86+
"order": {
87+
"_count": "asc"
88+
},
89+
"extended_bounds": {
90+
"min": "2014-06-06T12:01:02.123",
91+
"max": "2016-06-06T12:01:02.123"
92+
},
93+
"missing": "2015-06-06T12:01:02.123"
94+
},
95+
"aggs": {
96+
"project_tags": {
97+
"nested": {
98+
"path": "tags"
99+
},
100+
"aggs": {
101+
"tags": {
102+
"terms": {
103+
"field": "tags.name"
104+
}
105+
}
106+
}
107+
}
108+
}
109+
}
110+
}
111+
----
112+
28113
=== Handling responses
29114

30115
The `AggregateDictionary found on `.Aggregations` on `ISearchResponse<T>` has several helper methods

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

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,72 @@ IMPORTANT: this aggregation includes the `from` value and excludes the `to` valu
2323

2424
Be sure to read the Elasticsearch documentation on {ref_current}/search-aggregations-bucket-daterange-aggregation.html[Date Range Aggregation]
2525

26+
[source,csharp]
27+
----
28+
a => a
29+
.DateRange("projects_date_ranges", date => date
30+
.Field(p => p.StartedOn)
31+
.Ranges(
32+
r => r.From(DateMath.Anchored(FixedDate).Add("2d")).To(DateMath.Now),
33+
r => r.To(DateMath.Now.Add(TimeSpan.FromDays(1)).Subtract("30m").RoundTo(DateMathTimeUnit.Hour)),
34+
r => r.From(DateMath.Anchored("2012-05-05").Add(TimeSpan.FromDays(1)).Subtract("1m"))
35+
)
36+
.TimeZone("CET")
37+
.Aggregations(childAggs => childAggs
38+
.Terms("project_tags", avg => avg.Field(p => p.Tags))
39+
)
40+
)
41+
----
42+
43+
[source,csharp]
44+
----
45+
new DateRangeAggregation("projects_date_ranges")
46+
{
47+
Field = Field<Project>(p => p.StartedOn),
48+
Ranges = new List<DateRangeExpression>
49+
{
50+
new DateRangeExpression {From = DateMath.Anchored(FixedDate).Add("2d"), To = DateMath.Now},
51+
new DateRangeExpression {To = DateMath.Now.Add(TimeSpan.FromDays(1)).Subtract("30m").RoundTo(DateMathTimeUnit.Hour)},
52+
new DateRangeExpression {From = DateMath.Anchored("2012-05-05").Add(TimeSpan.FromDays(1)).Subtract("1m")}
53+
},
54+
TimeZone = "CET",
55+
Aggregations =
56+
new TermsAggregation("project_tags") {Field = Field<Project>(p => p.Tags)}
57+
}
58+
----
59+
60+
[source,javascript]
61+
.Example json output
62+
----
63+
{
64+
"projects_date_ranges": {
65+
"date_range": {
66+
"field": "startedOn",
67+
"ranges": [
68+
{
69+
"to": "now",
70+
"from": "2015-06-06T12:01:02.123||+2d"
71+
},
72+
{
73+
"to": "now+1d-30m/h"
74+
},
75+
{
76+
"from": "2012-05-05||+1d-1m"
77+
}
78+
],
79+
"time_zone": "CET"
80+
},
81+
"aggs": {
82+
"project_tags": {
83+
"terms": {
84+
"field": "tags"
85+
}
86+
}
87+
}
88+
}
89+
}
90+
----
91+
2692
=== Handling Responses
2793

2894
The `AggregateDictionary found on `.Aggregations` on `ISearchResponse<T>` has several helper methods

0 commit comments

Comments
 (0)