Spring data elastic search long to localdatetime 转换错误
Spring data elastic search long to localdatetime conversion error
我有以下映射
@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;
}
以下存储库
@Repository
public interface DocumentRepository extends ElasticsearchRepository<ElasticDocument, String> {
}
但是来自 spring 数据弹性搜索 4.0.3.RELEASE 的以下查询会引发转换错误:
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]
我正在使用 elasticsearch 7.9.1 和 spring data elasticsearch 4.0。3.RELEASE 根据我的理解,从 spring data elasticsearch 4.x 我们不知道只要我在映射中添加字段注释就不需要创建自定义转换
您需要在 @Field
注释中为您的自定义格式添加模式
@Field(type = FieldType.Date, format = DateFormat.custom, pattern = "uuuu-MM-dd'T'HH:mm:ss.SSS")
我有以下映射
@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;
}
以下存储库
@Repository
public interface DocumentRepository extends ElasticsearchRepository<ElasticDocument, String> {
}
但是来自 spring 数据弹性搜索 4.0.3.RELEASE 的以下查询会引发转换错误:
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]
我正在使用 elasticsearch 7.9.1 和 spring data elasticsearch 4.0。3.RELEASE 根据我的理解,从 spring data elasticsearch 4.x 我们不知道只要我在映射中添加字段注释就不需要创建自定义转换
您需要在 @Field
注释中为您的自定义格式添加模式
@Field(type = FieldType.Date, format = DateFormat.custom, pattern = "uuuu-MM-dd'T'HH:mm:ss.SSS")