Search code examples
javaelasticsearchelasticsearch-aggregation

Range Aggregation with min and max aggregation in java


I have a scenario where I need to build range aggregation for elastic search in java for numeric field, but I do not have the range. I need to calculate range(min and max) from existing documents and then pass it to range aggregation. How can we do it ? Is it the case where we can combine range, min and max aggregation?


Solution

  • Ideally it is possible to pick a value or type of value/results from the output of an aggregation to be reused in another family of aggregation. This family of aggregation are called Pipeline Aggregation https://www.elastic.co/guide/en/elasticsearch/reference/current/search-aggregations-pipeline.html

    However Range Aggregation is not part of the Pipeline sibling aggregation. So, you in your scenario, you would need to make a 1st query (with the min and max as the two metric aggregations https://www.elastic.co/guide/en/elasticsearch/reference/current/search-aggregations-metrics.html) to fetch the min and max value and then reuse the data to make the 2nd call to ES.