2016-05-19 111 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试过了,但那也行不通 –