繁体   English   中英

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

[英]What is the alternative for es.mapping.timestamp in ElasticSearch 7.x?

ElasticSearch 的官方文档说:

包含文档时间戳的文档字段/属性名称。 要指定常量,请使用格式。 不适用于 Elasticsearch 6.0+ 索引版本,但将继续支持 5.x 索引版本及以下版本。

因此,当我尝试使用它来确保我的索引分别具有时间戳时,我会收到此错误。

org.elasticsearch.hadoop.EsHadoopIllegalArgumentException:无法在 ES 6.x 及更高版本中的索引/更新请求上使用时间戳。 请删除 [es.mapping.timestamp] 设置。

我试过的代码是:

df.write.format("org.elasticsearch.spark.sql").config("es.mapping.timestamp","timestamp")mode("overwrite").save("indexname/doc")

时间戳是 Spark dataframe 中的一个字段。 我也用 saveToEs 尝试过,得到了同样的错误。 有什么方法可以通过使用任何其他字段在 ElasticSearch 7.x 中做到这一点?

我对 Spark 不太熟悉,但不推荐使用_timestamp元字段,因此您必须使用在 ES 映射中定义的date字段——根据您的规范,其格式可以是epoch_secondepoch_millis

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

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM