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
      }
    }
  }
}

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

相关推荐
Elasticsearch13 小时前
深入解析 simdvec:Elasticsearch 如何利用神经网络和视频编解码 CPU 指令实现向量搜索
elasticsearch
Elasticsearch1 天前
一条命令。自然语言。你的 Elasticsearch 数据,直接进入终端
elasticsearch
vivo互联网技术2 天前
从 10 分钟到 1 秒:ES 深度分页任意跳页的三轮优化实战
服务器·数据库·redis·elasticsearch·深度分页
Elasticsearch2 天前
热力直达:使用 Elasticsearch 插件将 ES|QL 引入你的 Grafana 仪表板
elasticsearch
小猿姐2 天前
唯品会大规模数据库云原生实践:基于 KubeBlocks 管理数千实例的统一运维之路
运维·elasticsearch·云原生
Elasticsearch3 天前
使用 Elastic Agent Builder 和 Sarvam AI 构建多语言语音 agent
elasticsearch
武子康7 天前
调查研究-197 FAISS vs Elasticsearch 全面对比:从向量检索、全文搜索到 RAG 选型指南
人工智能·elasticsearch·agent
Elasticsearch8 天前
Elasticsearch ES|QL:现已支持视图、子查询和读取时模式定义
elasticsearch
Elasticsearch10 天前
Kibana 中的 SNMP 拓扑数据:从采集到 Canvas
elasticsearch