Max ES Query

Dear Forum,

I need some help to design a query I have some difficulties.
I need the maximum value of two fields (i.e. numerical ones). I have figured out by myself the max of one value with this query:

    {
      "size": "0",
      "aggs": {
        "max_myField": {
          "max": {
            "field": "myFieldOne"
          }
        }
      }
    }

but how to have the max value among myFieldOne and myFiledTwo ?

Regards,
S.

If both fields always exist:

POST /_search
{
  "size": 0,
  "aggs": {
    "max_price": {
      "max": {
        "script": {
          "source": "Math.max(doc.myFieldOne.value, doc.myFieldTwo.value)"
        }
      }
    }
  }
}

Thanks!

S.

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