时间戳,Elasticsearch是可以在索引创建后,映射字段type为date时,使用format来自定义时间戳格式的,最常用的:

PUT test
{
  "mappings": {
    "type": {
      "properties": {
        "inserted": {
          "type": "date",
          "format": "yyyy-MM-dd HH:mm:ss.SSSSSS"
        }
      }
    }
  }
}

PUT /test/type/1
{
  "inserted" : "2017-03-15 23:39:03.000000"
}

PUT /test/type/2
{
  "inserted" : "2017-03-15 23:39:03.002000"
}

 

date_hour_minute_second or strict_date_hour_minute_second
A formatter that combines a full date, two digit hour of day, two digit minute of hour, and two digit second of minute: yyyy-MM-dd’T’HH:mm:ss.
按官方文档说明,需要中间加个

'T'

才能正确识别时间戳。
当然,后来我直接用了long,然后用unix时间戳存储了。

参考资料:
https://www.elastic.co/guide/en/elasticsearch/reference/current/mapping-date-format.html
https://discuss.elastic.co/t/mysql-yyyy-mm-dd-hh-mm-ss-datetime-into-elasticsearch/78775/2

Related Posts: Elasticsearch 索引创建映射时间戳字段Date Format介绍 :

avatar