使用弹性搜索中的术语facet返回单个文档的术语计数

时间:2013-12-27 10:29:45

标签: json api http elasticsearch

说我有以下搜索查询......

POST /topics/_search
{
    "fields": [
       "topic_attachment",
       "topic_replies",
       "topic_status"
    ],
    "query" : {
        "filtered" : {
            "query" : {
                "term" : { 
                    "_id" : "5478"
                }
            }
        }           
    },
    "facets": {
       "text": {
          "terms": {
             "field": "text",
             "size": 10,
             "order": "count"
            }
       }
    }
}

此搜索的结果如下:

{
   "took": 93,
   "timed_out": false,
   "_shards": {
      "total": 5,
      "successful": 5,
      "failed": 0
   },
   "hits": {
      "total": 1,
      "max_score": 1,
      "hits": [
         {
            "_index": "topics",
            "_type": "full-topic",
            "_id": "5478",
            "_score": 1,
            "fields": {
               "topic_replies": 1141,
               "topic_status": 0,
               "topic_attachment": false
            }
         }
      ]
   },
   "facets": {
      "text": {
         "_type": "terms",
         "missing": 0,
         "total": 8058,
         "other": 8048,
         "terms": [
            {
               "term": "ω",
               "count": 1
            },
            {
               "term": "œyouâ",
               "count": 1
            },
            {
               "term": "œyou",
               "count": 1
            },
            {
               "term": "œwhisperedâ",
               "count": 1
            },
            {
               "term": "œwalt",
               "count": 1
            },
            {
               "term": "œunderstandingâ",
               "count": 1
            },
            {
               "term": "œtieâ",
               "count": 1
            },
            {
               "term": "œthe",
               "count": 1
            },
            {
               "term": "œpersonally",
               "count": 1
            },
            {
               "term": "œnappiesâ",
               "count": 1
            }
         ]
      }
   }
}

每个术语的计数正好为1.这是为什么?我知道这份文件中的文字有不止一个共同的用语。这是因为术语计数每个文档只增加一次吗?如果是这样,我如何从单个文档中多次计算一个术语?

1 个答案:

答案 0 :(得分:3)

这是文件计数,而不是术语频率。幸运的是,新的aggregations模块(替换1.0.Beta2中引入的方面)count已重命名为doc_count以澄清它是什么。

相关问题