Elasticsearch 聚合操作

 1. 聚类统计

说明:

根据deviceId字段聚类,类似select column,count(*)  from table_name  group by cloumn

请求URL:

POST  http://*.*.*.*:9200/index_name/_search

request:

 

{
  "query": {
    "range": {
      "captureTime": {
        "gte": 1645768329000,
        "lte": 1646031696000
      }
    }
  },
  "size": 0,
  "aggs": {
    "my-agg-name": {
      "terms": {
        "field": "deviceId"
      }
    }
  }
}

 

response:


{
    "took": 6,
    "timed_out": false,
    "_shards": {
        "total": 5,
        "successful": 5,
        "skipped": 0,
        "failed": 0
    },
    "hits": {
        "total": {
            "value": 516,
            "relation": "eq"
        },
        "max_score": null,
        "hits": []
    },
    "aggregations": {
        "my-agg-name": {
            "doc_count_error_upper_bound": 0,
            "sum_other_doc_count": 7,
            "buckets": [
                {
                    "key": "10137422912377a",
                    "doc_count": 161
                },
                {
                    "key": "3floor",
                    "doc_count": 80
                },
                {
                    "key": "shanghai",
                    "doc_count": 71
                },
                {
                    "key": "5kxU00Yi0BxmUf1af65e3",
                    "doc_count": 46
                },
                {
                    "key": "shanghai2",
                    "doc_count": 43
                },
                {
                    "key": "22eferwg",
                    "doc_count": 41
                },
                {
                    "key": "5kxU00Yi0BxVW014019d4",
                    "doc_count": 38
                },
                {
                    "key": "5kxU00Yi0BxmUl1316778",
                    "doc_count": 11
                },
                {
                    "key": "473fweofw",
                    "doc_count": 10
                },
                {
                    "key": "5kxU00Yi0BxVW510dec95",
                    "doc_count": 8
                }
            ]
        }
    }
}
 

 

posted @ 2022-03-02 22:43  szcj~  阅读(39)  评论(0)    收藏  举报