ElasticSearch索引创建
curl -XPOST 'http://localhost:9200/music/' -d '{}'
场映射
curl -XPUT 'http://localhost:9200/music/_mapping/song' -d '
{
"properties": {
"name" : {
"type" : "string"
},
"suggest": {
"type" : "completion"
}
}
}'
LogStash配置文件,musicStash.config
input {
file {
path => "pathToCsv"
start_position => beginning
}
}
filter {
csv {
columns => ["id", "name", "suggest"]
separator => ","
}
}
output {
elasticsearch {
hosts => "localhost"
index => "music"
document_id => "%{id}"
}
}
现在,在执行logstash文件时,在elasticsearch控制台中收到以下异常
failed to put mappings on indices [[music]], type [logs]
java.lang.IllegalArgumentException: Mapper for [suggest] conflicts with existing mapping in other types:
[mapper [suggest] cannot be changed from type [completion] to [string]]
at org.elasticsearch.index.mapper.FieldTypeLookup.checkCompatibility(FieldTypeLookup.java:117)
在logstash控制台接收到的错误,
response=>{"index"=>{"_index"=>"music", "_type"=>"logs", "_id"=>"5", "status"=>400,
"error"=>{"type"=>"illegal_argument_exception",
"reason"=>"Mapper for [suggest] conflicts with existing mapping in other types:\n[mapper [suggest] cannot be changed from type [completion] to [string]]"}}}, :level=>:warn}
那么如何通过Logstash导入csv文件来实现elasticsearch自动完成功能呢?
发布于 2016-02-16 12:55:51
在elasticsearch
输出中缺少以下设置:
document_type => "song"
发生的情况是,logstash正在创建一个名为logs
(默认情况下)的新类型,而且由于从ES2.0开始,禁止在同一个索引中有两个名称相同但类型不同的字段(string
与completion
),因此它正在出错。
只需像这样修改您的输出就可以了:
output {
elasticsearch {
hosts => "localhost"
index => "music"
document_type => "song"
document_id => "%{id}"
}
}
发布于 2016-10-07 14:13:56
我是装载机的作者
如果您只想将CSV数据加载到elasticsearch中,可以使用elasticsearch_loader
安装后,您将能够通过发出以下命令将csv/json/parquet文件加载到elasticsearch中:
elasticsearch_loader \
--index-settings-file mappings.json \
--index completion \
--type song \
--id-field id \
csv \
input1.csv input2.csv
https://stackoverflow.com/questions/35433121
复制相似问题