首页 > 解决方案 > 弹性重新索引日期格式太短

问题描述

尝试重新索引索引,因为日期字段的格式已更改。格式从

 ...
 "start_date": {
      "type":   "date",
      "format": "yyyy-MM-dd HH:mm",
       "fields": {
        "keyword": { 
          "type": "keyword"
        }
      }
    }
  ...

 ...
 "start_date": {
      "type":   "date",
      "format": "yyyy-MM-dd HH:mm:ss",
       "fields": {
        "keyword": { 
          "type": "keyword"
        }
      }
    }
 ...

我尝试将我的索引重新索引为 tmp 索引,但它会引发以下错误:

"cause": {
    "type": "mapper_parsing_exception",
    "reason": "failed to parse [start_date]",
    "caused_by": {
      "type": "illegal_argument_exception",
      "reason": "Invalid format: \"2019-01-30 13:03\" is too short"
    }
  },

所以,现在我有一个大问题。如何更改我的日期字段的格式?还有另一种不重新索引的选择吗?

标签: elasticsearchformatreindex

解决方案


由于格式更改,您需要做的是附加:00到您的日期字段以匹配新格式:

POST _reindex
{
  "source": {
    "index": "oldindex"
  },
  "dest": {
    "index": "newindex"
  },
  "script": {
    "source": "ctx._source.start_date = ctx._source.start_date + ':00';"
  }
}

推荐阅读