Zeedox
Zeedox

Reputation: 80

How to replace Elasticsearch Indices Query

In Elasticsearch 5.0, the Indices Query has been marked as deprecated.

The documentation tells me to "Search on the _index field instead", but it is not obvious to me how to do this. How can I change an example query like this to the new method(s)?

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

Upvotes: 3

Views: 615

Answers (1)

Val
Val

Reputation: 217254

You could try like this:

{
  "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
                    }
                  }
                ]
              }
            }
          ]
        }
      }
    ]
  }
}

Upvotes: 4

Related Questions