Elasticsearch Nested Aggregation

I have some documents in Elasticsearch. I want to aggregate with tags equals 5 and sort by evaluationCount in aggregates data.

I used min query at busEvaluationCount, but I want to aggregating for tags:5. I dont got it how can I do this?

      id:1
     {"date":"2017-12-24","lastUpdatedAt":"2017-12-24 00:04:46","origin":"LON","destination":"LHR","price":1685.44,"originCity":"LON","globalRank":4,"tags":[{"evaluationCount":199965,"tag":1},{"evaluationCount":199930,"tag":5},],"destinationCity":"LON",}

      id:2
      {"date":"2017-12-24","lastUpdatedAt":"2017-12-24 00:04:46","origin":"LON","destination":"LHR","price":1285.44,"originCity":"LON","globalRank":4,"tags":[{"evaluationCount":1000,"tag":1},{"evaluationCount":2000,"tag":5},],"destinationCity":"LON",}

This here the search section.

      {"aggs":{"groupByCity":{"aggs":{"busEvaluationCount":{"min":{"field":"tags.evaluationCount"}},"busGlobalRankCount":{"min":{"field":"globalRank"}},"busPrice":{"min":{"field":"price"}},"sourceDocument":{"aggs":{"dedupDocs":{"top_hits":{"size":1,"sort":[{"tags.evaluationCount":"desc"},{"price":"asc"}]}}},"terms":{"field":"destinationCity.keyword","size":1}}},"terms":{"field":"destinationCity.keyword","order":{"busEvaluationCount":"desc"},"size":1000000}}},"query":{"bool":{"must":[{"match":{"originCity":"LON"}},{"query_string":{"query":"tags.tag:5"}},{"range":{"date":{"gte":"2018-08-06","include_lower":true,"include_upper":true,"lte":"2019-02-06"}}}]}},"size":0,"sort":{"price":{"order":"asc"}}}

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