弹性搜索:把一个应该放在一个过滤器中 [英] elasticsearch : make a should into a filter
本文介绍了弹性搜索:把一个应该放在一个过滤器中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想用一个过滤器进行搜索,排除不符合条件或不符合条件的结果:
I would want to do search with a filter that exclude result that not match a condition OR anothor condition:
我试图在过滤器中做一个应用,但是失败:
I tried to do a should into a filter but it fails:
POST /my_index/_search
{
"query": {
"bool": {
"filter": [
{
"should": [
{
"match": {
"type1_title": "searched match"
}
},
{
"match": {
"type2_title": "searched match"
}
}
]
}
]
}
}
}
它引发了这个错误:
"error": {
"root_cause": [
{
"type": "parsing_exception",
"reason": "[should] query malformed, no start_object after query name",
"line": 9,
"col": 21
}
],
"type": "parsing_exception",
"reason": "[should] query malformed, no start_object after query name",
"line": 9,
"col": 21
},
"status": 400
}
你知道我们可以做一个还是一个过滤器?
Do you know if we can do an or in a filter?
推荐答案
p>为什么不简单地 bool / should
,不需要 filter
这里
Why not simply bool/should
, there's no need for filter
here
POST /my_index/_search
{
"query": {
"bool": {
"minimum_should_match": 1,
"should": [
{
"match": {
"type1_title": "searched match"
}
},
{
"match": {
"type2_title": "searched match"
}
}
]
}
}
}
如果你真的想保持
POST /my_index/_search
{
"query": {
"bool": {
"filter": [
{
"bool": {
"should": [
{
"match": {
"type1_title": "searched match"
}
},
{
"match": {
"type2_title": "searched match"
}
}
]
}
}
]
}
}
}
这篇关于弹性搜索:把一个应该放在一个过滤器中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文