2017-02-16 130 views
0

我希望做的是排除结果是不符合条件或anothor条件过滤搜索:elasticsearch:做应该到过滤

我想一个应该做的到的过滤器,但它失败:

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 
} 

你知道,如果我们可以做一个或一个过滤器?

回答

1

为什么不干脆bool/should,没有必要为filter这里

POST /my_index/_search 
{ 
    "query": { 
    "bool": { 
      "minimum_should_match": 1, 
      "should": [ 
      { 
       "match": { 
       "type1_title": "searched match" 
       } 
      }, 
      { 
       "match": { 
       "type2_title": "searched match" 
       } 
      } 
      ] 
    } 
    } 
} 

如果你真的想保持bool/filter/should结构,那么你需要做的是这样的:

POST /my_index/_search 
{ 
    "query": { 
    "bool": { 
     "filter": [ 
     { 
     "bool": { 
      "should": [ 
      { 
       "match": { 
       "type1_title": "searched match" 
       } 
      }, 
      { 
       "match": { 
       "type2_title": "searched match" 
       } 
      } 
      ] 
     } 
     } 
     ] 
    } 
    } 
} 
+0

谢谢你,你是正确的,但我给了一个简单的例子。我真的想做一个或在一个过滤器。你知道它是否是一个功能吗? –

+1

'应该是一个OR过滤器 – Val

+0

我已经更新了我的答案,如果你真的想保留过滤器 – Val