2015-03-31 71 views
0

我对新的inner_hits功能有些麻烦。 当在父母/孩子上使用它时,它会起作用,但是如果我尝试在孙子上使用它,它似乎不起作用。Elasticsearch在孙子们的内在点击

这是我的映射

{ 
    "test": { 
     "template": "test", 
     "settings": { 
      "index": { 
       "number_of_replicas": 0 
      } 
     }, 
     "mappings": { 
      "parents": { 
       "dynamic": "strict", 
       "_routing": { 
        "required": true 
       }, 
       "properties": { 
        "parent_value": { 
         "type": "string" 
        } 
       } 
      }, 
      "children": { 
       "dynamic": "strict", 
       "_routing": { 
        "required": true 
       }, 
       "_parent": { 
        "type": "parents" 
       }, 
       "properties": { 
        "parent_id": { 
         "type": "string", 
         "index": "not_analyzed" 
        }, 
        "child_value": { 
         "type": "string" 
        } 
       } 
      }, 
      "grandchildren": { 
       "dynamic": "strict", 
       "_routing": { 
        "required": true 
       }, 
       "_parent": { 
        "type": "children" 
       }, 
       "properties": { 
        "children_id": { 
         "type": "string", 
         "index": "not_analyzed" 
        } 
       } 
      } 
     } 
    } 
} 

我插入数据通过正义

PUT test/parents/parent_id?routing=1 
{ 
    "parent_value": "PARENT VALUE" 
} 

PUT test/children/child_id?routing=1&parent=parent_id 
{ 
    "parent_id": "parent_id", 
    "child_value": "CHILD VALUE" 
} 

PUT test/grandchildren/grandchild_id?routing=1&parent=child_id 
{ 
    "children_id": "child_id" 
} 

这完美的作品

GET test/children/_search?routing=1 
{ 
    "post_filter": { 
     "bool": { 
     "must": [ 
      { 
       "has_parent": { 
        "parent_type": "parents", 
        "filter": { 
        "bool": { 
         "must": [ 
          { 
           "ids": { 
            "values": ["parent_id"] 
           } 
          } 
         ] 
        } 
        }, 
        "inner_hits": { 
        } 
       } 
      } 
     ] 
     } 
    } 
} 

耶!

但是,如果我尝试这个,它会发现一个文件,但inner_hits是空的。

GET test/grandchildren/_search?routing=1 
{ 
    "post_filter": { 
     "bool": { 
     "must": [ 
      { 
       "has_parent": { 
        "parent_type": "children", 
        "filter": { 
        "bool": { 
         "must": [ 
          { 
           "ids": { 
            "values": ["child_id"] 
           } 
          } 
         ] 
        } 
        }, 
        "inner_hits": { 
        } 
       } 
      } 
     ] 
     } 
    } 
} 

我在做什么错误..?

回答

0

这是一个众所周知的issue.workaround复制你的查询inner hits分支的所有层面:

curl -XGET "http://localhost:9200/_search" -d' 
{ 
    "query": { 
    "nested": { 
     "path": "cars", 
     "query": { 
     "nested": { 
      "path": "cars.manufacturers", 
      "query": { 
      "match": { 
       "cars.manufacturers.country": "Japan" 
      } 
      } 
     } 
     } 
    } 
    }, 
    "inner_hits": { 
    "cars": { 
     "path": { 
     "cars": { 
      "query": { 
      "nested": { 
       "path": "cars.manufacturers", 
       "query": { 
       "match": { 
        "cars.manufacturers.country": "Japan" 
       } 
       } 
      } 
      }, 
      "inner_hits": { 
      "manufacturers": { 
       "path": { 
       "cars.manufacturers": { 
        "query": { 
        "match": { 
         "cars.manufacturers.country": "Japan" 
        } 
        } 
       } 
       } 
      } 
      } 
     } 
     } 
    } 
    } 
}' 
相关问题