我遇到问题,对象已被编入索引,但在使用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",...}
这里不应该是父母还是什么?
答案 0 :(得分:1)
正如documentation所述:
"默认情况下,_id
未编入索引且未存储(因此,未创建)。"
答案 1 :(得分:0)
问题在于FOSElasticaBundle。 https://github.com/FriendsOfSymfony/FOSElasticaBundle/blob/master/Resources/doc/types.md#parent-fields声明_parent应该与"映射"分开,但Transformer没有接收_parent定义。另请参阅https://github.com/FriendsOfSymfony/FOSElasticaBundle/pull/665。
我想最快的方法就是在映射部分复制_parent(因为我已经编写了自己的Transformer,所以不能100%确定)。此外,ModelToElasticaAutoTransformer在设置子文档父项时会做一些奇怪的事情 - 获取子项 parent_id 字段,期望它是父对象,然后使用子项&#39获取其ID ; s 标识符设置。我认为它的马车:)
if ($key == '_parent') {
$property = (null !== $mapping['property'])?$mapping['property']:$mapping['type'];
$value = $this->propertyAccessor->getValue($object, $property);
$document->setParent($this->propertyAccessor->getValue($value, $mapping['identifier']));
continue;
}