2016-12-19 1 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의 BoolQuery에 허용 된 인수로 추가되었음을 알지 못했다. (https://www.elastic.co/guide/en/elasticsearch/reference/2.0/query-dsl-bool-query. html),하지만 그건 내 문제를 해결합니다. – Zeedox

+0

예, 실제로 ES 2.0에서 그랬습니다. 다행히 도왔다! – Val