ElasticSearch。索引中唯一术语的总数

时间:2015-11-30 16:08:58

标签: elasticsearch

有没有办法通过ES API访问索引中的术语总数? 我需要估计一个术语在索引中出现的先验概率:

total_term_frequency/total_terms_in_index

我可以访问ttf但不能存储在索引中的条款总数。

1 个答案:

答案 0 :(得分:1)

我认为cardinality aggregation是您正在寻找的。

例如:

POST /test_index/_search
{
   "size": 0,
   "aggs": {
      "term_count": {
         "cardinality": {
            "field": "doc_text"
         }
    }
}
...
{
   "took": 7,
   "timed_out": false,
   "_shards": {
      "total": 5,
      "successful": 5,
      "failed": 0
   },
   "hits": {
      "total": 4,
      "max_score": 0,
      "hits": []
   },
   "aggregations": {
      "term_count": {
         "value": 161
      }
   }
}

以下是我用来玩它的一些代码:

http://sense.qbox.io/gist/d5625c80946f332718b0fa166bba27efd264b76e

相关问题