【问题标题】:How to migrate Spring Data Elasticsearch from 3.x version to 4.x version如何将 Spring Data Elasticsearch 从 3.x 版本迁移到 4.x 版本
【发布时间】:2021-04-01 21:42:49
【问题描述】:

我想从 elasticsearch 中获取一些数据,我在 Spring Data Elasticsearch v 3.2.12 上成功了,但是在 4.x 版本中我不能做同样的事情。

在elasticsearch中,我有这样的数据:

{
    "_index" : "abc",
    "_type" : "_doc",
    "_id" : "SVJhjnEB6V1CiOscApfa",
    "_score" : 2.0954367E-5,
    "_source" : {
      "name" : "abc",
      "timestamp" : "2020-04-18T20:40:51Z",
      "temperature[*C]" : 20.56,
      "humidity[%]" : 45.65
    }

我想像id一样使用“_id”

我的 Dto 课程

@Data //from Lombok
@Document(indexName = "abc",type = "_doc")
public class Ascr2Dto {
  @Id
  @ReadOnlyProperty
  private String id;
  private String name;
  private Date timestamp;
  @JsonProperty("temperature[*C]")
  private float temperature;
  @JsonProperty("humidity[%]")
  private float humidity;}

如果我尝试从 Spring Data Elasticsearch 3.x 迁移到 4.x,当我尝试 findById 方法时,我会收到“IllegalArgumentException: null”

我浏览了这个帖子,没有结果 Spring Data Elasticsearch (4.x) - Using @Id forces id field in _source

谢谢!

【问题讨论】:

    标签: java spring elasticsearch spring-data spring-data-elasticsearch


    【解决方案1】:

    我通过以下步骤解决了问题: 1.我在最新版本中更新了我的所有依赖项(在 7.10.1 和 spring data elasticsearch 在 7.10.1 休息高级客户端) 2.注解@JsonProperty在spring data elasticsearch 4.x版本中不再可用,现在我们需要使用@Field(name = "something")

    【讨论】:

    • @JsonProperty 不是来自 Spring Data Elasticsearch 的注释,而是来自 Jackson。如果您通过 REST 将您的实体传递给其他服务 - 就像某些人所做的那样 - 除了 @Field 之外,您可能还需要它们
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多