我正在尝试获取已编入索引的某些事件的直方图,但我只希望响应中包含“方面结果”,而不是搜索 + 方面结果。
这是我正在运行的查询示例:
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
} ]
}
部分,没有匹配查询的所有文档。
这可能吗?
非常感谢。
最佳答案
您可以使用 count搜索类型:
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
}
'
关于没有文档的 ElasticSearch 分面结果,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10715812/