elasticsearch Elasticsearch inner_在ArrayOutOfBoundsException中命中查询结果,elasticsearch,lucene,elasticsearch,Lucene" /> elasticsearch Elasticsearch inner_在ArrayOutOfBoundsException中命中查询结果,elasticsearch,lucene,elasticsearch,Lucene" />

elasticsearch Elasticsearch inner_在ArrayOutOfBoundsException中命中查询结果

elasticsearch Elasticsearch inner_在ArrayOutOfBoundsException中命中查询结果,elasticsearch,lucene,elasticsearch,Lucene,我一直期待elasticsearch 1.5中引入的内置点击功能,所以今天决定试一试。但是,在尝试使用ArrayIndexOutOfBounds时,我一直会遇到一个ArrayIndexOutOfBounds错误。我可以通过以下示例重现我的问题: 我的映射: curl -XPOST 'http://localhost:9200/_template/test' -d ' { "template": "testindex", "mappings": { "testty

我一直期待elasticsearch 1.5中引入的内置点击功能,所以今天决定试一试。但是,在尝试使用ArrayIndexOutOfBounds时,我一直会遇到一个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":[]}}
请注意,如果我从查询中删除internal_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"}
        ]
    }
}}]}}
我不确定哪里出了问题,因为我认为我正确地遵循了这里的文档:请让我知道问题可能是什么。

这已被验证为elasticsearch 1.5.0中的问题。将在将来固定

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

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"
                                } 
                            }
                        }
                    }
                }
            }
        }
    }
}'

在这个问题中,这个人用嵌套查询解决了这个问题:不是完全相同的问题。在我的例子中,问题是嵌套对象位于另一个对象内。