Elasticsearch inner_hits查询结果为ArrayOutOfBoundsException

时间:2015-03-27 08:51:09

标签: elasticsearch lucene

我一直期待在elasticsearch 1.5中引入inner_hits功能,所以今天决定尝试一下。但是,我在尝试使用它时不断收到ArrayIndexOutOfBounds错误。我可以通过以下示例重现我的问题:

我的映射:

curl -XPOST 'http://localhost:9200/_template/test' -d '
{
    "template": "testindex", 
    "mappings": {
        "testtype" : {
            "properties" : {
                "comments" : {
                    "properties": {
                        "subEntries": {
                            "type": "nested",
                            "properties": {
                                "message": {
                                    "type" : "string", 
                                    "index": "not_analyzed"
                                } 
                            }
                        }
                    }
                }
            }
        }
    }
}
'

我的数据:

curl -XPOST 'http://localhost:9200/testindex/testtype' -d '
{
    "comments": {
        "subEntries": [
            {"message": "Nice website"},
            {"message": "Worst ever"}
        ]
    }
}'

我的查询:

curl -XGET 'http://localhost:9200/testindex/testtype/_search' -d '
{
    "query": {
        "nested": {
            "path": "comments.subEntries",
            "query": {
                "match": {"comments.subEntries.message": "Nice website"}
            },
            "inner_hits" : {}
        }
    }
}'

输出:

{"took":12,"timed_out":false,"_shards":{"total":5,"successful":4,"failed":1,"failures":[{"index":"testindex","shard":3,"status":500,"reason":"ArrayIndexOutOfBoundsException[-1]"}]},"hits":{"total":1,"max_score":1.4054651,"hits":[]}}

请注意,如果我从查询中删除inner_hits,一切都按预期工作(返回整个文档):

查询#2:

curl -XGET 'http://localhost:9200/testindex/testtype/_search' -d '
{
    "query": {
        "nested": {
            "path": "comments.subEntries",
            "query": {
                "match": {"comments.subEntries.message": "Nice website"}
            }
        }
    }
}'

输出#2:

{"took":133,"timed_out":false,"_shards":{"total":5,"successful":5,"failed":0},"hits":{"total":1,"max_score":1.4054651,"hits":[{"_index":"testindex","_type":"testtype","_id":"AUxaX1RovKqomcXSCC2z","_score":1.4054651,"_source":
{
    "comments": {
        "subEntries": [
            {"message": "Nice website"},
            {"message": "Worst ever"}
        ]
    }
}}]}}

我不确定有什么问题,因为我认为我已正确遵循此处的文档:inner_hits reference请让我知道问题所在。

1 个答案:

答案 0 :(得分:0)

这在elasticsearch 1.5.0中被验证为bug。将来会修复。

如果嵌套文档位于简单对象中,则会发生错误。解决方法是将简单对象也更改为嵌套文档。在这种情况下,映射需要更改为:

curl -XPOST 'http://localhost:9200/_template/test' -d '
{
    "template": "testindex", 
    "mappings": {
        "testtype" : {
            "properties" : {
                "comments" : {
-->                 "type": "nested",
                    "properties": {
                        "subEntries": {
                            "type": "nested",
                            "properties": {
                                "message": {
                                    "type" : "string", 
                                    "index": "not_analyzed"
                                } 
                            }
                        }
                    }
                }
            }
        }
    }
}'