2016-12-19 11 views
2

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

答えて

2

あなたはこのように試みることができる:

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

感謝を!私は[filter]が2.0のBool Queriesに許可された引数として追加されたことを知らなかった(https://www.elastic.co/guide/en/elasticsearch/reference/2.0/query-dsl-bool-query。 html)が、私の問題を解決します。 – Zeedox

+0

はい、確かに、それはES 2.0で行いました。うれしかったよ! – Val

関連する問題