How to use the Java API to build an Aggregation from JSON in 6.2.4?

I found the same question here. But this is not working in ES 6.2.4.

In old version, we can do this:
SearchRequestBuilder builder = client.prepareSearch(index);
QueryBuilder queryBuilder = getQueryBuilder(query);
builder.setQuery(queryBuilder); // set query
builder.setAggregations(agg.toString().getBytes()); // set aggregation

But in 6.2.4, we only have these 2 APIs:
builder.addAggregation(AggregationBuilder aggregation)
builder.addAggregation(PipelineAggregationBuilder aggregation)

How to make the "set aggregation" from JSON string work correctly?

I have same issue, high level rest client doesn't seem to let you do it.

In the end, we use low level client to send the "json query string" directly to ES to get response.

I took a different route, made an XContentParser and parsed the json directly into a SearchSourceBuilder. The ES unit tests had some code for doing it.

@Matt_Chambers1 Can you show me the link about “ES unit tests” if you have it ? Thanks.

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.