在Elasticsearch 5.0中,Indices Query has been marked as deprecated。
文档告诉我"在_index
字段上搜索",但对我来说,如何做到这一点并不明显。如何将这样的示例查询更改为新方法?
GET /_search
{
"query": {
"bool": {
"minimum_number_should_match": 1,
"should": [
{"indices": {
"indices": ["index1"],
"no_match_query": "none",
"query": {
"bool": {"must": [
{"multi_match": {"fields": ["field1", "field2"], "operator": "or", "query": "foobar", "type": "boolean", "use_dis_max": true}},
{"multi_match": {"fields": ["field1", "field2"], "operator": "or", "query": "xuul", "type": "boolean", "use_dis_max": true}}
]}}
}},
{"indices": {
"indices": ["index2", "index3"],
"no_match_query": "none",
"query": {"bool": {"must": [
{"multi_match": {"fields": ["field1", "field2"], "operator": "or", "query": "foobar", "type": "boolean", "use_dis_max": true}}
]}}}}
]}
}
}
答案 0 :(得分:4)
你可以尝试这样:
{
"bool": {
"minimum_number_should_match": 1,
"should": [
{
"bool": {
"filter": [
{
"terms": {
"_index": ["index1"]
}
},
{
"bool": {
"must": [
{
"multi_match": {
"fields": [
"field1",
"field2"
],
"operator": "or",
"query": "foobar",
"type": "boolean",
"use_dis_max": true
}
},
{
"multi_match": {
"fields": [
"field1",
"field2"
],
"operator": "or",
"query": "xuul",
"type": "boolean",
"use_dis_max": true
}
}
]
}
}
]
}
},
{
"bool": {
"filter": [
{
"terms": {
"_index": [
"index2",
"index3"
]
}
},
{
"bool": {
"must": [
{
"multi_match": {
"fields": [
"field1",
"field2"
],
"operator": "or",
"query": "foobar",
"type": "boolean",
"use_dis_max": true
}
}
]
}
}
]
}
}
]
}
}