Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ArgMax and ArgMin aggregations #10716

Closed
rcrezende opened this issue Apr 22, 2015 · 2 comments
Closed

ArgMax and ArgMin aggregations #10716

rcrezende opened this issue Apr 22, 2015 · 2 comments

Comments

@rcrezende
Copy link

Have argmin and argmax aggregations [http://en.wikipedia.org/wiki/Arg_max]

As percentiles, that would be a multi-value metric aggregation, but size limit controls that.

Request

{
    "aggs" : {
        "product_with_max_price" : {
            "argmax" : { 
                "arg" : "price",
                "field" : "product",
                "size" : 5
              }
          }
    }
}

Response

{
    ...
    "aggregations": {
        "product_with_max_price": {
            "values": {
               "ferrari" : 500000,
               "lamborghini" : 500000
            }
        }
    }
}
@colings86
Copy link
Contributor

@rcrezende you should be able to get this information with the existing aggregations by using the terms and max aggregations:

{
  "aggs": {
    "product_with_max_price": {
      "terms": {
        "field": "product",
        "size": 5,
        "order": {
          "max_price": "desc"
        }
      },
      "aggs": {
        "max_price": {
          "max": {
            "field": "price"
          }
        }
      }
    }
  }
}

This will get a list of the top 5 terms ordered by maximum price. Your client can then look for the top N which have the same value. With #10000 coming in 2.0 you could use the max_bucket aggregation to do this last step for you and return only the terms which have the maximum value.

A similar approach could be used for the argmin.

@clintongormley
Copy link

Agree with @colings86 - going to close this

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants