Json 过滤器'_指数';与'相同_类型';在搜索中跨多个索引查询弹性搜索
我有两个索引index1和index2,并且在弹性搜索中都有两个名称相同的类型type1和type2。(请假设我们有有效的业务原因) 我想搜索index1-type1和index2-type2 这是我的问题Json 过滤器'_指数';与'相同_类型';在搜索中跨多个索引查询弹性搜索,json,
elasticsearch,Json,
elasticsearch,我有两个索引index1和index2,并且在弹性搜索中都有两个名称相同的类型type1和type2。(请假设我们有有效的业务原因) 我想搜索index1-type1和index2-type2 这是我的问题 POST _search { "query": { "indices": { "indices": ["index1","index2"], "query": { "filtered":{ "query":{
POST _search
{
"query": {
"indices": {
"indices": ["index1","index2"],
"query": {
"filtered":{
"query":{
"multi_match": {
"query": "test",
"type": "cross_fields",
"fields": ["_all"]
}
},
"filter":{
"or":{
"filters":[
{
"terms":{
"_index":["index1"], // how can i make this work?
"_type": ["type1"]
}
},
{
"terms":{
"_index":["index2"], // how can i make this work?
"_type": ["type2"]
}
}
]
}
}
}
},
"no_match_query":"none"
}
}
}
您可以在筛选器中使用,对类型和索引进行筛选
查询将在以下行中显示:
POST index1,index2/_search
{
"query": {
"filtered": {
"query": {
"multi_match": {
"query": "test",
"type": "cross_fields",
"fields": [
"_all"
]
}
},
"filter": {
"bool": {
"should": [
{
"indices": {
"index": "index1",
"filter": {
"type": {
"value": "type1"
}
},
"no_match_filter": "none"
}
},
{
"indices": {
"index": "index2",
"filter": {
"type": {
"value": "type2"
}
},
"no_match_filter": "none"
}
}
]
}
}
}
}
}
在url示例中传递索引名:index1,index2/\u search是一种很好的做法,否则可能会跨集群中的所有索引执行查询。您可以在筛选器中使用,以筛选类型和索引
查询将在以下行中显示:
POST index1,index2/_search
{
"query": {
"filtered": {
"query": {
"multi_match": {
"query": "test",
"type": "cross_fields",
"fields": [
"_all"
]
}
},
"filter": {
"bool": {
"should": [
{
"indices": {
"index": "index1",
"filter": {
"type": {
"value": "type1"
}
},
"no_match_filter": "none"
}
},
{
"indices": {
"index": "index2",
"filter": {
"type": {
"value": "type2"
}
},
"no_match_filter": "none"
}
}
]
}
}
}
}
}
在url示例中传递索引名:index1,index2/\u search是一种很好的做法,否则可能会对集群中的所有索引执行查询。您能否解释一下您面临的问题。你们的查询对我来说很好,我有相同的场景,多个索引具有相同的类型。嗨,Roopendra,当我执行上面的查询时,它返回index1->type2和index2->type1的结果,我不想要这些结果。我只需要index1->type1和index2->type2。我相信这是因为它没有过滤“_index”字段中的术语。希望这是有意义的。很多人会向你解释你面临的问题。你们的查询对我来说很好,我有相同的场景,多个索引具有相同的类型。嗨,Roopendra,当我执行上面的查询时,它返回index1->type2和index2->type1的结果,我不想要这些结果。我只需要index1->type1和index2->type2。我相信这是因为它没有过滤“_index”字段中的术语。希望这是有意义的。多谢多谢。只需在索引过滤器内部做一个改进,我会使用术语,这样我就可以有多种类型。“筛选器”:{“术语”:{“类型”:[“类型1”、“类型3”、“类型5”]}非常感谢。只需在索引过滤器内部做一个改进,我会使用术语,这样我就可以有多种类型。“筛选器”:{“术语”:{“类型”:[“类型1”、“类型3”、“类型5”]}