ElasticSearch Spring-Data Date format always is long

后端 未结 4 706
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 06:55

    Starting from Elasticsearch 7 you should't use yyyy but uuuu. e.g:

    @Field(type = FieldType.Date, format = DateFormat.custom, pattern = "uuuu-MM-dd'T'HH:mm:ss.SSSZZ")
    private Date lastModifiedDate;
    

    You don't need @JsonProperty because now Spring Data Elasticsearch doesn't use Jackson but instead a MappingElasticsearchConverter. With this annotation, a converter is automatically created for this property and used.

提交回复
热议问题