映射时Elasticsearch更改日期格式

use*_*667 1 php mysql elasticsearch laravel

我正在使用Laravel和Elasticsearch.但我无法映射我的mysql时间戳,因为ES默认只支持时间戳为ISO 8601"2015-02-02T15:30:20"

我想绘制看起来像"2015-02-15 15:30:22"的时间戳 - 没有"T"的TS

是否可以更改ES以便允许时间戳如"2015-02-15 15:30:22"?

Oll*_*ank 5

在映射中设置自定义日期格式,以便它接受MySQL格式:

curl -XPUT "http://localhost:9200/test/date-format/_mapping" -d'
{
    "date-format" : {
       "properties": {
          "timestamp": {"type": "date","index": "not_analyzed","format" : "yyyy-MM-DD HH:mm:ss"}
        }
    }
}'
Run Code Online (Sandbox Code Playgroud)

然后通过发布消息测试它:

curl -XPOST "http://localhost:9200/test/date-format" -d'
{
      "timestamp": "2014-10-22 20:03:12"
}'
Run Code Online (Sandbox Code Playgroud)

它应该返回:

{"_index":"test","_type":"test-date","_id":"AUuD22Ls9cHgxNzY1tfJ","_version":1,"created":true}
Run Code Online (Sandbox Code Playgroud)