一、系统环境
组件 | 版本 |
---|---|
ElasticSearch | 6.6.1 |
ES有6个节点,简称es1、es2、es3、es4、es5、es6
二、问题复现
1、ES索引
{
"mappings": {
"_doc": {
"dynamic": "strict",
"properties": {
"title": {
"type": "text",
"analyzer": "ik_max_word"
}
}
}
},
"settings": {
"number_of_replicas": 1,
"number_of_shards": 5
}
}
2、插入数据
{
"title":"测试用例"
}
3、ES报错null_pointer_exception
ES插入数据时,有些时候返回错误,有些时候正常
{
"error": {
"root_cause": [
{
"type": "null_pointer_exception",
"reason": null
}
],
"type": "null_pointer_exception",
"reason": null
},
"status": 500
}
三、问题分析
null_pointer_exception是由于ES部分节点没有ik分词器返回错误,如:只有es1上有ik分词器
因而当数据随机落在节点es1上时,正常插入,其他节点均失败
# 验证机器是否安装ik分词器方法,记得修改成你的IP地址和端口号
curl -XGET "http://192.168.1.1:9200/_analyze" -H 'Content-Type: application/json' -d'
{
"analyzer": "ik_max_word",
"text": "我安装了分词器"
}'
# 成功则返回分词结果,失败则返回Error
四、解决方法
// 移动分片到指定的节点
POST /_cluster/reroute
{
"commands" : [ {
"move" :
{
"index" : "索引名",
"shard" : 4,
"from_node" : "节点名",
"to_node" : "节点名"
}
}
]
}