【问题标题】:LastModifiedDate is not getting updated for an entity using spring-data-elasticsearch使用 spring-data-elasticsearch 的实体未更新 LastModifiedDate
【发布时间】:2021-05-24 12:45:40
【问题描述】:

//实体模型定义

@Builder.Default
@LastModifiedDate
@Field(type = FieldType.Date, name = "modified_dt", format = DateFormat.basic_date_time)
private Instant modifiedDate = Instant.now();

//更新属性调用

protected void updateAttribute(String id, Document document) throws Exception {
    UpdateQuery updateQuery = UpdateQuery.builder(id).withDocument(document).build();
    UpdateResponse updateResponse = operations.update(updateQuery, indexCoordinates());
    Result result = updateResponse.getResult();
    if (!result.equals(Result.UPDATED)) {
        throw new Exception();
    }
}

【问题讨论】:

  • 我需要更新 LastModifiedDate,你的回答没有解决这个问题

标签: elasticsearch spring-data-elasticsearch


【解决方案1】:

从版本 7 开始日期格式有所不同,因为 yyyy 已被 uuuu 取代,可能与此有关:

https://www.elastic.co/guide/en/elasticsearch/reference/current/migrate-to-java-time.html#java-time-migration-incompatible-date-formats

Lombok 注释 @Builder.Default 也不适用于无参数构造函数,因此它可能也会产生干扰。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2012-08-06
    • 1970-01-01
    • 2018-06-15
    • 2019-12-21
    • 2023-03-07
    • 2018-11-27
    • 1970-01-01
    • 2016-03-31
    相关资源
    最近更新 更多