I am looking for how to init a SearchRequest Object with several no nested Aggregations by using the object initializer syntax.
If the request were given as param into ElasticClient.Search() with lambda expression helper it would be written like bellow:
var response = Client.Search<person>(s => s.Aggregations(a =>
a.Terms("bucketAge", t => t.Field("age").Size(50))
.Terms("bucketCity", t => t.Field("city").Size(50))));
What is paradoxical is i found i how to write a Agg with a nested Agg
var searchRequest = new SearchRequest<person>
{
Size = 0,
Aggregations =
new TermsAggregation("bucketAge")
{
Field = "age",
Size = 50,
Aggregations = new TermsAggregation("bucketcity")
{
Field = "city",
Size = 50
}
}
};
But i fail to init SearchRequest with 2 aggs on same level with Something like that:
var searchRequest = new SearchRequest<person>
{
Size = 0,
Aggregations =
{
new TermsAggregation("bucketAge")
{
Field = "age",
Size = 50
},
new TermsAggregation("bucketcity")
{
Field = "city",
Size = 50
}
}
};
How to do this please?