From 34e07e1b521b72e03feb2f4c43dbfc8b5d9bb58e Mon Sep 17 00:00:00 2001 From: Florian Bernd Date: Fri, 4 Oct 2024 15:25:42 +0200 Subject: [PATCH] Add more object initializer API examples --- docs/usage/aggregations.asciidoc | 50 ++++++++++++++++++++++++++++++++ docs/usage/query.asciidoc | 2 +- 2 files changed, 51 insertions(+), 1 deletion(-) diff --git a/docs/usage/aggregations.asciidoc b/docs/usage/aggregations.asciidoc index c52c950048..44f2f6d342 100644 --- a/docs/usage/aggregations.asciidoc +++ b/docs/usage/aggregations.asciidoc @@ -29,6 +29,26 @@ var response = await client ---- [discrete] +==== Object initializer API + +[source,csharp] +---- +var response = await client.SearchAsync(new SearchRequest("persons") +{ + Query = Query.MatchAll(new MatchAllQuery()), + Aggregations = new Dictionary + { + { "agg_name", Aggregation.Max(new MaxAggregation + { + Field = Infer.Field(x => x.Age) + })} + }, + Size = 10 +}); +---- + +[discrete] +==== Consuming the Response ==== Consume the response [source,csharp] @@ -70,6 +90,36 @@ var response = await client ---- [discrete] +==== Object initializer API + +[source,csharp] +---- +var topLevelAggregation = Aggregation.Terms(new TermsAggregation +{ + Field = Infer.Field(x => x.FirstName) +}); + +topLevelAggregation.Aggregations = new Dictionary +{ + { "avg_age", new MaxAggregation + { + Field = Infer.Field(x => x.Age) + }} +}; + +var response = await client.SearchAsync(new SearchRequest("persons") +{ + Query = Query.MatchAll(new MatchAllQuery()), + Aggregations = new Dictionary + { + { "firstnames", topLevelAggregation} + }, + Size = 10 +}); +---- + +[discrete] +==== Consuming the Response ==== Consume the response [source,csharp] diff --git a/docs/usage/query.asciidoc b/docs/usage/query.asciidoc index e4c6b5118e..b365825cdb 100644 --- a/docs/usage/query.asciidoc +++ b/docs/usage/query.asciidoc @@ -29,7 +29,7 @@ var response = await client var response = await client .SearchAsync(new SearchRequest("persons") { - Query = Query.Term(new TermQuery("firstName"!) + Query = Query.Term(new TermQuery(Infer.Field(x => x.FirstName)) { Value = "Florian" }),