Top_hits aggregation performance problem

Hello everyone,

I've a query which returns response in 3k-4k ms. When i remove top_hits aggregations it reduces to 60-70 ms. Why is top_hits aggregation so slow? How can i speed up my query? Is there any alternative to top_hits aggregation?

That's my query btw:

POST payments/_search?size=0
{
  "query": {
    "bool": {
      "must": [
        {"term": {
          "currency.keyword": {
            "value": "EUR"
          }
        }
        },
        {
          "range": {
            "@timestamp": {
              "gte": "2019-01-01",
              "lte": "2019-01-07"
            }
          }
        }
      ]
    }
  }, 
 "aggs": {
   "date_his": {
     "date_histogram": {
       "field": "@timestamp",
       "fixed_interval": "1m"
     },
     "aggs": {
       "volume": {
         "sum": {
           "field": "price"
         }
       },
       "max_price": {
         "max": {
           "field": "price"
         }
       },
       "min_price": {
         "min": {
           "field": "price"
         }
       },
       "first":{
         "top_hits": {
           "size": 1,
           "sort": [{"@timestamp":{"order":"asc"}}],
           "_source": {"includes": "price"}
         }
       },
       "last": {
         "top_hits": {
           "size": 1,
           "sort": [{"@timestamp": {"order":"desc"}}],
           "_source": {"includes": "price"}
         }
       }
     }
   }
 }
}

I am wondering if this is the typical case where using top_metrics instead of top_hits should help:

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