2016-12-19 2 views
2

In Elasticsearch 5.0, die Indices Query has been marked as deprecated.So ersetzen Sie Elasticsearch-Indizes Abfrage

Die Dokumentation sagt mir zu "Suche auf dem _index Feld statt", aber es ist mir nicht klar, wie man das macht. Wie kann ich eine Beispielabfrage wie diese auf die neue (n) Methode (n) ändern?

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

Antwort

2

Sie mögen diese könnten versuchen:

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

Dank! Ich wusste nicht, dass ['filter' als zulässiges Argument zu Bool Queries in 2.0 hinzugefügt wurde] (https://www.elastic.co/guide/en/elasticsearch/reference/2.0/query-dsl-bool-query). html), aber das löst mein Problem. – Zeedox

+0

Ja, tatsächlich, in ES 2.0. Froh, dass es geholfen hat! – Val