【问题标题】:Malformed date field to populate into new field in elasticsearch格式错误的日期字段填充到弹性搜索中的新字段
【发布时间】:2019-02-13 06:38:30
【问题描述】:

我在 elasticsearch 中创建了一个包含多个日期字段的索引,并将列格式化为yyyy-mm-dd HH:mm:ss。最终我发现日期格式不正确,并且在字段中填充了错误的数据。该索引有超过 600 000 条记录,我不想留下任何数据。现在我需要创建另一个字段或新索引,其日期字段和格式与YYYY-MM-ddTHH:mm:ss.Z 相同,并且需要将所有记录填充到新索引或新字段中。

我使用了如下的日期处理器管道。但它失败了。在这里纠正我的任何错误。

PUT _ingest/pipeline/date-malform
{
  "description": "convert malformed date to timestamp",
    "processors": [      
      {
        "date": {
          "field": "event_tm",
          "target_field" : "event_tm",
          "formats" : ["YYYY-MM-ddThh:mm:ss.Z"]
          "timezone" : "UTC"
        }
      },      
      {
        "date": {
          "field": "vendor_start_dt",
          "target_field" : "vendor_start_dt",
          "formats" : ["YYYY-MM-ddThh:mm:ss.Z"]
          "timezone" : "UTC"
        }
      },
        {
        "date": {
          "field": "vendor_end_dt",
          "target_field" : "vendor_end_dt",
          "formats" : ["YYYY-MM-ddThh:mm:ss.Z"]
          "timezone" : "UTC"
        }
      }   
    ]
}

我已经创建了管道并使用了如下的重新索引

POST _reindex
{
  "source": {
    "index": "tog_gen_test"
  },
  "dest": {
    "index": "data_mv",
    "pipeline": "some_ingest_pipeline",
    "version_type": "external"
  }
}

运行重新索引时出现以下错误

"failures": [
    {
      "index": "data_mv",
      "type": "_doc",
      "id": "rwN64WgB936y_JOyjc57",
      "cause": {
        "type": "exception",
        "reason": "java.lang.IllegalArgumentException: java.lang.IllegalArgumentException: unable to parse date [2019-02-12 10:29:35]",
        "caused_by": {
          "type": "illegal_argument_exception",
          "reason": "java.lang.IllegalArgumentException: unable to parse date [2019-02-12 10:29:35]",
          "caused_by": {
            "type": "illegal_argument_exception",
            "reason": "unable to parse date [2019-02-12 10:29:35]",
            "caused_by": {
              "type": "illegal_argument_exception",
              "reason": "Illegal pattern component: T"
            }
          }

【问题讨论】:

    标签: date elasticsearch malformed


    【解决方案1】:

    您可以像 Shailesh Pratapwar 建议的那样使用 logstash,但您也可以选择使用 elasticsearch reindex + ingest 来做同样的事情:

    1. 使用适当的日期处理器创建一个摄取管道,以修复日期格式/操作:https://www.elastic.co/guide/en/elasticsearch/reference/master/date-processor.html

    2. 使用日期操作将旧索引中的数据重新索引到新索引。来自:https://www.elastic.co/guide/en/elasticsearch/reference/current/docs-reindex.html

    Reindex 还可以通过指定管道来使用 Ingest Node 功能

    【讨论】:

    • 评论不用于扩展讨论;这个对话是moved to chat。请记住用任何见解更新答案。
    【解决方案2】:

    使用 Logstash

    Read from ElasticSearch 使用 LogStash。

    Manipulate the date format.

    Write to ElasticSearch 使用 LogStash。

    【讨论】:

    • 是的.. 我想使用相同的 Logstash。但我需要知道如何处理格式错误的数据日期字段。例如:字段 event_date 的格式为“yyyy-mm-dd HH:mm:ss”,我需要将此数据填充到具有日期数据类型的新字段中(格式为“yyyy-mm-ddTHH:mm:ss. Z”)。那么请您帮我获取转换级别并填充数据。
    • 显然,如果我可以从旧字段中的数据中排除“HH:mm:ss”,我认为 ES 可以正常理解日期格式并将数据加载到新字段或新索引中使用修改后的字段。例如:2019-02-03 00:00:00 to 2019-02-03 此转换有助于插入旧数据
    • 是的。 ES 接受 ISO 日期格式,其中时间是可选部分。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2018-10-29
    • 2021-01-30
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多