ES实战-高级聚合

多桶型聚合
1.词条聚合–terms
2.范围聚合–range
3,直方图聚合–histogram/日期直方图
4.嵌套聚合
5.地理距离聚合
include(包含)exclude(不包含)

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

range范围聚合统计

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

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

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

你可能感兴趣的:(ES实战,elasticsearch)