0

我在 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"
            }
          }
4

2 回答 2

0

您可以像 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 功能

于 2019-02-13T07:19:59.397 回答
0

使用Logstash

使用 LogStash从 ElasticSearch中读取。

操纵日期格式

使用 LogStash写入ElasticSearch。

于 2019-02-13T07:03:39.480 回答