首页 > 其他 > 详细

ElasticSearch6设置某个字段不分词

时间:2020-05-11 13:42:07      阅读:657      评论:0      收藏:0      [点我收藏+]

最近在学习ElasticSearch官方文档过程中发现的某个问题,记录一下 希望能帮助到后面的朋友

https://www.elastic.co/guide/cn/elasticsearch/guide/current/_finding_exact_values.html

先说结论:字段类型更改为 ‘keyword‘

elasticSearch官方文档中创建index代码如下

PUT /my_store 
{
    "mappings" : {
        "products" : {
            "properties" : {
                "productID" : {
                    "type" : "string",
                    "index" : "not_analyzed" 
                }
            }
        }
    }

}

由于es官方文档版本基于2.x编写,而本人安装版本为6.6 在执行如上代码过程中出现如下错误

No handler for type [string] declared on field [productID]

技术分享图片

 

 

 这里报错是因为ElasticSearch5.x以上版本没有string类型了,换成了text和keyword作为字符串类型。


 

字符串 - text:用于全文索引,该类型的字段将通过分词器进行分词,最终用于构建索引

字符串 - keyword:不分词,只能搜索该字段的完整的值,只用于 filtering

此时我们将文档中代码更改为如下

PUT /my_store 
{
    "mappings" : {
        "products" : {
            "properties" : {
                "productID" : {
                    "type" : "keyword",
                    "index": true
                }
            }
        }
    }
}

 

技术分享图片

 

 创建成功,此时我们进行查询试试看

GET /my_store/products/_search
{
    "query" : {
        "constant_score" : {
            "filter" : {
                "term" : {
                    "productID" : "XHDK-A-1293-#fJ3"
                }
            }
        }
    }
}

 

技术分享图片

 

ElasticSearch6设置某个字段不分词

原文:https://www.cnblogs.com/feidao158/p/12868558.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!