elastic / elasticsearch-java

Official Elasticsearch Java Client
Apache License 2.0
397 stars 228 forks source link

Creating aggregation from json via supplied reader #795

Closed SwonVIP closed 1 month ago

SwonVIP commented 2 months ago

Java API client version

8.13.2

Java version

OpenJDK Runtime Environment Temurin-21.0.2+13

Elasticsearch Version

8.6.2

Problem description

Hello,

it seems like the fromJson method on the Aggregation and Query objects work differently and the Builders returned work a bit different.

In our test setup we are using a function like this to create a query fixture from a supplied json which works fine:

    public static Query createQueryFromFile(String fileContent) {
        return Query.of(q1 -> q1.withJson(new StringReader(fileContent)));
    }

However doing the same for aggregations results in a type error:

    public static Aggregation createAggregationFromFile(String fileContent) {
        return Aggregation.of(agg1 -> agg1.withJson(new StringReader(fileContent)));
    }   

Bad return type in lambda expression: Builder cannot be converted to ObjectBuilder

So it seems the interface is different although to me as a consumer they should work in a similar way?

l-trotta commented 2 months ago

Hello, thank you for reporting this! Yes in theory it should work the same, we'll investigate on this.