【发布时间】:2015-03-02 05:02:48
【问题描述】:
我一直在尝试使用 Logstash 中的 CSV 过滤器将制表符分隔的文件导入 Elasticsearch。获取数据实际上非常容易,但是当我在 Kibana 中查看数据时,我无法正确输入字段类型。日期和整数继续以字符串形式出现,因此我无法按日期绘制或对整数(总和、平均值等)进行任何分析。
我在获取要填充的字段的 .raw 版本时也遇到了麻烦。例如,在设备中我有“HTC One”之类的数据,但是如果我在 Kibana 中制作饼图,它会显示为两个单独的分组“HTC”和“One”。当我尝试绘制 device.raw 图表时,它会作为缺失字段出现。根据我的阅读,Logstash 似乎应该自动创建每个字符串字段的原始版本,但这似乎并没有发生。
我一直在筛选文档、谷歌和堆栈,但没有找到解决方案。任何想法表示赞赏!谢谢。
配置文件:
#logstash.conf
input {
file {
path => "file.txt"
type => "event"
start_position => "beginning"
sincedb_path => "/dev/null"
}
}
filter {
csv {
columns => ["userid","date","distance","device"]
separator => " "
}
}
output {
elasticsearch {
action => "index"
host => "localhost"
port => "9200"
protocol => "http"
index => "userid"
workers => 2
template => template.json
}
#stdout {
# codec => rubydebug
#}
}
这是模板文件:
#template.json:
{
"template": "event",
"settings" : {
"number_of_shards" : 1,
"number_of_replicas" : 0,
"index" : {
"query" : { "default_field" : "userid" }
}
},
"mappings": {
"_default_": {
"_all": { "enabled": false },
"_source": { "compress": true },
"dynamic_templates": [
{
"string_template" : {
"match" : "*",
"mapping": { "type": "string", "index": "not_analyzed" },
"match_mapping_type" : "string"
}
}
],
"properties" : {
"date" : { "type" : "date", "format": "yyyy-MM-dd HH:mm:ss"},
"device" : { "type" : "string", "fields": {"raw": {"type": "string","index": "not_analyzed"}}},
"distance" : { "type" : "integer"}
}
}
}
【问题讨论】:
标签: elasticsearch logstash kibana