Skip to content

Commit 34e07e1

Browse files
committed
Add more object initializer API examples
1 parent bf72330 commit 34e07e1

File tree

2 files changed

+51
-1
lines changed

2 files changed

+51
-1
lines changed

docs/usage/aggregations.asciidoc

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,26 @@ var response = await client
2929
----
3030

3131
[discrete]
32+
==== Object initializer API
33+
34+
[source,csharp]
35+
----
36+
var response = await client.SearchAsync<Person>(new SearchRequest("persons")
37+
{
38+
Query = Query.MatchAll(new MatchAllQuery()),
39+
Aggregations = new Dictionary<string, Aggregation>
40+
{
41+
{ "agg_name", Aggregation.Max(new MaxAggregation
42+
{
43+
Field = Infer.Field<Person>(x => x.Age)
44+
})}
45+
},
46+
Size = 10
47+
});
48+
----
49+
50+
[discrete]
51+
==== Consuming the Response
3252
==== Consume the response
3353

3454
[source,csharp]
@@ -70,6 +90,36 @@ var response = await client
7090
----
7191

7292
[discrete]
93+
==== Object initializer API
94+
95+
[source,csharp]
96+
----
97+
var topLevelAggregation = Aggregation.Terms(new TermsAggregation
98+
{
99+
Field = Infer.Field<Person>(x => x.FirstName)
100+
});
101+
102+
topLevelAggregation.Aggregations = new Dictionary<string, Aggregation>
103+
{
104+
{ "avg_age", new MaxAggregation
105+
{
106+
Field = Infer.Field<Person>(x => x.Age)
107+
}}
108+
};
109+
110+
var response = await client.SearchAsync<Person>(new SearchRequest("persons")
111+
{
112+
Query = Query.MatchAll(new MatchAllQuery()),
113+
Aggregations = new Dictionary<string, Aggregation>
114+
{
115+
{ "firstnames", topLevelAggregation}
116+
},
117+
Size = 10
118+
});
119+
----
120+
121+
[discrete]
122+
==== Consuming the Response
73123
==== Consume the response
74124

75125
[source,csharp]

docs/usage/query.asciidoc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ var response = await client
2929
var response = await client
3030
.SearchAsync<Person>(new SearchRequest<Person>("persons")
3131
{
32-
Query = Query.Term(new TermQuery("firstName"!)
32+
Query = Query.Term(new TermQuery(Infer.Field<Person>(x => x.FirstName))
3333
{
3434
Value = "Florian"
3535
}),

0 commit comments

Comments
 (0)