Skip to content

Commit

Permalink
Add more object initializer API examples
Browse files Browse the repository at this point in the history
  • Loading branch information
flobernd committed Oct 4, 2024
1 parent bf72330 commit 34e07e1
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 1 deletion.
50 changes: 50 additions & 0 deletions docs/usage/aggregations.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,26 @@ var response = await client
----

[discrete]
==== Object initializer API

[source,csharp]
----
var response = await client.SearchAsync<Person>(new SearchRequest("persons")
{
Query = Query.MatchAll(new MatchAllQuery()),
Aggregations = new Dictionary<string, Aggregation>
{
{ "agg_name", Aggregation.Max(new MaxAggregation
{
Field = Infer.Field<Person>(x => x.Age)
})}
},
Size = 10
});
----

[discrete]
==== Consuming the Response
==== Consume the response

[source,csharp]
Expand Down Expand Up @@ -70,6 +90,36 @@ var response = await client
----

[discrete]
==== Object initializer API

[source,csharp]
----
var topLevelAggregation = Aggregation.Terms(new TermsAggregation
{
Field = Infer.Field<Person>(x => x.FirstName)
});
topLevelAggregation.Aggregations = new Dictionary<string, Aggregation>
{
{ "avg_age", new MaxAggregation
{
Field = Infer.Field<Person>(x => x.Age)
}}
};
var response = await client.SearchAsync<Person>(new SearchRequest("persons")
{
Query = Query.MatchAll(new MatchAllQuery()),
Aggregations = new Dictionary<string, Aggregation>
{
{ "firstnames", topLevelAggregation}
},
Size = 10
});
----

[discrete]
==== Consuming the Response
==== Consume the response

[source,csharp]
Expand Down
2 changes: 1 addition & 1 deletion docs/usage/query.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ var response = await client
var response = await client
.SearchAsync<Person>(new SearchRequest<Person>("persons")
{
Query = Query.Term(new TermQuery("firstName"!)
Query = Query.Term(new TermQuery(Infer.Field<Person>(x => x.FirstName))
{
Value = "Florian"
}),
Expand Down

0 comments on commit 34e07e1

Please sign in to comment.