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

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

相关推荐
Elasticsearch4 天前
Elastic Observability 的跨项目搜索:通过一个查询搜索所有关联项目
elasticsearch
Elasticsearch4 天前
Elasticsearch 中的 agentic 工作流:暂停 AI agent 等待人工审批,72 小时后恢复
elasticsearch
Elastic 中国社区官方博客4 天前
jina-ocr-v1:在低成本 GPU 上实现更快速的文档解析
大数据·数据库·elasticsearch·搜索引擎·全文检索·jina
vx-程序开发5 天前
【计算机毕设】django校园跑腿服务系统83141
java·数据库·vue.js·spring boot·spring·elasticsearch·django
Elasticsearch5 天前
jina-ocr-v1:在低成本 GPU 上实现更快速的文档解析
elasticsearch
深海鱼肝油ya5 天前
向量数据库Elasticsearch(四)搜索文档——各种方式
人工智能·elasticsearch·向量数据库·es搜索文档·只能体·非结构化数据库
Elasticsearch5 天前
SNAP 支付错误检测:Elastic 如何帮助美国各州应对 FY2028 的处罚
elasticsearch
Elastic 中国社区官方博客5 天前
使用 Elasticsearch 和 Jina 进行 AI 视频搜索:精准找到你需要的视频片段秒数
大数据·数据库·人工智能·elasticsearch·搜索引擎·ai·全文检索
Elasticsearch5 天前
2026 年唯一获得满分 Endpoint Prevention and Response(EPR)评分的是 Elastic
elasticsearch
Elasticsearch6 天前
没有小到无法记录的日志文件:Elastic Agent 如何跟踪低于 1 KiB 阈值的文件
elasticsearch