Get the corresponding document from a min aggregation

Hello,

i'm querying an aggregation for the minimum and maximum price in an index, like this:

"aggregations": {
    "PriceMin": {
      "min": {"field": "PriceProduct"}
    },
    "PriceMax": {
      "max": {"field": "PriceProduct"}
    }
  }

However, i'd like to get the corresponding documents, i.e. the document that contains the min price, and also the one that contains the max price. If several documents apply it doesn't matter if i get all of them or just a single one.

Is there a good solution for that?

Hi Toast.
Use the top_hits aggregation with a "size":1 setting and appropriate sort order.

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