2012-05-23 48 views
16

我試圖得到我已經索引的一些事件的直方圖,但我只希望在響應'facet results'而不是搜索+ facet結果。ElasticSearch方面的結果沒有文檔

這是我運行查詢的示例:

curl -XGET 'http://localhost:9200/main/events/_search?pretty=true' -d ' 
{ 
    "facets" : { 
    "histo1" : { 
     "query" : { 
      "query_string" : {"query":"*:*"} 
     }, 
     "date_histogram" : { 
      "field" : "time", 
      "interval" : "minute" 
     } 
    } 
    } 
} 
' 

所以結果我想剛纔的

"facets" : { 
"histo1" : { 
    "_type" : "date_histogram", 
    "entries" : [ { 
    "time" : 1337700000, 
    "count" : 76 
    } ] 
} 

一部分,沒有所有與查詢匹配的文件。

這可能嗎?

非常感謝。

回答

28

您可以使用count SEARCH_TYPE:

curl -XGET 'http://localhost:9200/main/events/_search?search_type=count&pretty=true' -d ' 
{ 
    "facets" : { 
    "histo1" : { 
     "query" : { 
      "query_string" : {"query":"*:*"} 
     }, 
     "date_histogram" : { 
      "field" : "time", 
      "interval" : "minute" 
     } 
    } 
    } 
} 
' 

或者,您可以設置"size":0您的查詢,但它的效率會降低:

curl -XGET 'http://localhost:9200/main/events/_search?pretty=true' -d ' 
{ 
    "facets" : { 
    "histo1" : { 
     "query" : { 
      "query_string" : {"query":"*:*"} 
     }, 
     "date_histogram" : { 
      "field" : "time", 
      "interval" : "minute" 
     } 
    } 
    }, 
    "size":0 
} 
' 
+0

SEARCH_TYPE =計數現在已經過時https://開頭www.elastic.co/guide/en/elasticsearch/reference/current/breaking_21_search_changes.html – ymonad

相關問題