首页 > 其他 > 详细

elasticsearch去重计数

时间:2020-03-28 12:07:19      阅读:150      评论:0      收藏:0      [点我收藏+]

如果需要针对ES索引统计某个字段上出现的不同值的个数时,可以使用cardinality聚合查询完成:

Post /urlAttributes/_search?search_type=count
{
  "aggs": {
    "uniq_attr": {
      "cardinality": {
        "field": "domain"
      }
    }
  }
}

 

注释:如上,是查询索引urlAttributes中domain字段上的不同值个数, "uniq_attr"是用户自己取的bucket名字。

得到的响应如下所示:

{    "took": 28,    "timed_out": false,    "_shards": {       "total": 6,       "successful": 6,       "failed": 0    },    "hits": {       "total": 689562,       "max_score": 0,       "hits": []    },    "aggregations": {       "uniq_attr": {          "value": 121618       }    } }

返回结果表示该字段出现过121618个不同的domain名字。

elasticsearch去重计数

原文:https://www.cnblogs.com/suntp/p/9562130.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!