1

I have a field, location.vertical.depth.value, which is a float_range field. I'd like Elasticsearch to return the minimum lower bound for this field across all query results.

An example document might be:

{
    "location": {
        "vertical": {
            "depth": {
                "value": {
                    "gte": 42.0,
                    "lte": 64.0
                }
            }
        }
    }
}

This is my attempt:

"aggs": {
    "min_depth": { "min": { "field": "location.vertical.depth.value" } }
}

This throws an exception:

class org.elasticsearch.search.aggregations.support.ValuesSource$Range cannot be cast to class org.elasticsearch.search.aggregations.support.ValuesSource$Numeric

Interestingly though I can do something similar with a date_range field with "min_date": { "min": { "field": "date" } }.

3
  • recent version of elastic give a more clear message. But it's exactly the same "Field [duration_range] of type [integer_range] is not supported for aggregation [min]". To do this you have to keep the value itself and aggregate on it. or use a script Commented Sep 15, 2020 at 4:57
  • Can you share a sample doc? Commented Sep 15, 2020 at 11:15
  • 1
    @Joe I included an example document. Commented Sep 15, 2020 at 14:01

1 Answer 1

1

min and max aggs on range data types are currently not supported. The alternative is a script, just like @Jaycreation suggested:

{
  "size": 0,
  "aggs": {
    "min_depth": {
      "min": {
        "script": {
          "source": "params._source.location.vertical.depth.value.gte;"
        }
      }
    }
  }
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.