带有模糊性的多个字段上的ElasticSearch multi_match查询 [英] ElasticSearch multi_match query over multiple fields with Fuzziness

查看:895
本文介绍了带有模糊性的多个字段上的ElasticSearch multi_match查询的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何为模糊匹配查询添加模糊性?因此,如果有人要搜索棒球,它仍然会找到棒球文章。当前我的查询如下:

How can I add fuzziness to a multi_match query? So if someone is to search for 'basball' it would still find 'baseball' articles. Currently my query looks like this:

POST /newspaper/articles/_search
{
    "query": {
        "function_score": {
            "query": {
                "multi_match": {
                    "query": "baseball",
                    "type": "phrase",
                    "fields": [
                        "subject^3", 
                        "section^2.5", 
                        "article^2", 
                        "tags^1.5",
                        "notes^1"
                    ]
                }
            }
        }
    }
}

我正在寻找的一个选择是做这样的事情,只是不知道这是否是最好的选择。保持基于得分的排序很重要:

One option I was looking at is to do something like this, just don't know if this is the best option. It's important to keep the sorting based on the scoring:

   "query" : { 
      "query_string" : { 
         "query" : "subject:basball^3 section:basball^2.5 article:basball^2", 
         "fuzzy_prefix_length" : 1 
      } 
   } 

建议?

推荐答案

要将模糊性添加到多查询中,您需要按如下所述添加模糊性属性:

To add fuzziness to a multiquery you need to add the fuzziness property as described here:

{
    "query": {
        "function_score": {
            "query": {
                "multi_match": {
                    "query": "baseball",
                    "type": "phrase",
                    "fields": [
                        "subject^3", 
                        "section^2.5", 
                        "article^2", 
                        "tags^1.5",
                        "notes^1"
                    ],
                    "fuzziness" : "AUTO",
                    "prefix_length" : 2

                }
            }
        }
    }
}

请注意,前缀长度在文档中的解释为:

Please notice that prefix_length explained in the doc as:

不会被模糊化的初始字符数。这有助于减少必须检查的术语数量。默认值为0。

The number of initial characters which will not be "fuzzified". This helps to reduce the number of terms which must be examined. Defaults to 0.

要检查模糊性的可能值,请访问ES文档

To check the possible values of fuzziness please visit the ES docs.

这篇关于带有模糊性的多个字段上的ElasticSearch multi_match查询的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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