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

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

相关推荐
Elastic 中国社区官方博客1 天前
Elasticsearch 向量数据库:几分钟内完成部署,以经济高效的方式扩展至数千亿规模
大数据·运维·数据库·elasticsearch·搜索引擎·ai·全文检索
Elasticsearch1 天前
将 Vercel 数据导入 Elastic:无需安装任何东西的无服务器可观测性
elasticsearch
Elastic 中国社区官方博客2 天前
Elasticsearch Python DSL 客户端开发
大数据·数据库·python·elasticsearch·搜索引擎·全文检索
阿里云大数据AI技术2 天前
Al Search x ES Agent Builder:让数据活起来,从搜索走向行动
人工智能·elasticsearch·agent
Elasticsearch2 天前
Elastic Agent Builder 中能够引用证据的 AI 根因分析
elasticsearch
考虑考虑2 天前
elasticSearch中的element_type
运维·后端·elasticsearch
CHANCE V2 天前
Elasticsearch 进阶
大数据·elasticsearch·搜索引擎
Elasticsearch2 天前
Elasticsearch 向量数据库:几分钟内完成部署,以经济高效的方式扩展至数千亿规模
elasticsearch
vx-Biye_Design2 天前
SSM伴侣动物伴护星小程序06330-计算机课程设计、毕业设计
spring boot·后端·elasticsearch·小程序·架构·课程设计·idea