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

Creating aggregation from json via supplied reader

Open SwonVIP opened this issue 9 months ago • 1 comments

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<Aggregation>

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

SwonVIP avatar May 02 '24 14:05 SwonVIP

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

l-trotta avatar May 03 '24 07:05 l-trotta