行动是治愈恐惧的良药,而犹豫、拖延将不断滋养恐惧。

无法索引到ES,类型不匹配?

Elasticsearch | 作者 bearsurvival | 发布于2018年11月13日 | 阅读数:5995

[2018-11-13T14:32:25,699][WARN ][logstash.outputs.elasticsearch] Could not index event to Elasticsearch. {:status=>400, :action=>["index", {:_id=>nil, :_index=>"test-2018.11.13", :_type=>"log", :_routing=>nil}, #<LogStash::Event:0x329a91a9>], :response=>{"index"=>{"_index"=>"test-2018.11.13", "_type"=>"log", "_id"=>"EPLCC2cBh0m3bGrR4-gG", "status"=>400, "error"=>{"type"=>"illegal_argument_exception", "reason"=>"mapper [host] of different type, current_type [text], merged_type [long]"}}}}

这个之前运行了一段时间都没有问题的,我是每天按照日期新建一个索引,索引是按照模版自动创建的,其他索引都没有问题,就一个项目索引的host老是匹配不了,我打印了一下元数据,索引不了的host用的是一个类似[2500,"1.1.1.1","2.2.2.2"] ,正常索引host传到ES的是类似["3-0100","1.1.1.1","2.2.2.2"],有没有哪位大神可以帮忙解答一下,有没有比较低成本的解决办法,我在测试环境试过,感觉用数字和双引号都支持的
已邀请:

JackGe

赞同来自: bearsurvival weizijun

host中的内容为["3-0100","1.1.1.1","2.2.2.2"]是一个数组。当新创建一个索引且没有指定host类型时,es会根据第一次写入数据内容进行推断。如果先写入的是"3-0100",则host的类型为string,如果先写入的是2500,则host的类型为long。
据你说在线下环境试过2500和"2500"都是可以的,需要确认下线下环境索引mapping配置中是否已经定义好host的类型为string了,并且测试的时候待写入的索引是不存在的,会触发创建索引的操作。
 
解决这种的问题的方式是给host字段指定类型。给这类索引创建好template,在template中定义好host的类型为string。例如
{
"order": 10,
"template": "indexName*",
"settings": {
"index": {
"number_of_shards": "1"
}
},
"mappings": {
"type": {
"properties": {
"host": {
"type": "keyword"
}
}
}
}
}

weizijun - elasticsearch fan

赞同来自: bearsurvival

host字段的类型出错了,当前是text类型,然后传递了long类型的值,导致写入失败

要回复问题请先登录注册