2016-08-16 98 views
1

我有兩個指標:多指數搜索與嵌套字段

首先,questions,嵌套場answers。其次,articles沒有這個字段。

我試圖通過多指標進行搜索:

{ 
    "index": "questions, articles", 
    "body":{ 
     "query":{ 
      "bool":{ 
       "must":{ 
        "nested":{ 
         "path": "answer", 
         ... 
        } 
       } 
      } 
     } 
    } 
} 

,並得到錯誤"query_parsing_exception: [nested] failed to find nested object under path [answer]"

我怎麼能沒有錯誤搜索,當一個索引嵌套場,但另一個沒有?

回答

1

我認爲你需要使用indices query併爲每個索引使用不同的查詢。類似這樣的:

GET /questions,articles/_search 
{ 
    "query": { 
    "bool": { 
     "must": [ 
     { 
      "bool": { 
      "should": [ 
       { 
       "indices": { 
        "indices": [ 
        "questions" 
        ], 
        "query": { 
        "nested": { 
         "path": "answer", 
         "query": { 
         "term": { 
          "text": "bla" 
         } 
         } 
        } 
        } 
       } 
       }, 
       { 
       "match_all": {} 
       } 
      ] 
      } 
     }, 
     { 
      "term": { 
      "some_common_field": { 
       "value": "whatever" 
      } 
      } 
     } 
     ] 
    } 
    } 
} 
+0

Thanx!這是工作! –