mapping 是用来手动给 index 的字段 分配类型的,默认es会自动分配类型。
当你手动分配字段类型为 keyword 时,该字段不会分词存储,而是直接存储
PUT usertest { "mappings": { "properties": { "age":{ "type": "integer" }, "name":{ "type": "text" }, "desc":{ "type": "keyword" }, "price":{ "type": "scaled_float", "scaling_factor": 100 } } } }
具体分词器,如下
可以为某个字段指定 分词器
PUT my-index-000001 { "mappings": { "properties": { "title": { "type": "text", "analyzer": "whitespace" } } } }
安装中文分词器 ik
下载对应的版本
https://github.com/medcl/elasticsearch-analysis-ik/releases
解压到plugins目录,命名为ik
若是文件夹没有正常挂载出来,就直接复制进去
docker cp d:\elasticsearch\plugins\ik d7ea6aa5852a:/usr/share/elasticsearch/plugins
若是遇到 es 版本与 ik 版本不一致,直接修改ik版本
vi ./elasticsearch/ik/plugins/plugin-descriptor.properties
开始使用 ik 分词
手动检测这个词会怎样拆
GET _analyze { "text": "中国科技大学", "analyzer": "ik_smart" } GET _analyze { "text": "中国科技大学", "analyzer": "ik_max_word" } // 往往 ik_max_word 使用起来更好一点
手动设定 分词器 使用
# 手动设置 cn 的 name 字段的分词器 PUT cn { "mappings": { "properties": { "name":{ "type": "text", "analyzer": "ik_max_word" } } } } # 使用 POST cn/_bulk {"index":{"_index":"cn"}} {"name":"这是一个杯子"} {"index":{"_index":"cn"}} {"name":"中国博物馆"}
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。