I need to return the number of children for each parent. That is my solution:
foreach (var person in someList)
{
var countingFields = _elasticsearchClient.Search<SomeModel>(esModel=> esModel
.Aggregations(aggregation => aggregation
.Filter("Parents", filter => filter
.Filter(innerFilter => innerFilter
.Term(field => field.ParentId, person.Id))
.Aggregations(innerAggregation => innerAggregation
.ValueCount("Counting", count => count
.Field(field => field.ParentId))))));
}
I need help to improve this, I want to get the same data with only one connection to ElasticSearch.