格式错误的日期字段,以填充到 elasticsearch 中的新字段中



我在 elasticsearch 中创建了一个包含多个日期字段的索引,并将该列格式化为 yyyy-mm-dd HH:mm:ss .最终,我发现日期格式不正确,并将错误的数据填充到字段中。该索引有超过60万条记录,我不想留下任何数据。现在我需要创建另一个字段或新索引,其日期字段和格式与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"
            }
          }

你可以像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

重新索引还可以通过指定管道来使用"采集节点"功能

使用 Logstash

使用 LogStash 从 ElasticSearch 中读取。

操作日期格式。

使用 LogStash 写入 ElasticSearch。

最新更新