如果需要针对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名字。

相关文章:

  • 2022-12-23
  • 2021-06-26
  • 2021-04-14
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-09-14
猜你喜欢
  • 2021-05-31
  • 2022-12-23
  • 2021-11-05
  • 2022-03-06
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案