首页 > 解决方案 > Elasticsearch 查询这种特殊类型的错字:“bath mat”与“bathmat”

问题描述

当有人输入错误的单词“bathmat”时,我试图从 Elasticsearch 获取结果——正确的拼写是“bath mat”。换句话说,当有人输入了错误的单词“bathmat”时,我希望 Elasticsearch 返回结果,就好像输入了正确的单词“bath mat”一样。

这是我的查询:

GET localhost:9200/products/_search
{ 
    "size": 10000,
    "query": { 
        "bool": {
            "minimum_should_match": 1,
            "should": [
                {
                    "match": {
                        "title": {
                            "query": "bathmat",
                            "fuzziness": "AUTO"
                        }
                    }
                },
                {
                    "match_phrase": {
                        "main_description": "bathmat"
                    }
                }
            ],
            "must": [
                {
                    "nested": {
                        "path": "taxonomies",
                        "query": {
                            "bool": {
                                "should": [
                                    { "match": { "taxonomies.name": "bathmat" }}
                                ]
                            }
                        }
                    }
                }
            ]
        }
    }
}

有人可以指向相关的 Elasticsearch 文档/博客文章,或者在下面解释我如何创建一个 Elasticsearch 请求来获得我正在寻找的结果吗?

标签: elasticsearch

解决方案


推荐阅读