Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/json/13.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Json 过滤器'_指数';与'相同_类型';在搜索中跨多个索引查询弹性搜索_Json_<img Src="//i.stack.imgur.com/RUiNP.png" Height="16" Width="18" Alt="" Class="sponsor Tag Img">elasticsearch - Fatal编程技术网 elasticsearch,Json,elasticsearch" /> elasticsearch,Json,elasticsearch" />

Json 过滤器'_指数';与'相同_类型';在搜索中跨多个索引查询弹性搜索

Json 过滤器'_指数';与'相同_类型';在搜索中跨多个索引查询弹性搜索,json,elasticsearch,Json,elasticsearch,我有两个索引index1和index2,并且在弹性搜索中都有两个名称相同的类型type1和type2。(请假设我们有有效的业务原因) 我想搜索index1-type1和index2-type2 这是我的问题 POST _search { "query": { "indices": { "indices": ["index1","index2"], "query": { "filtered":{ "query":{

我有两个索引index1index2,并且在弹性搜索中都有两个名称相同的类型type1type2。(请假设我们有有效的业务原因)

我想搜索index1-type1index2-type2

这是我的问题

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”]}