无法从temporalaccessor获取instant:{},iso解析为java.time.format.parsed类型的2018-01-01

xienkqul  于 2021-06-14  发布在  ElasticSearch
关注(0)|答案(1)|浏览(307)

我制作了一个elasticsearch(7.8.1版)文档,其中包含以下Map:

{
    "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;

}

据我所知,问题在于这里的Map:

@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]o.a.c.c.c.[/].[dispatcherservlet]:路径为[]的上下文中servlet[dispatcherservlet]的servlet.service()引发异常[请求处理失败;嵌套的异常是java.time.datetimeexception:无法从temporalaccessor获取instant:{},iso已解析为类型为java.time.format.parsed]的2016-01-01,并带有根本原因
java.time.temporal.unsupportedtemporaltypeexception:不支持的字段:instantseconds

ebdffaop

ebdffaop1#

将模式改为使用uuuu而不是yyyy;这在这里有记录,elasticsearch的变化导致了这一点:https://www.elastic.co/guide/en/elasticsearch/reference/current/migrate-to-java-time.html#java-时间迁移不兼容的日期格式
我看到的另一件事是:
您使用的日期格式只包含年、月和日。那是个普通的约会。但是 java.util.Date 不是日期,而是utc区域中的一个瞬间-包括时间戳。
所以你应该改变你的财产类型 java.time.LocalDate 就像奥莱在评论中说的那样。这些类在Java8中被引入,以弥补 java.util.Date 有。

相关问题