ElasticSearch Spring-Data Date format always is long

后端 未结 4 700
Happy的楠姐
Happy的楠姐 2021-02-07 06:01

When using spring-data to insert Elasticsearch document with Date type, I can\'t get right date format, the date format always is Long.

here is the java code: Entity.jav

4条回答
  •  执笔经年
    2021-02-07 07:01

    It worked for me with below settings. Note: delete your index before to test this change. Make sure that the patterns are same at all places.

    @Field(type = FieldType.Date, store = true, format = DateFormat.custom, pattern = "yyyy-MM-dd'T'HH:mm:ss.SSS'Z'")
    @JsonFormat (shape = JsonFormat.Shape.STRING, pattern ="yyyy-MM-dd'T'HH:mm:ss.SSS'Z'")
    private Date date;
    

提交回复
热议问题