Elasticsearch配置ik_max_word默认analyzer

安装插件的相信你已经搞掂了
https://github.com/medcl/elasticsearch-analysis-ik

我们国人,使用的字段,基本都是中文了,不需要什么理由。但是如果要我在每个mappings里一个个写属性的分词器,我就很不爽了。
既然 elasticsearch 默认使用的是 standard ,我就想把默认设置成 ik_max_word

尝试网上所说的方法

网上的多数滞后的资料是这么说的,在 elasticsearch.yml 写上这句

index.analysis.analyzer.default.type: ik_max_word

或详细的写法,从名字可以看出来,default 是索引和搜索时用的默认的 analyzer,default_index 是索引时用的默认的 analyzer , default_search 是查询时用的默认analyzer。

index:
  analysis:
    analyzer:
        default:
            type: ik_max_word
        default_index:
            type: ik_max_word
        default_search:
            type: ik_max_word

那就先尝试一下吧。不加 -d 用前台运行,可以看到报错信息如下:

*************************************************************************************
Found index level settings on node level configuration.

Since elasticsearch 5.x index level settings can NOT be set on the nodes 
configuration like the elasticsearch.yaml, in system properties or command line 
arguments.In order to upgrade all indices the settings must be updated via the 
/${index}/_settings API. Unless all settings are dynamic all indices must be closed 
in order to apply the upgradeIndices created in the future should use index templates 
to set default values. 

Please ensure all required values are updated on all indices by executing: 

curl -XPUT 'http://localhost:9200/_all/_settings?preserve_existing=true' -d '{
  "index.analysis.analyzer.default.type" : "ik_max_word"
}'
*************************************************************************************

说得很清晰,5.x 版本后,不能写在配置文件了,使用restApi来配置吧。

正确配置方式

这里我只是针对 cherish_blog 这个index

PUT /cherish_blog
{
    "settings" : {
        "index" : {
            "analysis.analyzer.default.type": "ik_max_word"
        }
    }
}

根据这里的说明,尝试下吧

https://github.com/medcl/elasticsearch-analysis-ik

评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值