9

我正在使用下面的查询在博客索引中查找“开发者”一词...

http://localhost:9200/blog/_search
{ 
   "query": {
     "query_string": {
        "query": "developer"
      }
    }
}

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

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

...但是我不确定如何将构面与查询相结合来计算此类命中,因为大多数示例我发现计数字段命中;我尝试使用_index返回索引命中,但无法让它工作;类型是否有类似的东西,例如_type,计算索引中的文档类型命中?

4

1 回答 1

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"}
        }
      }
    }

回复

{
  ...
  "facets": {
    "type": {
      "_type": "terms",
      "missing": 0,
      "total": 4,
      "other": 0,
      "terms": [
        {
          "term": "user",
          "count": 3
        },
        {
          "term": "post",
          "count": 1
        }
      ]
    }
  }
}
于 2013-06-21T22:17:12.993 回答