linux下elasticsearch环境配置(包含IK)

来源:互联网 发布:ubuntu删除maraidb 编辑:程序博客网 时间:2024/06/05 22:46

1、下载elasticsearch2.3.5版本
https://download.elastic.co/elasticsearch/release/org/elasticsearch/distribution/tar/elasticsearch/2.3.5/elasticsearch-2.3.5.tar.gz

2、通过git clone https://github.com/medcl/elasticsearch-analysis-ik,下载分词器源码,然后进入下载目录,执行命令:mvn clean package,打包生成elasticsearch-analysis-ik/target/releases/elasticsearch-analysis-ik-1.9.5.zip。拷贝和解压release下的文件: #{project_path}/elasticsearch-analysis-ik/target/releases/elasticsearch-analysis-ik-*.zip 到你的 elasticsearch 插件目录, 如: plugins/ik 重启elasticsearch

3、分词器配置

打开ES_HOME/config/elasticsearch.yml文件,在文件最后加入如下内容:
 # IK分词index.analysis.analyzer.default.type: ik# fielddata缓存indices.fielddata.cache.size: "4G"indices.cache.filter.size: "1G"# 稳定性:增强集群稳定性#discovery.zen.ping.timeout: 30s# 安全性:防止删除所有索引action.disable_delete_all_indices: truescript.groovy.sandbox.enabled: false#action.auto_create_index: false# 慢查询日志index.search.slowlog.threshold.query.warn: 10sindex.search.slowlog.threshold.query.info: 5sindex.search.slowlog.threshold.query.debug: 2s#index.search.slowlog.threshold.query.trace: 500msindex.search.slowlog.threshold.fetch.warn: 1sindex.search.slowlog.threshold.fetch.info: 800msindex.search.slowlog.threshold.fetch.debug: 500ms#index.search.slowlog.threshold.fetch.trace: 200ms

ok!插件安装已经完成,请重新启动ES,接下来测试ik分词效果啦!

默认Elasticsearch查询是1万条数据,可以通过 elasticsearch.yml 修改。
index.max_result_window : 100000000

三、ik分词测试

1、创建一个索引,名为index。

curl -XPUT http://localhost:9200/index

2、为索引index创建mapping。

curl -XPOST http://localhost:9200/index/fulltext/_mapping -d'{    "fulltext": {             "_all": {            "analyzer": "ik"        },        "properties": {            "content": {                "type" : "string",                "boost" : 8.0,                "term_vector" : "with_positions_offsets",                "analyzer" : "ik",                "include_in_all" : true            }        }    }}'

3、测试

curl 'http://localhost:9200/index/_analyze?analyzer=ik&pretty=true' -d '{"text":"世界如此之大"}'

显示结果如下:

  "tokens" : [ {    "token" : "text",    "start_offset" : 4,    "end_offset" : 8,    "type" : "ENGLISH",    "position" : 1  }, {    "token" : "世界",    "start_offset" : 11,    "end_offset" : 13,    "type" : "CN_WORD",    "position" : 2  }, {    "token" : "如此",    "start_offset" : 13,    "end_offset" : 15,    "type" : "CN_WORD",    "position" : 3  }, {    "token" : "之大",    "start_offset" : 15,    "end_offset" : 17,    "type" : "CN_WORD",    "position" : 4  } ]}

后台运行elasticsearch

./bin/elasticsearch -d

参考文献:https://zhuowenji1.gitbooks.io/elasticsearch/content/yunxing_elasticsearch_md.html

0 0
原创粉丝点击