首页 > 解决方案 > Logstash 时间戳在 Elasticsearch 中显示为文本

问题描述

我正在使用 Elasticsearch 7.3.1 和 Logstash 7.3.1。我正在尝试使用日期过滤器将我的一个字段作为 Elasticsearch 时间戳。数据正在正确插入,但类型@timestamp即将到来text。我该如何解决?

我的输入时间戳就像1567408605794750813. 我的代码是:

input {
  elasticsearch {
    hosts => "x.x.x.x"
    index => "raw"
    docinfo => true
  }
}
filter {
  mutate {
    convert => {
      "timestamp" => "integer"
    }
  }
  date {
    match => ["timestamp", "UNIX_MS", "ISO8601"]
    target => "@timestamp"
  }
}
output {
  elasticsearch {
    index => "logs-%{app_name}"
    document_id => "%{[@metadata][_id]}"
  }
}

运行映射 API 后,我得到

"@timestamp" : {
  "type" : "text",
  "fields" : {
    "keyword" : {
      "type" : "keyword",
      "ignore_above" : 256
    }
  }
}

标签: elasticsearchlogstash

解决方案


试试下面的代码,

date {
    match => [ "[timestamp]", "UNIX" ]
    target => "[@timestamp]"
}

推荐阅读