【发布时间】:2014-09-04 10:28:50
【问题描述】:
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 可能对 percolator 做了一些奇怪的事情,但当它不是嵌套对象时,它工作得很好。
所以我的问题是,我是否遗漏了一些明显的东西?这是预期的行为,我只是在文档中错过了它,还是这是一个错误?
我知道我可以轻松地以不同的方式创建此查询(并且愿意接受一些建议)但是我正在以编程方式构建它们,因此 bool 结构似乎是最佳选择。我还尝试使用带有嵌套“或”过滤器的“非”过滤器,结果相同。
【问题讨论】:
标签: elasticsearch