我有一个问题,对象已被索引,但使用 has_child 搜索时,没有返回任何内容。
映射:
家长:
$ curl -XGET 'http://localhost:9200/items/article/_mapping?pretty'
"items" : {
"mappings" : {
"article" : {
"_meta" : {
"model" : "..."
},
"_source" : {
"enabled" : false,
"includes" : [ ],
"excludes" : [ ]
},
"properties" : {
"content" : {
"type" : "string",
"store" : true,
"analyzer" : "app_standard",
"fields" : {
"transliterated" : {
"type" : "string",
"analyzer" : "transliteration"
},
"stemmed" : {
"type" : "string",
"analyzer" : "app_text_analyzer"
}
}
}
,...
}
}
}
}
孩子:
$ curl -XGET 'http://localhost:9200/items/comment/_mapping?pretty'
"items" : {
"mappings" : {
"comment" : {
"_meta" : {
"model" : "..."
},
"_parent" : {
"type" : "article"
},
"_routing" : {
"required" : true,
"path" : "article_id"
},
"_source" : {
"enabled" : false,
"includes" : [ ],
"excludes" : [ ]
},
"properties" : {
"article_id" : {
"type" : "long",
"store" : true
}
,...
}
}
}
}
父文档和子文档都存在:
家长:
$ curl -XGET 'http://localhost:9200/items/article/110700879894'
结果:
{
"_index": "items",
"_type": "article",
"_id": "110700879894",
"_version": 1,
"found": true
}
没有路由的孩子失败:
$ curl -XGET 'http://localhost:9200/items/comment/110700879894.110700879894'
结果:
{
"error": "RoutingMissingException[routing is required for [items]/[comment]/[110700879894.110700879894]]",
"status": 400
}
带路由的孩子:
$ curl -XGET 'http://localhost:9200/items/comment/110700879894.110700879894?parent=110700879894'
结果:
{
"_index": "items",
"_type": "comment",
"_id": "110700879894.110700879894",
"_version": 1,
"found": true
}
但是 has_child 什么也没找到:
$ curl -XGET 'http://localhost:9200/items/article/_search' -d '{
"query": {
"has_child": {
"type": "comment",
"query": {
"term": {
"article_id": "110700879894"
}
}
}
}
}'
结果:
{
"took": 3,
"timed_out": false,
"_shards": {
"total": 5,
"successful": 5,
"failed": 0
},
"hits": {
"total": 0,
"max_score": null,
"hits": []
}
}
has_parent 也是:
$ curl -XGET 'http://localhost:9200/items/comment/_search' -d '{
"query": {
"has_parent": {
"type": "article",
"query": {
"match_all": {}
}
}
}
}'
结果:
{
"took": 232,
"timed_out": false,
"_shards": {
"total": 5,
"successful": 5,
"failed": 0
},
"hits": {
"total": 0,
"max_score": null,
"hits": []
}
}
我的猜测是索引有问题,没有设置父子关系。但另一方面,发现孩子具有正确的路由。
或者我只是做错了查询。
如何查看父母的子文件是什么?
编辑
索引请求:
PUT http://localhost:9200/_bulk
{"index":{"_index":"items","_type":"comment","_id":"110700879894.110700879894"}}
{"article_id":"110700879894",...}
这里不应该是父母还是什么?