{
"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/