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

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: true
script.groovy.sandbox.enabled: false
#action.auto_create_index: false

# 慢查询日志
index.search.slowlog.threshold.query.warn: 10s
index.search.slowlog.threshold.query.info: 5s
index.search.slowlog.threshold.query.debug: 2s
#index.search.slowlog.threshold.query.trace: 500ms
index.search.slowlog.threshold.fetch.warn: 1s
index.search.slowlog.threshold.fetch.info: 800ms
index.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
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值