elasticsearch-net icon indicating copy to clipboard operation
elasticsearch-net copied to clipboard

CompositeAggregationSource is not serialized correctly

Open asal-hesehus opened this issue 11 months ago • 3 comments

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
}

asal-hesehus avatar Jul 12 '23 05:07 asal-hesehus