elasticsearch聚合系列之cardinality

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/u010503427/article/details/81592468

cardinality 即去重计算,类似sql中 count(distinct),先去重再求和,计算指定field值的种类数。

下面实例,计算有多少个不同的city。

请求:

POST bank/_doc/_search
{
  "size": 0,
  "aggs": {
    "cartinality_gender": {
      "cardinality": {
        "field": "city.keyword"
      }
    }
  }
}

响应:

{
  "took": 2,
  "timed_out": false,
  "_shards": {
    "total": 5,
    "successful": 5,
    "skipped": 0,
    "failed": 0
  },
  "hits": {
    "total": 15,
    "max_score": 0,
    "hits": []
  },
  "aggregations": {
    "cartinality_gender": {
      "value": 15
    }
  }
}

 

阅读更多

没有更多推荐了,返回首页