Skip to content

Searches with FilterAggregations fails to deserialize the response from the server. #7844

Closed
@Hesehus-ASAL

Description

@Hesehus-ASAL

Elastic.Clients.Elasticsearch version:8.1.3

Elasticsearch version:8.6.2

.NET runtime version:6.0

Operating system version:Windows 11

Description of the problem including expected versus actual behavior:
A clear and concise description of what the bug is.

Steps to reproduce:
Run this code:

var settings = new ElasticsearchClientSettings(new Uri("https://localhost:9200"))
    .Authentication(new BasicAuthentication("elastic", "ELASTIC_PASSWORD"));
settings.DisableDirectStreaming();

var docs = DocGenerator.Generate(20);
settings.ThrowExceptions(false);
var client = new ElasticsearchClient(settings);
var indexName = "doc_index";

await client.Indices.CreateAsync<Doc>(x =>
{
    x.Index(indexName).Mappings(y => y.Properties(p => p.Keyword(n => n.Color)));
});

await client.IndexManyAsync(docs, indexName);


var filters = new Buckets<Query>(new Dictionary<string, Query>
    { { "color_filter", new MatchQuery("Color") { Query = "red" } } });
var aggregationDescriptor = new AggregationDescriptor<Doc>();

aggregationDescriptor.Terms("color_aggregate",
        termsAggregationDescriptor => termsAggregationDescriptor.Field(n => n.Color))
    .Filters("bucket_name",
        descriptor => descriptor.Filters(filters));

var searchRequest = new SearchRequestDescriptor<Doc>();
searchRequest.Aggregations(aggregationDescriptor);
searchRequest.Index(indexName);

/*This fails with exception */
await client.SearchAsync(searchRequest);


public class Doc
{
    public string Id { get; set; }
    public string Color { get; set; }
}

public static class DocGenerator
{
    private static string[] colors = new[] { "red", "green", "blue" };

    public static Doc[] Generate(int docCount)
    {
        var docs = new Doc[docCount];
        for (int i = 0; i < docCount; i++)
        {
            docs[i] = new Doc() { Color = colors[i % 3], Id = i.ToString() };
        }
        return docs;
    }
}

Expected behavior
SearchAsync returns a search result with the aggregations filters

Provide ConnectionSettings (if relevant):

Provide DebugInformation (if relevant):
Stacktrace:
'The JSON value could not be converted to System.Collections.Generic.IReadOnlyCollection1[Elastic.Clients.Elasticsearch.Aggregations.FiltersBucket].'`

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions