【发布时间】:2020-05-11 15:11:50
【问题描述】:
我从 jdbc 源读取数据并将其直接写入弹性搜索索引。 当我在 ES 中查询数据时,我看到我的数据框中的所有时间戳字段都转换为 long
在下面查看我的代码
val appName="ExractToolEngine"
val master = "local[2]"
val conf = new SparkConf().setAppName(appName).setMaster(master)
conf.set("es.write.operation", "index")
conf.set("es.mapping.id", "user_id")
conf.set("index.mapper.dynamic", "true")
conf.set("es.mapping.rich.date", "true")
def main(args: Array[String]): Unit = {
val sc = new SparkContext(conf)
val sqlContext = new SQLContext(sc)
import sqlContext.implicits._
val srcData = sqlContext.read.format("jdbc").
options(Map("driver"->"com.jdbc.Driver",
"url" -> "jdbc...",
"dbtable"-> "tbl",
"partitionColumn"-> "user_id",
"lowerBound"-> "1",
"upperBound"-> "1000000",
"numPartitions"-> "50"
)
).load()
srcData.filter("user_id>=1 and user_id<=1000000").saveToEs("test_users/sm_1")
}
当我运行srcData.printSchema()
我明白了:
|-- dwh_insert_ts: timestamp (nullable = true)
|-- dwh_update_ts: timestamp (nullable = true)
当我查询http://localhost:9200/test_users/_mapping/sm_1上的索引映射时
我明白了
"properties": {
"dwh_insert_ts": {
"type": "long"
},
"dwh_update_ts": {
"type": "long"
},
是否有办法强制弹性搜索保持时间戳并进行转换?
【问题讨论】:
-
但时间戳是长,不是吗?
-
spark timestamp 表示 datetime 对象,我可以应用 datetime 函数而无需将其从 long 转换(类似于 mysql 和 postgres 等其他 RDBMS)
标签: elasticsearch apache-spark spark-dataframe