多匹配弹性搜索在布尔查询中的模糊性 [英] fuzziness in bool query with multimatch elasticsearch

查看:96
本文介绍了多匹配弹性搜索在布尔查询中的模糊性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Elasticsearch 6.3.0版.我想同时使用模糊度和多重匹配.但这是没有选择的.有人可以为我提供解决方案吗?提前致谢 查询:

i am using elasticsearch version 6.3.0. I want to use fuzziness along with multimatch. but there is no option for that. Can anybody provide me a solution ? Thanks in advance Query :

    {   "query": {
        "bool": {
          "must": [
            {"function_score": {
              "query": {
                "multi_match": {
                  "query": "local",
                  "fields": [
                      "user.name^3", 
                      "main_product"
                    ],
                    "type": "phrase"
                }
              }
            }}
          ], 
          "filter": {
            "geo_distance": {
              "distance": "1000km",

              "user.geolocation": {
                "lat": 25.55,
                "lon": -84.44
              }
            }
          }
        }   
} }

推荐答案

查看现有查询,您正在寻找

Looking at your existing query, you are looking for mix of

  • 基于字段的提升
  • 多场比赛
  • 词组匹配
  • 模糊匹配

如果不是phrase_match,则只需在现有查询中添加"fuzziness": "AUTO""fuzziness":1 or whatever number based on your requirement,您将得到所需的内容.

If it isn't phrase_match you can simply add "fuzziness": "AUTO" or "fuzziness":1 or whatever number based on your requirement in your existing query and you'd get what you are looking for.

POST <your_index_name>/_search
{  
   "query":{  
      "bool":{  
         "must":[  
            {  
               "function_score":{  
                  "query":{  
                     "multi_match":{  
                        "query":"local",
                        "fields":[  
                           "user.name^3",
                           "main_product"
                        ],
                        "fuzziness":"AUTO"
                     }
                  }
               }
            }
         ],
         "filter":{  
            "geo_distance":{  
               "distance":"1000km",
               "user.geolocation":{  
                  "lat":25.55,
                  "lon":-84.44
               }
            }
         }
      }
   }
}

短语模糊:

在这种情况下,您需要使用跨度查询

为了简单起见,我放弃了过滤部分,并提出了以下查询.假设我正在搜索名为pearl jam的短语.

I've discarded the filtering part just for the sake of simplicity and came up with the below query. And let's say that I am searching for phrase called pearl jam.

POST <your_index_name>/_search
{  
   "query":{  
      "function_score":{  
         "query":{  
            "bool":{  
               "should":[  
                  {  
                     "bool":{  
                        "boost":3,
                        "must":[  
                           {  
                              "span_near":{  
                                 "clauses":[  
                                    {  
                                       "span_multi":{  
                                          "match":{  
                                             "fuzzy":{  
                                                "user.name":"pearl"
                                             }
                                          }
                                       }
                                    },
                                    {  
                                       "span_multi":{  
                                          "match":{  
                                             "fuzzy":{  
                                                "user.name":"jam"
                                             }
                                          }
                                       }
                                    }
                                 ],
                                 "slop":0,
                                 "in_order":true
                              }
                           }
                        ]
                     }
                  },
                  {  
                     "bool":{  
                        "boost":1,
                        "must":[  
                           {  
                              "span_near":{  
                                 "clauses":[  
                                    {  
                                       "span_multi":{  
                                          "match":{  
                                             "fuzzy":{  
                                                "main_product":"pearl"
                                             }
                                          }
                                       }
                                    },
                                    {  
                                       "span_multi":{  
                                          "match":{  
                                             "fuzzy":{  
                                                "main_product":"jam"
                                             }
                                          }
                                       }
                                    }
                                 ],
                                 "slop":0,
                                 "in_order":true
                              }
                           }
                        ]
                     }
                  }
               ]
            }
         }
      }
   }
}

所以我正在基于模糊匹配的多字段短语中的字段执行增强 .

So what I am doing is performing boosting based on fields in multi-field phrase with fuzzy match for phrase called pearl jam.

具有slop: 0in_order:true将使我能够对子句中指定的单词进行词组匹配.

Having slop: 0 and in_order:true would enable me to do phrase match for the words I've specified in the clauses.

如果您有任何疑问,请告诉我.

Let me know if you have any queries.

这篇关于多匹配弹性搜索在布尔查询中的模糊性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆