search - 如何使用minimum_should_match 进行多字段搜索?

标签 search elasticsearch indexing

我正在尝试过滤 elasticsearch 的结果,它必须返回与搜索文本 80% 兼容的结果。

当我只对一个键执行此操作时,minimum_should_match 工作完美:

{
       "size":30,
       "from":930,
       "query":{
          "filtered":{
             "query":{
                "query_string":{
                   "default_field":"campo1",
                   "query":"portugues",                  
                   "minimum_should_match":"80%"
                }
             }
          }
       }
    }

当我使用多个键进行搜索时,minimum_should_match 无法正常工作,返回具有 70% 兼容性的结果:

{
       "size":30,
       "from":123420,
       "query":{
          "filtered":{
             "query":{
                "query_string":{
                   "default_operator":"or",
                   "query":"portugues",
                   "fields":[
                      "campo1",
                      "campo2^5",
                      "campo3"
                   ],
                   "minimum_should_match":"80%"
                }
             }
          }
       }
    }

据我所知,我需要按键设置minimum_should_match,但我不知道该怎么做。 如果有人可以帮助我这样做,那就太好了。

最佳答案

我需要使用 boolmulti_match,这是正确的方法:

{
   "size":"30",
   "from":0,
   "query":{
      "filtered":{
         "query":{
            "bool":{
               "should":[
                  {
                     "multi_match":{
                        "query":"portugues",
                        "type":"cross_fields",
                        "fields":[
                           "campo1^3",
                           "campo2^5",
                           "campo3^3"
                        ],
                        "minimum_should_match":"80%"
                     }
                  }
               ]
            }
         }
      }
   }
}

关于search - 如何使用minimum_should_match 进行多字段搜索?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22695749/

相关文章:

list - 在 Haskell 的列表中查找元素的索引?

search - Redis To Go 与 Websolr 的分面对比

google-chrome - Chrome 22 开发者工具 - 环球资源搜索无法正常工作 (ctrl-shift-f)

c# - NEST 2.3.1 (Elastic Search) 创建索引出错

python - pip 安装不会向 pipFile 或 pipFile.lock 添加任何内容

nginx - 解析Nginx日志时出现Logstash _grokparsefailure

xml - R:将节点插入特定位置的xml树

ajax - YII2 gridview使用ajax自定义搜索

mysql - "where"或 "like"子句更适合使用索引

r - 一次索引并分配多组行