Spring Data Elastic Search 4.0.3 – 日期字段列表

huangapple go评论73阅读模式
英文:

Spring Data Elastic Search 4.0.3 - List Of Dates Field

问题

以下是您要的代码部分的中文翻译:

@Field(type = FieldType.Nested, includeInParent = true, format = DateFormat.date)
private List<LocalDate> birthdates = new ArrayList<>();

这部分代码的功能是定义一个包含生日日期的列表。

请注意,您提到的错误信息是因为Spring Data没有找到将java.lang.Long类型转换为java.time.LocalDate类型的默认转换器。您是否需要创建自定义转换器或包装对象?这是一个值得考虑的问题,因为默认情况下,Spring Data不提供将Long转换为LocalDate的支持。

谢谢您的提问。

英文:

Lets say i have I have a list of birthdates

@Field(type = FieldType.Nested, includeInParent = true, format = DateFormat.date)
private List&lt;LocalDate&gt; birthdates = new ArrayList&lt;&gt;();

What is the proper way to map this using spring data without getting this error..
No converter found capable of converting from type [java.lang.Long] to type [java.time.LocalDate]

Do I really need to create a custom converter? or a wapper object?
I would think this would be supported out of the box.

Thank you in advance.

答案1

得分: 0

以下是翻译好的内容:

正确的属性注解方式应该是:

@Field(type = FieldType.Date, format = DateFormat.date)
private List<LocalDate> birthdates = new ArrayList<>();

这将会将映射条目写入为类型 date,格式为 date,并且存储和搜索数组将正常工作。

不好的消息是,当前版本的 Spring Data Elasticsearch 无法正确处理这个。

好消息是,我刚刚实现了对此的修复,它将包含在版本 4.0.4.RELEASE 和 4.1.0.RC1 中;这两个版本都计划在明天发布。

编辑: 这两个版本现在已经发布。

英文:

The correct way to annotate this property should be

@Field(type = FieldType.Date, format = DateFormat.date)
private List&lt;LocalDate&gt; birthdates = new ArrayList&lt;&gt;();

This would write the mappings entry as type date and format date, and storing and searching the array would work.

The bad news is that the current version of Spring Data Elasticsearch does not handle this correctly.

The good news is, that I just implemented the fix for this, it will be contained in versions 4.0.4.RELEASE and 4.1.0.RC1; both are planned to be released tomorrow.

Edit: both versions are released now

huangapple
  • 本文由 发表于 2020年9月15日 05:33:14
  • 转载请务必保留本文链接:https://go.coder-hub.com/63892103.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定