我对新的inner_hits
功能有些麻烦。
在 parent / child 上使用时,它可以工作,但是如果我尝试在孙子上使用它,则似乎不起作用。
这是我的 map
{
"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"
}
}
}
}
}
}
我通过Sense插入数据
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": {
}
}
}
]
}
}
}
我究竟做错了什么..?
最佳答案
这是一个已知的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"
}
}
}
}
}
}
}
}
}
}
}'
关于elasticsearch - Elasticsearch对子孙的内在打击,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29361395/