更新 "keyword" 到 "text" elasticsearch 中不精确词匹配索引的字段类型

Update "keyword" to "text" field type of an index for inexact words matching in elasticsearch

{
        "myindex": {
            "mappings": {
                "properties": {
                    "city": {
                        "type": "text",
                        "fields": {
                            "keyword": {
                                "type": "keyword",
                                "ignore_above": 256
                            }
                        }
                    }
                }
            }
        }
    }

我尝试通过在索引上使用以下 PUT 请求来更新,但仍然得到上面的 _mapping 输出

{
        "_doc" : {
            "properties" : {
                "city" : {"type" : "text"}
            }
        }
    }

因为类型是“关键字”,所以无法查询到不准确的词,因为下面记录的实际值是“孟买”

{
    "query": {
        "bool": {
            "must": {
                "match": {
                    "city": {
                        "query": "Mumbi",
                        "minimum_should_match": "10%"
                    }
                }
            }
        }
    }
}

minimum_should_match

Minimum number of clauses that must match for a document to be returned

它表示从句的百分比而不是字符串的百分比。浏览 this 文档以构建查询以获得预期结果。无效查询 return 无效结果。

下面的映射(问题中共享的内容)将 'city' 存储为文本,将 'city.keyword' 存储为关键字。

{
        "myindex": {
            "mappings": {
                "properties": {
                    "city": {
                        "type": "text",   // ==========> Store city as text
                        "fields": {
                            "keyword": {
                                "type": "keyword",  // =========> store city.keyword as a keyword
                                "ignore_above": 256
                            }
                        }
                    }
                }
            }
        }
    }

你的是模糊搜索的用例而不是minimum_should_match.

用于模糊搜索的 ES 文档: https://www.elastic.co/blog/found-fuzzy-search

尝试以下查询

{
  "query": {
    "match": {
      "city": {
        "query": "mubai",
        "fuzziness": "AUTO"
       }
     }
   }
}