elasticsearch-net
elasticsearch-net copied to clipboard
Aggregation bucket results have wrong keys or are not returned at all
NEST/Elasticsearch.Net version: 7.17.5
Elasticsearch version: 8.6.2
.NET runtime version: .NET 6.0
Operating system version: Fedora 38, elasticsearch is running in Docker
Description of the problem including expected versus actual behavior: Here's a simple query I am running:
var someDescriptor = new SearchDescriptor<MyModel>(Indices.Index(new[] { "someindex" }))
.Aggregations(ag => ag
.Terms("some_term_agg", term => term
.Field(m => m.CityCode)
.Size(10)));
var someResult = await _client.SearchAsync<PrecomputedPackage>(
someDescriptor,
cancellationToken);
The corresponding REST API request JSON is as follows:
{
"aggs": {
"some_term_agg": {
"terms": {
"field": "cityCode",
"size": 10
}
}
}
}
(The above JSON was generated with _client.RequestResponseSerializer.SerializeToString(someDescriptor)
)
The response I'm getting with NEST contains 8 buckets:
However, each bucket is empty:
When I execute my query with elasticsearch's REST API, I get:
"aggregations": {
"some_term_agg": {
"doc_count_error_upper_bound": 0,
"sum_other_doc_count": 0,
"buckets": [
{
"key": "BCN",
"doc_count": 134
},
{
"key": "ROM",
"doc_count": 134
},
{
"key": "LCJ",
"doc_count": 132
},
{
"key": "LIZ",
"doc_count": 130
},
{
"key": "WAW",
"doc_count": 126
},
{
"key": "WRO",
"doc_count": 120
},
{
"key": "BER",
"doc_count": 115
},
{
"key": "LON",
"doc_count": 109
}
]
}
}
(I skipped the documents, they are alright in both NEST and REST API responses)
Expected behavior I should get the same buckets values using NEST, as I do when using REST API.
This issue occurred to me while I was trying to prepare a simple reproduction example for another issue where buckets have values, but their keys are wrong - all keys have the same values equal to the name of the aggregation (e.g, "some_term_agg") instead of the value being aggreagated (like city codes).
Hi, I'll keep this as a NEST bug until I have time to check in detail. NEST does not have the highest priority at the moment.
In the meantime I would suggest to evaluate if it makes sense for you to use the new 8.x client side-by-side with NEST in your project.