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 @   szcj~  阅读(29)  评论(0编辑  收藏  举报
编辑推荐:
· AI与.NET技术实操系列(二):开始使用ML.NET
· 记一次.NET内存居高不下排查解决与启示
· 探究高空视频全景AR技术的实现原理
· 理解Rust引用及其生命周期标识(上)
· 浏览器原生「磁吸」效果!Anchor Positioning 锚点定位神器解析
阅读排行:
· DeepSeek 开源周回顾「GitHub 热点速览」
· 物流快递公司核心技术能力-地址解析分单基础技术分享
· .NET 10首个预览版发布:重大改进与新特性概览!
· AI与.NET技术实操系列(二):开始使用ML.NET
· 单线程的Redis速度为什么快?
点击右上角即可分享
微信分享提示