1

我有一个单列 Spark 数据框:

<class 'pyspark.sql.dataframe.DataFrame'>
StructType(List(StructField(updateDate,TimestampType,true)))

使用 spark 写入 elasticsearch 时,updateDate 字段不会被视为日期,而是写入 unix 时间戳 (ms)。

def write_to_elastic(table, destination):
    table.write \
      .format("org.elasticsearch.spark.sql") \
      .option("es.mapping.date.rich", "true") \
      .mode("overwrite") \
      .option("es.index.auto.create", "true") \
      .option("es.resource", destination + "/table") \
      .option("es.nodes", ce.es_nodes) \
      .option("es.net.ssl.protocol", "true") \
      .option("es.nodes.wan.only", "true") \
      .option("es.net.http.auth.user", ce.es_user) \
      .option("es.field.read.empty.as.null", "yes") \
      .option("es.net.http.auth.pass", ce.es_password) \
      .save()

这是摄取的项目:

  {
  "test-date": {
    "aliases": {},
    "mappings": {
      "table": {
        "properties": {
          "updateDate": {
            "type": "long"
          }
        }
      }
    },
    "settings": {
      "index": {
        "creation_date": "1517000418516",
        "number_of_shards": "5",
        "number_of_replicas": "1",
        "uuid": "DMYyE1NPTpyE9HuKI29BqA",
        "version": {
          "created": "6010299"
        },
        "provided_name": "test-date"
      }
    }
  }
}

如果我将 Spark 数据帧写入文件,则日期字段写为: 2017-10-27T00:00:00.000Z

什么可能导致这种行为?

4

0 回答 0