ElasticSearch multi_match query over multiple fields with Fuzziness

时光毁灭记忆、已成空白 提交于 2019-11-30 02:54:11

问题


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 
      } 
   } 

Suggestions?


回答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:

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.

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



来源:https://stackoverflow.com/questions/29632339/elasticsearch-multi-match-query-over-multiple-fields-with-fuzziness

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!