我正在使用AWS上的Elasticsearch 5.3.3
我在搜索查询中有多个过滤器,每个过滤器都有一个_name
。这些名称在结果中反映为matched_queries
。我想将这些结果分组到不同的桶中,其中每个桶的选择标准是matched_queries
中存在一个或多个过滤器名称。
以下是一个示例请求:
GET my_index/_search
{
"query": {
"bool": {
"must": [
{ "terms": { "bed": [0, 1, 2] } },
{ "terms": { "contract": ["none", "good", "tight"] } }
],
"should": [
{
"terms": {
"bed": ["0", "1"],
"_name": "exact_beds"
}
},
{
"term": {
"bed": {
"value": 2,
"_name": "increased_beds"
}
}
},
{
"terms": {
"contract": ["good", "tight"],
"_name": "money"
}
},
{
"term": {
"contract": {
"value": "none",
"_name": "no_money"
}
}
}
]
}
}
}
它将输出类似
的内容{
"took": 19,
"timed_out": false,
"_shards": {
"total": 5,
"successful": 5,
"failed": 0
},
"hits": {
"total": 297256,
"max_score": 5.8605247,
"hits": [
{
"_index": "my_index",
"_type": "listing",
"_id": "49932563",
"_score": 5.8605247,
"_source": {
"bed": 1,
"contract": "good",
},
"matched_queries": [
"money",
"exact_beds"
]
}
]
}
}
我想在我的请求中添加这样的内容
"aggs": {
"E1": {
"filter": {
"script": {
"script": {
"lang": "painless",
"inline": "matched_queries.contains('exact_beds') && matched_queries.contains('money')"
}
}
}
}
但我收到错误"Variable [matched_queries] is not defined."
。有没有办法访问matched_queries
?