我是Elasticsearch的新手,刚开始使用ELK堆栈。我正在我的Logstash中收集键值类型日志并将其传递给Elasticsearch中的索引。我在Logstash中使用kv过滤器插件。因此,默认情况下,所有字段都是字符串类型。
当我尝试在Elasticsearch中对数字字段执行avg或sum等聚合时,我收到异常:ClassCastException[org.elasticsearch.index.fielddata.plain.PagedBytesIndexFieldData cannot be cast to org.elasticsearch.index.fielddata.IndexNumericFieldData]
当我检查索引中的映射时,除时间戳之外的所有字段都标记为字符串。
请告诉我如何克服这个问题,因为我的日志事件中有许多数字字段用于聚合。
谢谢,
Keerthana
答案 0 :(得分:8)
您可以为这些字段设置显式映射(例如,请参阅Change default mapping of string to "not analyzed" in Elasticsearch获取一些指导),但使用mutate filter将这些字段转换为Logstash中的整数更容易:
mutate {
convert => ["name-of-field", "integer"]
}
然后Elasticsearch会更好地猜测您的字段的最佳数据类型。
答案 1 :(得分:0)
在最新的Logstash中,语法如下
filter {
mutate {
convert => { "fieldname" => "integer" }
}
}
您可以访问此链接了解更多详情:https://www.elastic.co/guide/en/logstash/current/plugins-filters-mutate.html#plugins-filters-mutate-convert