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 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.
Apache, Apache Lucene, Apache Hadoop, Hadoop, HDFS and the yellow elephant
logo are trademarks of the
Apache Software Foundation
in the United States and/or other countries.