2
votes

I have the following mapping

@Document(indexName = "some-index")
@Data
public class ElasticDocument {

    @Id
    @Field(type = FieldType.Text)
    private String id;

    @Field(type = FieldType.Date, format = DateFormat.custom)
    @JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "uuuu-MM-dd'T'HH:mm:ss.SSS")
    private LocalDateTime issuedTimestamp;

}

The following repository

@Repository
public interface DocumentRepository extends ElasticsearchRepository<ElasticDocument, String> {

}

But the following query from spring data elastic search 4.0.3.RELEASE throws a conversion error:

Page<ElasticDocument> elasticDocuments = documentRepository.findAll(PageRequest.of(0, 10));

[MappingElasticsearchConverter.java:290] [Type LocalDateTime of property ElasticDocument.issuedTimestamp is a TemporalAccessor class but has neither a @Field annotation defining the date type nor a registered converter for reading! It cannot be mapped from a complex object in Elasticsearch! [No converter found capable of converting from type [java.lang.Long] to type [java.time.LocalDateTime]] [org.springframework.core.convert.ConverterNotFoundException: No converter found capable of converting from type [java.lang.Long] to type [java.time.LocalDateTime]

I'm using elasticsearch 7.9.1 and spring data elasticsearch 4.0.3.RELEASE and from what i understood starting with spring data elasticsearch 4.x we don't need to create a custom conversion as long as i added the Field annotation at mapping

1

1 Answers

3
votes

You need to add the pattern for your custom format in the @Field annotation

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