【问题标题】:Elasticsearch Filtered Bool QueryElasticsearch 过滤布尔查询
【发布时间】:2017-09-29 11:27:36
【问题描述】:

我在使用自定义搜索时遇到了一些严重的问题。我想要的只是三个字段中的通配符搜索,结果应该由另一个字段过滤。在 Elastica 中,它会导致以下查询:

{
   "bool":{
      "should":[
         {
            "wildcard":{
               "ean":"*180g*"
            }
         },
         {
            "wildcard":{
               "titel":"*180g*"
            }
         },
         {
            "wildcard":{
               "interpret":"*180g*"
            }
         }
      ],
      "filter":[
         {
            "term":{
               "genre":{
                  "value":"Rock",
                  "boost":1
               }
            }
         }
      ]
   }
}

实际上我找不到错误,但 Elasticsearch 没有给我过滤结果。发生什么了? Elasticsearch 返回所有带有过滤词的项目,如果布尔应该是 True 或 False。当我将过滤器添加为“必须”时,我得到了相同的结果吗?这里有什么问题!?

【问题讨论】:

  • 您应该在 bool 查询中添加 "minimum_should_match": 1
  • 就是这样!非常感谢!

标签: elasticsearch elastica foselasticabundle


【解决方案1】:

您需要在bool 查询中添加"minimum_should_match": 1

{
   "bool":{
      "minimum_should_match": 1,
      "should":[
         {
            "wildcard":{
               "ean":"*180g*"
            }
         },
         {
            "wildcard":{
               "titel":"*180g*"
            }
         },
         {
            "wildcard":{
               "interpret":"*180g*"
            }
         }
      ],
      "filter":[
         {
            "term":{
               "genre":{
                  "value":"Rock",
                  "boost":1
               }
            }
         }
      ]
   }
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-09-18
    • 2018-03-17
    • 1970-01-01
    • 2018-04-28
    • 1970-01-01
    相关资源
    最近更新 更多