24 May 2022

Elastic: Group_By and sort

get /my_index/_search
{
  "query": {
    "bool": {
      "filter": [
        {
          "range": {
            "block_time": {
              "gt": "2013-11-21T05:17:33",
              "lt": "2023-11-19T10:30:33"
            }
          }
        },
        {
          "term": {
            "mytoken": "token14"
          }
        }
      ]
    }
  },
  "_source": false,
  "aggs": {
    "block_height_agg": {
      "terms": {
        "field": "block_height",
        "size": 5,
        "order": {"_key": "desc"}
      }
    }
  },
  "size": 3
}


Example to GROUP BY block_height and SORT it

No comments:

Post a Comment

Terima kasih