1

我有一个问题,对象已被索引,但使用 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",...}

这里不应该是父母还是什么?

4

2 回答 2

1

文档中所述:

“默认情况下_id不被索引也不存储(因此,不被创建)。”

于 2014-08-03T00:41:11.220 回答
0

Problem was with FOSElasticaBundle. https://github.com/FriendsOfSymfony/FOSElasticaBundle/blob/master/Resources/doc/types.md#parent-fields states that _parent should be separate from "mappings", but Transformer did not receive _parent definition. See also https://github.com/FriendsOfSymfony/FOSElasticaBundle/pull/665.

I guess quickest way would be copying _parent under mappings section as well (can't be 100% sure because I have written my own Transformer). Also ModelToElasticaAutoTransformer does some weird things on setting child documents parent - gets childs parent_id field, expecting it to be parent object, then gets its id, using child's identifier setting. I think its buggy :)

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;
}
于 2014-08-03T17:37:45.450 回答