Elasticsearch无法识别yyyyMMddHHmmssS日期

时间:2019-08-02 12:20:27

标签: elasticsearch date-format

我想将日期格式如下所示的文档编入Elasticsearch中:201012301152521 我相信我只需要将弹性索引模式指定为yyyyMMddHHmmssS即可,但是以某种方式它无法识别它。在相同的索引编制过程中,我还要为其他日期建立索引。

我已经坐了几个小时了,但是什么都没用。我也已经在格式上变得非常有创意,无济于事。

注意:我不太在乎最后一个字符S,也不太在乎秒...但是我也没有找到一种忽略其格式的方法。

编辑:

同事很高兴为此创建了一个测试用例:

PUT testdate
{  "mappings": {
     "dynamic": false,
     "properties": {
       "col1": { "type": "date", 
                 "format": "yyyyMMddHHmmss"
       }
    }
  }
}

POST testdate/_doc/1
{
  "col1": "20170802123415"
}
# => SUCCESS


PUT testdate
{  "mappings": {
     "dynamic": false,
     "properties": {
       "col1": { "type": "date", 
                 "format": "yyyyMMddHHmmssS"
       }
    }
  }
}

POST testdate/_doc/1
{
  "col1": "201708021234150"
}
# => ERROR

我们正在使用Elasticsearch版本7.1.1

Edit2: 我们得到的错误是:

{
  "error": {
    "root_cause": [
      {
        "type": "mapper_parsing_exception",
        "reason": "failed to parse field [col1] of type [date] in document with id '1'"
      }
    ],
    "type": "mapper_parsing_exception",
    "reason": "failed to parse field [col1] of type [date] in document with id '1'",
    "caused_by": {
      "type": "illegal_argument_exception",
      "reason": "failed to parse date field [201708021234150] with format [yyyyMMddHHmmssS]",
      "caused_by": {
        "type": "date_time_parse_exception",
        "reason": "Text '201708021234150' could not be parsed at index 0"
      }
    }
  },
  "status": 400
}

0 个答案:

没有答案