1

我正在尝试设置 logstash、elasicsearch 和 Kibana 来可视化日志。日志应该通过TCP发送到logstash,过滤,输出到ES-index,然后在kibana中显示。

我发送到 logstash 的消息:

msg_to_tcp="id=1324 type=error name=system_name"

logstash.conf:

input{
   tcp {
      host => localhost
      port => 55555
     }
}
filter {
   kv {} 
   mutate {
      convert => ["id" , "integer"]
   }
}
output {
   elasticsearch {
       host => localhost
       port => 9200
    } 
}

用法:logstash 1.4.2、elasticsearch 1.4.4 和 kibana 4

不幸的是,将 id 转换为整数不起作用。Kibana 告诉我它仍然是一个字符串。

我还尝试在 kibana 中使用“脚本过滤器”,它只会导致错误。

Integer.parseInt(doc["id"].value)

有人可以帮我将“id”转换为整数吗?

4

2 回答 2

3
  • 从elasticsearch中删除现有索引并创建一个具有适当映射的新索引,即,如果您希望id为整数,则在创建索引时将id列数据类型创建为整数。

    PUT indexname
    {
     "mappings": {
         "mappingname": {
            "properties": {
            "id": {
            "type": "integer"
          },
          "name": {
            "type": "string"
          }   
    
            }
         }
      }
    
    }
    
  • 然后为 logstash 创建 grok 过滤器以识别字段值,如下所示

    input{
    tcp {
          host => localhost
          port => 55555
         }
    }
    filter {
       grok {
                match => {
                    "message" => "id=%{NUMBER:id}\s*type=%{WORD:type}\s*name=%{WORD:name}"
                }
    
            }
    }
    output {
       elasticsearch {
           host => localhost
           port => 9200
        } 
    }
    

现在尝试使用上述解决方案,我希望它会起作用!

于 2018-12-26T14:07:06.360 回答
0

在进行此更改之前,您是否删除了任何已经存在的索引?如果没有,您无法更改 ElasticSearch 索引使用的模板,其中包括每个字段的类型。相反,您必须创建一个新索引并将数据填充到其中。如果要使用相同的索引名称,则需要先删除现有索引。

于 2015-03-12T16:23:42.080 回答