ES实战-高级聚合

多桶型聚合

1.词条聚合--terms

2.范围聚合--range

3,直方图聚合--histogram/日期直方图

4.嵌套聚合

5.地理距离聚合
include(包含)exclude(不包含)

bash 复制代码
GET /get-together/_search?pretty
{
  "size": 0,
  "aggs": {
    "tags": {
      "terms": {
      "field": "tags.verbatim",
      "include": ".*search.*"
      }
    }
  }
}

range范围聚合统计

bash 复制代码
GET /get-together/_search
{
  "aggs": {
    "attendees_breakdown": {
      "range": {
        "script": {
          "source": "doc['attendees'].size()"
        },
        "ranges": [
          {"to": 4},
          {"from": 4,"to": 6},
          {"from": 6}
        ]
      }
    }
  }
}

histogram定义一个固定间距,es会自动构建范围.

bash 复制代码
#ES会构建从最小值开始的范围,并不断加入interval,
#直到包含最大值
GET /get-together/_search
{
  "aggs": {
    "attendees_histogram": {
      "histogram": {
        "script": {
          "source": "doc['attendees'].size()"
        },
        "interval": 1
      }
    }
  }
}

通过嵌套聚合获得结果分组

相关推荐
liu_sir_4 小时前
升级谷歌webview
大数据·elasticsearch·搜索引擎
Elastic 中国社区官方博客9 小时前
Elasticsearch 下采样方法:最后值采样 vs. 聚合采样
大数据·运维·elasticsearch·搜索引擎·全文检索
Andya_net12 小时前
Git | Git 核心命令深入解析:从原理到实战
大数据·git·elasticsearch
不仙5201 天前
VMware Workstation 26.0.0 在 Ubuntu 24.04 (内核 6.17.0) 上的安装与内核模块编译问题
linux·ubuntu·elasticsearch
qziovv1 天前
Git 回退场景
大数据·git·elasticsearch
ZeroNews内网穿透1 天前
面向 AI 协作的本地客户端能力:ZeroNews Agent Skills
大数据·人工智能·elasticsearch
Elastic 中国社区官方博客1 天前
快 12 倍的 Elasticsearch 向量索引:使用 GPU 和 CPU 分层部署 NVIDIA cuVS
大数据·人工智能·elasticsearch·搜索引擎·ai·全文检索·nvidia
海兰1 天前
【实用应用】React+TypeScript+Next.js博客项目
开发语言·javascript·elasticsearch
乐观的Terry1 天前
博客系统全文搜索实战:用 Elasticsearch 告别 MySQL LIKE 查询
mysql·elasticsearch
敖正炀1 天前
索引写入与数据持久化深度
elasticsearch