es 時間 mapping建議

mapping

    "createTime": {
                    "type": "date",
                    "format": "yyyy-MM-dd'T'HH:mm:ss'Z'"
                }

java 代碼註解

    @Field(type = FieldType.Date,
            format = DateFormat.custom,
            pattern = "yyyy-MM-dd HH:mm:ss")
    @JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "yyyy-MM-dd HH:mm:ss")
    private Date creatDate;
}

通過 kibana dev 查詢 看到還是 utc 時間

{
  "took": 0,
  "timed_out": false,
  "_shards": {
    "total": 2,
    "successful": 2,
    "skipped": 0,
    "failed": 0
  },
  "hits": {
    "total": 1,
    "max_score": 1,
    "hits": [
      {
        "_index": "student",
        "_type": "student",
        "_id": "dxmYhGwBAdpwDaWWx8kH",
        "_score": 1,
        "_source": {
          "id": null,
          "name": "name:",
          "age": 12,
          "desc": "hello world",
          "area": "xian",
          "creatDate": "2019-08-12 06:51:40",
          "logTime": "2019-08-12T06:51:40Z"
        }
      }
    ]
  }
}

最終通過kibana discover 查看結果,已經是本地時間了


建議存儲的時候還是使用utc 時間,免得導致通過kibana 查詢的結果對不上。

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章