java - 无法从TemporalAccessor获取即时消息:{},ISO解析为java.time.format.Parsed类型的2018-01-01

标签 java spring-boot elasticsearch spring-data-elasticsearch elasticsearch-dsl

我用以下映射制作了一个Elasticsearch(7.8.1版)文档:

{
    "transaction": {
        "mappings": {
            "properties": {
                "_class": {
                    "type": "text",
                    "fields": {
                        "keyword": {
                            "type": "keyword",
                            "ignore_above": 256
                        }
                    }
                
                },
                "settlementEntries": {
                    "type": "nested",
                    "properties": {
                        "settlementDate": {
                            "type" : "date",
                            "format" : "uuuu-MM-dd"
                        },
                        "settlementId": {
                            "type": "long"
                        }
                    }
                },
                "transactionId": {
                    "type": "text",
                    "fields": {
                        "keyword": {
                            "type": "keyword",
                            "ignore_above": 256
                        }
                    }
                }
            }
        }
    }
}
我使用的格式为yyyy-MM-dd来存储沉降日期。使用curl进行查询时,可以使用CURL -X GET localhost:9200/transaction/_search查看数据。但是,当我尝试通过springboot进行相同操作时,会抛出错误。我的实体是:
public class TransactionBo {

    @Id
    private String transactionId;
    @Field(type = FieldType.Nested)
    private SettlementEntryBo settlementEntries;
    
}
public class SettlementEntryBo {

    @Id
    private Long settlementId;
    @Nullable
    @Field(type = FieldType.Date, format = DateFormat.custom, pattern = "uuuu-MM-dd")
private Date settlementDate;

}
从我可以看出来的问题在于这里的映射:
@Field(type = FieldType.Date, format = DateFormat.custom, pattern = "uuuu-MM-dd")
private Date settlementDate;
[错误片段]:
2020-09-05 02:51:18.105错误10080-[nio-8090-exec-4] oaccC [。[。[/]。[dispatcherServlet]:Servlet [dispatcherServlet]的Servlet.service()路径[]引发异常[请求处理失败;嵌套异常为java.time.DateTimeException:无法从TemporalAccessor获取即时消息:{},ISO解析为类型为java.time.format.Parsed的2016-01-01,其根本原因是
java.time.temporal.UnsupportedTemporalTypeException:不支持的字段:InstantSeconds

最佳答案

更改模式以使用uuuu代替yyyy;这is documented here,Elasticsearch中的更改负责:https://www.elastic.co/guide/en/elasticsearch/reference/current/migrate-to-java-time.html#java-time-migration-incompatible-date-formats
我看到的另一件事:
您正在使用仅包含年,月和日的日期格式。那是个简单的约会。但是java.util.Date不是日期,而是UTC区域中的时间瞬时-包括时间戳。
因此,您应该像Ole在其注释中建议的那样更改属性类型java.time.LocalDate。这些类是在Java 8中引入的,以克服java.util.Date的所有不足。

关于java - 无法从TemporalAccessor获取即时消息:{},ISO解析为java.time.format.Parsed类型的2018-01-01,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63747516/

相关文章:

java - 访问匿名外部类而不存储在变量中?

java - 什么是更快的 Java REST 服务框架?

java - 是否可以在同一程序的多个实例的多个线程之间进行通信?

java - Spring 执行器即使设置server.servlet.contextPath后也会显示404 Not found错误

tomcat - 多部分异常 - Spring Boot 中的 maxPostSize 错误

apache-spark - 解释程序Spark依赖关系管理中的zeppelin AdditionalRemoteRepository URL配置

elasticsearch - 在Elastic Search中将嵌套的单位数据存储在Kibana中进行分析是否更好?

java - 从 Java 原语转换为包装类

spring-boot - 当我设置 spring.active.profile 时,Spring Boot 不读取 Application.yml 文件

java - Elasticsearch - 如何使用 Java 在 JSON 对象中添加或编辑字符串数组?