用了Elasticsearch,一口气上5T

本计划用grok从日志中提取数字型字段,但发现插入es后变成文本型,如何解决?

Logstash | 作者 Klein | 发布于2019年11月22日 | 阅读数:3219

原计划从网络设备的日志中提取某些字段,转换成数字型,以方便以后进行计算统计。但发现,虽然在grok中定义了按INT或NUMBER提取字段,但通过kibana看时,一开始是?,等到在index pattern中refresh field list以后,就都变成了字符串类型,而且还不能更改了。如何解决这个问题呢。
 
logstash, elastic search和kibana的版本都是7.3.0. 下面是最简单的配置信息。
  if "test" in [tags] {
    grok {
      match => { "message" => "%{INT:int} %{NUMBER:number} %{WORD:word}" }
    }
  }
 
 
日志为:
10 10 test
 
最后从kibana上查到这个日志为:
 

grokissue.jpg

 
如何解决这个问题呢?
 
 
 
 
 
已邀请:

mobikarl

赞同来自: Klein

https://www.elastic.co/guide/e ... .html
 
另外已建立的索引需要删掉,否则mapping已确定改了也没用

haoyanfeiyun

赞同来自:

提前建好索引,或者建索引模板,设置字段对应的type就可以了

mobikarl

赞同来自:

你定义的有问题,应该写成match => { "message" => "%{INT:int:int} %{NUMBER:number:int} %{WORD:word}" }
 
具体解释看这个:Optionally you can add a data type conversion to your grok pattern. By default all semantics are saved as strings. If you wish to convert a semantic’s data type, for example change a string to an integer then suffix it with the target data type. For example %{NUMBER:num:int} which converts the num semantic from a string to an integer. Currently the only supported conversions are int and float.
 
 

Klein

赞同来自:

@mobikarl 非常感谢。但我刚才大致试了一下,好像还是不行。我再试试(我甚至换了变量名称)。另外,你这段话是在哪儿发现的?
 
 match => { "message" => "%{INT:xxx:INT} %{NUMBER:yyy:INT} %{WORD:word}" }

Klein

赞同来自:

@haoyanfeiyun 也非常感谢你的回复。你的方法,我也会试一下。我正在看如何reindex,不过好像会比较费资源。

Klein

赞同来自:

@mobikarl 太棒了,删掉就可以,换变量名似乎没作用。
 
match => { "message" => "%{INT:xx:int} %{NUMBER:yy:int} %{WORD:word}" }

neu_cyd

赞同来自:

好问题

skyRain

赞同来自:

我试了还不错,解决了我当前的问题,谢谢

要回复问题请先登录注册