【发布时间】:2019-03-06 09:16:28
【问题描述】:
我有多个弹性搜索索引,我想获得doc_count 有多少文档与每个索引的查询匹配(即使没有文档与索引匹配)。我试过这个(使用 elasticsearch.js):
{
index: 'one,or,many,indices,here',
query: {
query_string: {
query: 'hello',
},
},
aggs: {
group_by_index: {
terms: {
field: '_index',
min_doc_count: 0,
},
},
},
from: 0,
size: 20,
};
这仅在我指定 index 键上的所有索引时才有效。但是,我并不总是希望在我的搜索结果中匹配所有索引中的文档。
所以我想出了:
{
index: 'all,indices,here',
query: {
bool: {
must: [
{
query_string: {
query: 'hello',
},
},
{
terms: {
_index: 'only,search,hits,indices,here',
},
},
],
},
},
aggs: {
group_by_index: {
terms: {
field: '_index',
min_doc_count: 0,
},
},
},
from: 0,
size: 20,
};
然后我得到doc_count: 0 用于匹配的索引,因为该索引不在 bool 查询中。
如何获取所有索引的 doc_count,但不能从不需要的索引中获取搜索命中?
【问题讨论】:
标签: elasticsearch elasticsearch-aggregation