在elasticsearch 7.x中,es.mapping.timestamp的替代方法是什么?

cgfeq70w  于 2021-06-13  发布在  ElasticSearch
关注(0)|答案(1)|浏览(959)

elasticsearch的官方文档显示:
包含文档时间戳的文档字段/属性名称。要指定常量,请使用格式。将不适用于elasticsearch 6.0+索引版本,但将继续支持5.x索引版本及以下版本。
因此,当我试图用它来确保我的索引有单独的时间戳时,我得到了这个错误。
org.elasticsearch.hadoop.eshadoPillegalArgumentException:无法在es 6.x及更高版本中的索引/更新请求上使用时间戳。请删除[es.mapping.timestamp]设置。
我试过的代码是:
df.write.format(“org.elasticsearch.spark.sql”).config(“es.mapping.timestamp”,“timestamp”)mode(“overwrite”).save(“indexname/doc”)
时间戳是sparkDataframe中的一个字段。我也用savetoes试过了,也得到了同样的错误。在elasticsearch 7.x中,有没有任何方法可以通过使用其他字段来实现这一点?

oalqel3c

oalqel3c1#

我对Spark不太熟悉,但是 _timestamp 元字段已弃用,因此必须使用 date 在esMap中定义的字段——根据您的规范,其格式可以是 epoch_second 或者 epoch_millis :

PUT your_index_name
{
  "mappings": {
    "properties": {
      "timestamp": {
        "type": "date",
        "format": "epoch_second"
      }
    }
  }
}

在那之后,我想你不需要 .config("es.mapping.timestamp","timestamp") 不再是因为 timestamp 文档中的值将在es中直接解析为 date 支持各自日期查询的字段。

相关问题