How to filter an index by the maximum value of a field?

There is a field in the index by the name of date but the data of that field is not in a proper date format its only a number. So I want a filter to include only the data of maximum data of date field I mean how to create a filter which finds the maximum value of the date field and filter the index based upon that value.

Terms aggregation with order on _key will create a bucket for sub-aggregation.

GET kibana_sample_data_flights/_search
{
  "size":0,
  "aggs": {
    "MaxFlightDelay": {
      "terms": {
        "field": "FlightDelayMin",
        "order": {"_key":"desc"},
        "size": 1
      },
      "aggs": {
        "hit": {
          "top_hits": {
            "size": 10
          }
        }
      }
    }
  }
}

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