【问题标题】:failed to parse field [review_start_datetime] of type [date] in document with id 'DEMO_54ddab6'无法解析 ID 为“DEMO_54ddab6”的文档中类型为 [date] 的字段 [review_start_datetime]
【发布时间】:2020-12-17 08:58:18
【问题描述】:

索引映射

"review_start_datetime" : {
   "type" : "date"
},
"review_start_time" : {
   "type" : "date"
}

from elasticsearch_dsl import Document, Date

class DocumentX(Document):
    review_start_datetime = Date(format='yyyy-MM-dd HH:mm:ss',
                            default_timezone="UTC")

创建数据

doc = DocumentX.get('DEMO_54ddab6')
doc.review_start_time = datetime.datetime.now()
doc.review_start_datetime = datetime.datetime.now()
doc.save()

在执行保存方法时,它只为 review_start_datetime 字段而不是 review_start_time 给出以下错误。

elasticsearch.exceptions.RequestError: RequestError(400, 'mapper_parsing_exception', "解析字段失败 [review_start_datetime] 类型为 [date] 的文档中具有 id 'DEMO_54ddab6'")

【问题讨论】:

  • 您确定没有为 review_start_datetime 定义“格式”吗?
  • @SahilGupta 是的。映射同上。
  • 您正在将datetime 对象转储到该字段中,而 ES 期待更像字符串的东西。使用obj.strftime('yyyy-MM-dd HH:mm:ss')解析对象

标签: python-3.x elasticsearch elasticsearch-dsl elasticsearch-dsl-py


【解决方案1】:

通过在索引映射中添加 DateTime 格式,它将解决。

"review_start_datetime" : {
    "type" : "date",
    "format" : "yyyy-MM-dd HH:mm:ss"
},

【讨论】:

    【解决方案2】:

    我在各种工具中遇到了同样的错误,例如 Apache NiFi 和 Logstash。我的问题是我想将 MongoDB 文档放在 Elasticsearch 索引中,这些文档已经包含 _id 字段,当我想创建那个 Elasticsearch 数据库时,将创建新字段 _id 可以与较早的不存在。因此,这会导致错误。解决方案可能是在将文档放入 Elastic 之前删除/更改文档中的 _id 字段。

    【讨论】:

    • 这并不能真正回答问题。如果您有其他问题,可以点击 进行提问。要在此问题有新答案时收到通知,您可以follow this question。一旦你有足够的reputation,你也可以add a bounty 来引起对这个问题的更多关注。 - From Review
    猜你喜欢
    • 2019-06-11
    • 2022-11-14
    • 1970-01-01
    • 1970-01-01
    • 2015-10-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-08-28
    相关资源
    最近更新 更多