File tree Expand file tree Collapse file tree 4 files changed +168
-1
lines changed Expand file tree Collapse file tree 4 files changed +168
-1
lines changed Original file line number Diff line number Diff line change @@ -6,7 +6,7 @@ include::{asciidoc-dir}/../../shared/attributes.asciidoc[]
6
6
7
7
:doc-tests-src: {docdir}/../tests/Tests/Documentation
8
8
:net-client: Elasticsearch .NET Client
9
- :latest-version: 8.1.0
9
+ :latest-version: 8.15.8
10
10
11
11
:es-docs: https://www.elastic.co/guide/en/elasticsearch/reference/{branch}
12
12
Original file line number Diff line number Diff line change
1
+ [[aggregations]]
2
+ == Aggregation Examples
3
+
4
+ This page demonstrates how to use aggregations.
5
+
6
+ [discrete]
7
+ === Top Level Aggreggation
8
+
9
+ [discrete]
10
+ ==== Fluent API
11
+
12
+ [source,csharp]
13
+ ----
14
+ var response = await client
15
+ .SearchAsync<Person>(search => search
16
+ .Index("persons")
17
+ .Query(query => query
18
+ .MatchAll(_ => {})
19
+ )
20
+ .Aggregations(aggregations => aggregations
21
+ .Add("agg_name", aggregation => aggregation
22
+ .Max(max => max
23
+ .Field(x => x.Age)
24
+ )
25
+ )
26
+ )
27
+ .Size(10)
28
+ );
29
+ ----
30
+
31
+ [discrete]
32
+ ==== Consuming the Response
33
+
34
+ [source,csharp]
35
+ ----
36
+ var max = response.Aggregations!.GetMax("agg_name")!;
37
+ Console.WriteLine(max.Value);
38
+ ----
39
+
40
+ [discrete]
41
+ === Sub Aggregation
42
+
43
+ [discrete]
44
+ ==== Fluent API
45
+
46
+ [source,csharp]
47
+ ----
48
+ var response = await client
49
+ .SearchAsync<Person>(search => search
50
+ .Index("persons")
51
+ .Query(query => query
52
+ .MatchAll(_ => {})
53
+ )
54
+ .Aggregations(aggregations => aggregations
55
+ .Add("firstnames", aggregation => aggregation
56
+ .Terms(terms => terms
57
+ .Field(x => x.FirstName)
58
+ )
59
+ .Aggregations(aggregations => aggregations
60
+ .Add("avg_age", aggregation => aggregation
61
+ .Max(avg => avg
62
+ .Field(x => x.Age)
63
+ )
64
+ )
65
+ )
66
+ )
67
+ )
68
+ .Size(10)
69
+ );
70
+ ----
71
+
72
+ [discrete]
73
+ ==== Consuming the Response
74
+
75
+ [source,csharp]
76
+ ----
77
+ var firstnames = response.Aggregations!.GetStringTerms("firstnames")!;
78
+ foreach (var bucket in firstnames.Buckets)
79
+ {
80
+ var avg = bucket.Aggregations.GetAverage("avg_age")!;
81
+ Console.WriteLine($"The average age for persons named '{bucket.Key}' is {avg}");
82
+ }
83
+ ----
Original file line number Diff line number Diff line change
1
+ [[mappings]]
2
+ == Custom Mappings Examples
3
+
4
+ This page demonstrates how to configure custom mappings on an index.
5
+
6
+ [discrete]
7
+ === Configure Mappings during Index Creation
8
+
9
+ [source,csharp]
10
+ ----
11
+ await client.Indices.CreateAsync<Person>(index => index
12
+ .Index("index")
13
+ .Mappings(mappings => mappings
14
+ .Properties(properties => properties
15
+ .IntegerNumber(x => x.Age!)
16
+ .Keyword(x => x.FirstName!, keyword => keyword.Index(false))
17
+ )
18
+ )
19
+ );
20
+ ----
21
+
22
+ [discrete]
23
+ === Configure Mappings after Index Creation
24
+
25
+ [source,csharp]
26
+ ----
27
+ await client.Indices.PutMappingAsync<Person>(mappings => mappings
28
+ .Indices("index")
29
+ .Properties(properties => properties
30
+ .IntegerNumber(x => x.Age!)
31
+ .Keyword(x => x.FirstName!, keyword => keyword.Index(false))
32
+ )
33
+ );
34
+ ----
Original file line number Diff line number Diff line change
1
+ [[query]]
2
+ == Query Examples
3
+
4
+ This page demonstrates how to perform a search request.
5
+
6
+ [discrete]
7
+ === Fluent API
8
+
9
+ [source,csharp]
10
+ ----
11
+ var response = await client
12
+ .SearchAsync<Person>(search => search
13
+ .Index("persons")
14
+ .Query(query => query
15
+ .Term(term => term
16
+ .Field(x => x.FirstName)
17
+ .Value("Florian")
18
+ )
19
+ )
20
+ .Size(10)
21
+ );
22
+ ----
23
+
24
+ [discrete]
25
+ === Object Initializer API
26
+
27
+ [source,csharp]
28
+ ----
29
+ var response = await client
30
+ .SearchAsync<Person>(new SearchRequest<Person>("persons")
31
+ {
32
+ Query = Query.Term(new TermQuery("firstName"!)
33
+ {
34
+ Value = "Florian"
35
+ }),
36
+ Size = 10
37
+ });
38
+ ----
39
+
40
+
41
+ [discrete]
42
+ === Consuming the Response
43
+
44
+ [source,csharp]
45
+ ----
46
+ foreach (var person in response.Documents)
47
+ {
48
+ Console.WriteLine(person.FirstName);
49
+ }
50
+ ----
You can’t perform that action at this time.
0 commit comments