我正在尝试为已编入索引的某些事件获取直方图,但我只想在响应中使用'facet results'而不是search + facet结果。
这是我正在运行的查询的一个示例:
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
} ]
}
部分,没有与查询匹配的所有文档。
这可能吗?
非常感谢。
答案 0 :(得分: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
}
'