美文网首页
es 时间 mapping建议

es 时间 mapping建议

作者: 良人与我 | 来源:发表于2019-08-12 15:11 被阅读0次

mapping

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

java 代码注解

    @Field(type = FieldType.Date,
            format = DateFormat.custom,
            pattern = "yyyy-MM-dd HH:mm:ss")
    @JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "yyyy-MM-dd'T'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-12T06:51:40",
          "logTime": "2019-08-12T06:51:40Z"
        }
      }
    ]
  }
}

最终通过kibana discover 查看结果,已经是本地时间了


image.png

建议存储的时候还是使用utc 时间,免得导致通过kibana 查询的结果对不上。

相关文章

网友评论

      本文标题:es 时间 mapping建议

      本文链接:https://www.haomeiwen.com/subject/ckjujctx.html