elasticsearch-net
elasticsearch-net copied to clipboard
CompositeAggregationSource is not serialized correctly
Elastic.Clients.Elasticsearch version: 8.6.2
Elasticsearch version: 8.1.1
.NET runtime version: 6.0
Operating system version: Windows 11
Description of the problem including expected versus actual behavior: CompositeAggregationSource is not serialized correctly. The query below is serialized to
{
"aggregations": {
"my_aggregation": {
"composite": {
"size": 10000,
"sources": [
{
"path": {
"terms": {
"terms": {
"field": "my_field"
}
}
}
}
]
}
}
},
"size": 0
}
Which fails to parse on the elastic search side as there are one nested "terms" to much. The error returned is: [composite] failed to parse field [sources]","caused_by":{"type":"x_content_parse_exception","reason":"[1:91] [terms] unknown field [terms]"}}
Steps to reproduce:
var response = await elasticClient
.SearchAsync<MyDocument>(
x => x.Index(indexName)
.Aggregations(aggregationDescriptor => aggregationDescriptor
.Composite(CompositeName, compositeAggregationDescriptor =>
{
var term = new TermsAggregation("my_aggregation")
{
Field = "my_field"
};
compositeAggregationDescriptor.Sources(new IDictionary<string, CompositeAggregationSource>[]
{
new Dictionary<string, CompositeAggregationSource>
{
{ CompositeKey, new CompositeAggregationSource { Terms = term } }
}
}).Size(10000).Size(0);
})));
Expected behavior I would expect the json to be:
{
"aggs": {
"my_aggregation": {
"composite": {
"size": 10000
},
"sources": {
"path": {
"terms": {
"field": "my_field"
}
}
}
}
},
"size": 0
}