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

时间戳,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时间戳存储了。

 


未经允许不得转载:阿藏博客 » Elasticsearch 索引创建映射时间戳字段Date Format介绍

赞 (0) 打赏