用于计算弹性搜索中的索引和类型命中的方面

raf*_*ian 9 indexing faceted-search elasticsearch

我正在使用下面的查询在博客索引中找到"开发者"这个词......

http://localhost:9200/blog/_search
{ 
   "query": {
     "query_string": {
        "query": "developer"
      }
    }
}
Run Code Online (Sandbox Code Playgroud)

该查询返回3次点击user和1 次点击post类型,我想要一个方面来反映那些点击显示像...

搜索结果...
博客帖子(1)
用户(3)

...但我不确定如何将一个方面与一个查询结合起来计算这些命中数,因为大多数例子我发现了计数字段命中率; 我尝试使用_index返回索引命中,但无法使其工作; 是否有类似的类型,例如_type,计算索引中的文档类型命中?

raf*_*ian 11

好吧,想通了,显然有一个_type方面的基础,基于此...

http://elasticsearch-users.115913.n3.nabble.com/enabled-quot-index-quot-does-not-allow-me-to-get-facet-values-td1056215.html

询问

http://localhost:9200/blog/_search

    {
      "size" : 0,
      "query" : {   
         "query_string" : {
            "query" : "developer"}
       },
      "facets" : {
        "type" : {
          "terms" : { "field" : "_type"}
        }
      }
    }
Run Code Online (Sandbox Code Playgroud)

响应

{
  ...
  "facets": {
    "type": {
      "_type": "terms",
      "missing": 0,
      "total": 4,
      "other": 0,
      "terms": [
        {
          "term": "user",
          "count": 3
        },
        {
          "term": "post",
          "count": 1
        }
      ]
    }
  }
}
Run Code Online (Sandbox Code Playgroud)