2016-05-19 152 views
0

我有下面的映射,我試圖查詢最內層的嵌套元素,但它給了我錯誤。在多級嵌套對象中的彈性搜索

映射:

{ 
    "search_v1" : { 
    "mappings" : { 
     "statement" : { 
     "properties" : { 
      "details" : { 
      "type" : "text",    
      }, 
      "source" : { 
      "type" : "nested", 
      "properties" : { 
       "affiliation" : { 
       "type" : "nested", 
       "properties" : {     
        "name" : { 
        "type" : "text"     
        } 
       } 
       }, 
       "first_name" : { 
       "type" : "text" 
       }, 
       "last_name" : { 
       "type" : "text" 
       } 
      } 
      } 
     } 
     } 
    } 
    } 
} 

數據:

{ 
    "_index" : "search_v1", 
    "_type" : "statement", 
    "_id" : "AVTHp5y8yr47EGbDlTWu", 
    "_score" : 1.0, 
    "_source" : { 
    "details" : "test test", 
    "source" : {   
     "first_name" : "source2", 
     "last_name" : "source2", 
     "affiliation" : [ {    
     "name" : "affiliation1" 
     }, {    
     "name" : "affiliation2" 
     }, {    
     "name" : "affiliation4" 
     } ] 
    } 
    } 
} 

查詢:

{ 
    "query": { 
    "bool": { 
     "must": [  
     { 
      "nested": { 
      "path": "source", 
      "query": { 
       "bool": { 
       "must": [ { 
        "nested": { 
         "path": "affiliation", 
         "query": { 
         "bool": { 
          "must": [ 
          { "match": { "affiliation.name": "affiliation2" }} 
          ] 
        }}}} 
       ] 
     }}}} 
     ] 
}}} 

錯誤: query_shard_exception:無法創建查詢

,如果我嘗試查詢source.first_name然後它可以工作,但是當我嘗試去1級深,它會給出錯誤。

謝謝。

回答

0

試試這個問題。我不認爲你需要雙重嵌套查詢,但你確實需要匹配查詢中的全限定路徑。

{ 
    "query": { 
     "bool": { 
     "must": [ 
      { 
       "nested": { 
        "path": "source", 
        "query": { 
        "bool": { 
         "must": [ 
          { 
           "match": { 
           "source.affiliation.name": "affiliation2" 
           } 
          } 
         ] 
        } 
        } 
       } 
      } 
     ] 
     } 
    } 
} 
+0

其沒有給予任何結果,單位也是一個嵌套的對象,也可以在源 –

+0

更多然後1點的隸屬關係關於如何使用您的原始查詢,但使用在比賽中完全合格的路徑? '{「match」:{「source.affiliation.name」:「affiliation2」}}' –

+0

yes試過了,但那也行不通 –