我一直试图使用多个过滤器来获取文档。
我当前正在使用ES 1.7,是否可以在过滤器上使用两次match_phrase
?
示例:人物文档q=aaron&address=scarborough
-通过姓名和地址搜索人,效果很好。
{
"query": {
"match_phrase": {
"name": "aaron"
}
},
"filter": {
"bool": {
"must": {
"nested": {
"path": "addresses",
"query": {
"match_phrase": {
"address": "scarborough"
}
}
}
}
}
},
[q=aaron&phone=813-689-6889
-通过姓名和电话号码搜索人也可以。
{
"query": {
"match_phrase": {
"name": "aaron"
}
},
"filter": {
"bool": {
"must": {
"query": {
"match_phrase": {
"phone": "813-689-6889"
}
}
}
}
}
但是,当我同时使用过滤器,地址和电话时,出现No filter registered for [match_phrase]
错误
例如:q=aaron&address=scarborough&phone=813-689-6889
{
"query": {
"match_phrase": {
"name": "aaron"
}
},
"filter": {
"bool": {
"must": {
"nested": {
"path": "addresses",
"query": {
"match_phrase": {
"address": "scarborough"
}
}
},
"query": {
"match_phrase": {
"phone": "813-689-6889"
}
}
}
}
}
[同时使用address
和phone
过滤器时的错误:
nested: QueryParsingException[[pl_people] No filter registered for [match_phrase]]; }]","status":400}):
也许您可以使用term-filter,而不是match_phrase作为过滤器。
请参见here。