提问要多花一点心思哦

用logstash导入ES且自定义mapping时踩的坑

jiakechong1642 发表了文章 • 5 个评论 • 12931 次浏览 • 2017-04-26 16:14 • 来自相关话题

问题发生背景:

1.本来我是使用logstash的默认配置向ES导入日志的。然后很嗨皮,发现一切OK,后来我开始对日志进行聚合统计,发现terms聚合时的key很奇怪,后来查询这奇怪的key,发现这些关键字都是源字符串的一段,而且全部复现场景都是出现"xxxx-xxxxxx"时就会截断,感觉像是分词器搞的鬼。所以想自己定制mapping。下面是原来的logstash配置
output{
elasticsearch{
action => "index"
hosts => ["xxxxxx:9200"]
index => "xxxxx"
document_type => "haha"
}
}



说干就干:

开始四处查阅文档,发现可以定制mapping,很开心。
output{
elasticsearch{
action => "index"
hosts => ["xxx"]
index => "logstashlog"
template => "xx/http-logstash.json"
template_name => "http-log-logstash"
template_overwrite => true
}
stdout{
codec => rubydebug
}

}没有什么一帆风顺:
问题1:
但是我发现我已经上传了自定义的template,但是就是不能生效。
这时知道了,这个要设置order才能覆盖,默认的order是0,必须更大才行,参考
http://elasticsearch.cn/article/21
问题2:
我看到自己上传的template的order已经是1了,怎么还是不生效呢?
原来自己的索引名称不匹配自己的template的名称,所以不能使用,就又用了默认的template。
改成下面后OK,终于生效了。(注意index名称变化)output{
elasticsearch{
action => "index"
hosts => ["xxx"]
index => "http-log-logstash"
document_type => "haha"
template => "xxx/http-logstash.json"
template_name => "http-log-logstash"
template_overwrite => true
}
stdout{
codec => rubydebug
}

}问题3:
发现导入失败,原来自己的时间字符串不能用默认的date的format匹配,
如2017-04-11 00:07:25   不能用 { "type" : "date"} 的默认format匹配,
改成:"format": "yyy-MM-dd HH:mm:ss||yyyy-MM-dd||epoch_millis"}, 
这样就能解析了。
一切OK,谢谢社区,谢谢Google(你是我见过的除了书籍和老师之后最提升生产力的工具)

附上我的模板
{ 
"template" : "qmpsearchlog",
"order":1,
"settings" : { "index.refresh_interval" : "60s" },
"mappings" : {
"_default_" : {
"_all" : { "enabled" : false },
"dynamic_templates" : [{
"message_field" : {
"match" : "message",
"match_mapping_type" : "string",
"mapping" : { "type" : "string", "index" : "not_analyzed" }
}
}, {
"string_fields" : {
"match" : "*",
"match_mapping_type" : "string",
"mapping" : { "type" : "string", "index" : "not_analyzed" }
}
}],
"properties" : {
"@timestamp" : { "type" : "date"},
"@version" : { "type" : "integer", "index" : "not_analyzed" },
"path" : { "type" : "string", "index" : "not_analyzed" },
"host" : { "type" : "string", "index" : "not_analyzed" },
"record_time":{"type":"date","format": "yyy-MM-dd HH:mm:ss||yyyy-MM-dd||epoch_millis"},
"method":{"type":"string","index" : "not_analyzed"},
"unionid":{"type":"string","index" : "not_analyzed"},
"user_name":{"type":"string","index" : "not_analyzed"},
"query":{"type":"string","index" : "not_analyzed"},
"ip":{ "type" : "ip"},
"webbrower":{"type":"string","index" : "not_analyzed"},
"os":{"type":"string","index" : "not_analyzed"},
"device":{"type":"string","index" : "not_analyzed"},
"ptype":{"type":"string","index" : "not_analyzed"},
"serarch_time":{"type":"date","format": "yyy-MM-dd HH:mm:ss||yyyy-MM-dd||epoch_millis"},
"have_ok":{"type":"string","index" : "not_analyzed"},
"legal":{"type":"string","index" : "not_analyzed"}
}
}
}
}



 

logstash将日志数据存放到elasticsearch中,logstash日志显示已经传到elasticsearch中,但elasticsearch收不到,怎么回事?

wyntergreg 回复了问题 • 2 人关注 • 1 个回复 • 4155 次浏览 • 2017-04-25 16:26 • 来自相关话题

头疼的问题,如何把多个字段列拼接成一个date类型?

回复

foxfire881 发起了问题 • 1 人关注 • 0 个回复 • 5094 次浏览 • 2017-04-22 19:03 • 来自相关话题

logstash如何在配置文件中定义一个全局变量,并且传一次数据就递增一次,作为elasticsearch的id

wyntergreg 回复了问题 • 2 人关注 • 1 个回复 • 9589 次浏览 • 2017-04-21 10:08 • 来自相关话题

.txt文件logstash写入es的无法多次导入

medcl 回复了问题 • 2 人关注 • 1 个回复 • 8812 次浏览 • 2017-04-24 15:15 • 来自相关话题

logstash配置文件中output 怎么获得input下kafka的id??

回复

iuiufa 发起了问题 • 1 人关注 • 0 个回复 • 4704 次浏览 • 2017-04-20 12:15 • 来自相关话题

在linux 上使用filebeat 读取日志文件,打开是正常的,用logstash 读取,输出到es乱码问题,怎么解决呢

fjkfjk 回复了问题 • 5 人关注 • 4 个回复 • 11879 次浏览 • 2018-05-18 10:37 • 来自相关话题

logstash_out_mongo从ES同步到mongo数据,大于1G报错!

回复

laoyang360 回复了问题 • 1 人关注 • 1 个回复 • 5223 次浏览 • 2017-04-14 15:21 • 来自相关话题

logstash多时间(date)字段文档导入

lsyoung 发表了文章 • 1 个评论 • 5678 次浏览 • 2017-04-13 20:43 • 来自相关话题

我们都知道如果文档中有表示时间的字段时可以用如下方法将字段转化为date(timestamp)格式导入
date {
match => [ "submission_time", "yyyyMMdd" ]
}
但是如果一条记录中有多个字段需要使用date类型呢?有人遇到了 同样的问题How to parse multiple date fields?其实多次使用date{}语法就行了,例如:
date {
match => [ "submission_time", "UNIX_MS" ]
target => "@timestamp"
}
date {
match => [ "submission_time", "UNIX_MS" ]
target => "submission_time"
}
date {
match => [ "start_time", "UNIX_MS" ]
target => "start_time"
}
date {
match => [ "end_time", "UNIX_MS" ]
target => "end_time"
}
查看官方文档后, 发现一直使用的date是省去了参数target的,而target默认值为@timestamp。

LS的output update or insert,正确姿势是什么?

回复

wyntergreg 发起了问题 • 2 人关注 • 0 个回复 • 4407 次浏览 • 2017-04-10 16:04 • 来自相关话题

用ELK在Kibana中显示mongoDB rs.status 的部分属性

回复

camili 发起了问题 • 1 人关注 • 0 个回复 • 4727 次浏览 • 2017-04-02 14:54 • 来自相关话题

Logstash5怎么读kafka0.8版本的数据?

BrickXu 回复了问题 • 2 人关注 • 1 个回复 • 4629 次浏览 • 2017-04-05 14:50 • 来自相关话题

偶尔丢失记录

回复

chinabinner 发起了问题 • 1 人关注 • 0 个回复 • 4565 次浏览 • 2017-03-30 15:46 • 来自相关话题

logstash5.2.2输出到hdfs时,如何获取本地服务器的时间

sa_linux 回复了问题 • 2 人关注 • 1 个回复 • 3933 次浏览 • 2019-03-27 10:19 • 来自相关话题

logstash 5.2 输出message 里 没有 path 那项

回复

liuweixing 发起了问题 • 1 人关注 • 0 个回复 • 4510 次浏览 • 2017-03-28 13:07 • 来自相关话题