IK中文分词器和elasticsearch操作
IK中文分词器
-
下载安装包
https://github.com/medcl/elasticsearch-analysis-ik>
-
将elasticsearch-analysis-ik-5.6.16.zip 复制到虚拟机中
scp elasticsearch-analysis-ik-5.6.16.zip python@10.211.55.7:~/
-
安装
sudo /usr/share/elasticsearch/bin/elasticsearch-plugin install file:///home/python/elasticsearch-analysis-ik-5.6.16.zip -> Downloading file:///home/python/elasticsearch-analysis-ik-5.6.16.zip [=================================================] 100% -> Installed analysis-ik
-
重新启动
sudo systemctl restart elasticsearch
-
测试
默认分词
curl -X GET 127.0.0.1:9200/_analyze?pretty -d ' { "analyzer": "standard", "text": "我是&中国人" }'
IK中文分词器
curl -X GET 127.0.0.1:9200/_analyze?pretty -d ' { "analyzer": "ik_max_word", "text": "我是&中国人" }'
操作索引
-
查看索引
curl 127.0.0.1:9200/_cat/indices
-
创建项目文章索引库(创建数据库)
# 语法 PUT /my_index { "settings": { ... any settings ... }, } # 例子 curl -X PUT 127.0.0.1:9200/articles -H 'Content-Type: application/json' -d' { "settings" : { "index": { "number_of_shards" : 3, "number_of_replicas" : 1 } } }'
注: 在Elasticsearch 5.x版本中,设置分片与设置索引的类型字段需要分两次设置完成。
-
删除项目索引
用以下的请求来 删除索引:
DELETE /my_index
你也可以这样删除多个索引:
DELETE /index_one,index_two DELETE /index_*
你甚至可以这样删除 全部 索引:
DELETE /_all DELETE /*
例如
curl -X DELETE 127.0.0.1:9200/articles
创建类型映射(创建表)
类型 在 Elasticsearch 中表示一类相似的文档,类型由 名称 和 映射 ( mapping)组成。
映射, mapping, 就像数据库中的 schema ,描述了文档可能具有的字段或 属性 、 每个字段的数据类型—比如 string
, integer
或 date
。
为了能够将时间字段视为时间,数字字段视为数字,字符串字段视为全文或精确值字符串, Elasticsearch 需要知道每个字段中数据的类型。
简单字段类型: