0

使用带有 elasticsearch-hadoop 库的 Spark 读取 Elasticsearch 记录时,时间戳无效。我正在使用以下 Spark 代码进行记录读取:

val sc = spark.sqlContext
  val elasticFields = Seq(
    "start_time",
    "action",
    "category",
    "attack_category"
  )

  sc.sql(
    "CREATE TEMPORARY TABLE myIndex " +
      "USING org.elasticsearch.spark.sql " +
      "OPTIONS (resource 'aggattack-2021.01')" )

  val all = sc.sql(
    s"""
      |SELECT ${elasticFields.mkString(",")}
      |FROM myIndex
      |""".stripMargin)
  all.show(2)

这导致以下结果:

+-----------------------+------+---------+---------------+
|start_time             |action|category |attack_category|
+-----------------------+------+---------+---------------+
|1970-01-19 16:04:27.228|drop  |udp-flood|DoS            |
|1970-01-19 16:04:24.027|drop  |others   |DoS            |
+-----------------------+------+---------+---------------+

但我期待当前年份的时间戳,例如2021-01-19 16:04:27.228。在弹性中,start_time字段具有以毫秒为单位的 unixtime 格式 ->start_time": 1611314773.641

4

1 回答 1

0

问题在于 ElasticSearch 中的数据。start_time字段被映射为epoch_seconds并包含具有三个小数位的值纪元秒(例如1611583978.684)。在我们将纪元时间转换为毫秒后一切正常,没有任何小数位

于 2021-01-25T19:34:56.387 回答