elasticsearch去重計數


如果需要針對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名字。


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM