Elasticsearch v1.1.1
我从过滤器中得到了意想不到的结果。我把它分解为它最简单的部分,但仍然会得到奇怪的结果。
首先,我创建一个带有映射的新索引:
PUT /test1
{
"mappings": {
"product": {
"properties": {
"subject": {
"type": "nested",
"properties": {
"code": {
"type": "string"
}
}
}
}
}
}
}
然后我创建了两个用于测试的对象:
PUT /test1/product/12345
{
"subject": {
"code": "FA"
}
}
PUT /test1/product/12346
{
"subject": {
"code": "BA"
}
}
然后我创建一个我希望仅在第二条记录上匹配的查询:
GET /test1/product/_search
{
"query": {
"filtered": {
"query": {
"match_all": []
},
"filter": {
"bool": {
"must_not": [
{
"query": {
"nested": {
"path": "subject",
"query": {
"prefix": {
"subject.code": "fa"
}
}
}
}
}
]
}
}
}
}
}
到目前为止,一切都按预期工作。查询返回第二条记录,第一条记录被筛选器排除。
然后我使用相同的查询来创建一个过滤器:
PUT /test1/.percolator/TEST
{
"query": {
"filtered": {
"query": {
"match_all": []
},
"filter": {
"bool": {
"must_not": [
{
"query": {
"nested": {
"path": "subject",
"query": {
"prefix": {
"subject.code": "fa"
}
}
}
}
}
]
}
}
}
}
}
对两个记录进行测试:
GET /test1/product/12345/_percolate
GET /test1/product/12346/_percolate
他们都返回相同的结果:
{
"took": 1,
"_shards": {
"total": 5,
"successful": 5,
"failed": 0
},
"total": 1,
"matches": [
{
"_index": "test1",
"_id": "TEST"
}
]
}
我在没有嵌套对象的情况下对此进行了测试,并且按照我的预期运行。起初我想也许match_all对于过滤器做了一些奇怪的事情,但是当它不是一个嵌套对象时它工作得很好。
所以我的问题是,我错过了一些明显的东西吗?这是预期的行为吗?我刚刚在文档中错过了它,或者这是一个错误?
我理解我可以用不同的方式轻松创建这个查询(并且对一些建议持开放态度)但是我以编程方式构建它们因此bool结构似乎是最好的选择。我也试过使用"不是"使用嵌套"或"过滤过滤相同的结果。
答案 0 :(得分:0)
原来这是一个错误。它在版本1.2.2中得到修复。
更多信息:https://github.com/elasticsearch/elasticsearch/issues/6540