【发布时间】:2018-01-23 04:56:32
【问题描述】:
我正在尝试根据查询和过滤器确定聚合范围。我可以做以下事情:
- 将聚合范围限定为全局,但我只能指定过滤器以进一步缩小聚合结果集。我无法指定查询(或 multi_match)。
- 继承整个 elasticsearch 查询的范围(所以 multi_match),但我无法删除在整个请求中指定的过滤器。
这里是1的例子:
{
'colors' => {
global: {},
aggs: {
results: {
filter: {
bool: {
must: my_filters_without_this_filter(filter_to_ignore),
},
},
aggs: {
results: {
terms: {
field: 'color',
size: 10,
},
},
},
},
},
},
}
问题是我无法为上述聚合指定搜索字符串。
我的另一个选择是简单地继承整个查询,但是我无法删除过滤器:
{
"aggs": {
"colors": {
"filter": {
"bool": {
"must": [, {
"terms": {
"colors": ["red", "white", "blue", "green"]
}
}]
}
},
"aggs": {
"results": {
"terms": {
"field": "colors",
"size": 10
}
}
}
},
},
"query": {
"bool": {
"must": {
"function_score": {
"boost_mode": "replace",
"functions": [{
"script_score": {
"script": "my_script"
}
}],
"query": {
"multi_match": {
"query": "",
"type": "cross_fields",
"fields": ["name^6", "description", "barcode^2"],
"operator": "and",
"zero_terms_query": "all"
}
}
}
},
"filter": {
"bool": {
"must": [{
"terms": {
"colors": ["red"]
}
}]
}
}
}
}
}
在上述查询中,出于聚合目的,我想忽略指定的过滤器(红色)。
是否可以有一个全局范围的聚合,但也可以指定一个过滤器和一个查询?
我不希望每个请求进行 2 个 elasticsearch 查询,但看起来我可能需要这样做。
【问题讨论】:
标签: elasticsearch