2017-09-01 42 views
0

我想运行一个弹性查询使用_count来计数。弹性搜索以获得个人条款计数

{ 
     "query": { 
     "bool": { 
      "must": [ { 
       "term": { 
          "A": "image" 
         } 
        }, 
        { 
       "aggs" : { 
         "C" : { 
           "terms" : { "field" : "C" , 
           "include" : ["X:969", "Y:96"] 
              } 
           } 
         }     
        } 
        ] 
       } 
       } 
    } 

现在我得到预期的输出。

{ 
    "count": 321, 
    "_shards": { 
    "total": 19, 
    "successful": 19, 
    "failed": 0 
    } 
} 

但反正是有得到的输出喜欢

X:969 count 2 
    Y:96 count 319 

基本上找个别情况,而不是即使当数组传递总数。

问候。

回答

0

计数API只是Search API的一个子集,您需要使用terms aggregation来按字段计算计数。也许它不是可以使用在伯爵API此聚集,所以你可能会考虑运行你的查询对_search

{ 
    "aggs" : { 
     "C" : { 
      "terms" : { "field" : "C" } 
     } 
    } 
} 
+0

谢谢,我如何通过此阵“条款”:{“场”:“C”}我尝试通过它在[],但失败 – user2854333

+0

请添加新的查询作为问题的一部分? – Mysterion

+0

已更新查询 – user2854333