elasticsearch - 在Elasticsearch中将 “keyword”更新为索引的 “text”字段类型以进行不精确的单词匹配

标签 elasticsearch lucene

{
        "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%"
                    }
                }
            }
        }
    }
}

最佳答案

下面的映射(问题中共享的内容)将“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"
       }
     }
   }
}

关于elasticsearch - 在Elasticsearch中将 “keyword”更新为索引的 “text”字段类型以进行不精确的单词匹配,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63499700/

相关文章:

php - 在Elasticsearch中查找类似主题(重复提名)

elasticsearch - 从logstash/elasticsearch中删除某种类型的记录

javascript - 使用php从json文件中获取特定数据

Elasticsearch 在加密 channel 上接收到明文流量,关闭连接 Netty4TcpChannel

indexing - 使用 LUKE 进行 Lucene 数字范围搜索

lucene - 获取solr中字段的最大值

mysql - 如何在elasticsearch中编写分组查询?

symfony - 如何创建从 Elastic 结果到 Doctrine 实体的自定义转换器

exception - 使用 Lucene : Why do I get a Too Many Clauses error if I do a prefix search?

java - 为 Google App Engine Java 实现全文搜索的最佳方法是什么