0

I want to bring some data from elasticsearch, I succeeded with Spring Data Elasticsearch v 3.2.12, but with 4.x version I can't do same thing.

In elasticsearch, I have data like this:

{
    "_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
    }

I want to use "_id" like id

My Dto class

@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;}

If I try to migrate from Spring Data Elasticsearch 3.x to 4.x, when I try findById method, I'm getting "IllegalArgumentException: null"

I went through this thread, without results Spring Data Elasticsearch (4.x) - Using @Id forces id field in _source

Thanks!

George Cosmin
  • 101
  • 1
  • 7

1 Answers1

0

I resolve the problem with this steps: 1.I update all my dependency at latest version (rest high level client at 7.10.1 and spring data elasticsearch at 4.1.2) 2.Annotation @JsonProperty is no longer available in spring data elasticsearch 4.x version, now we need to use @Field(name = "something")

George Cosmin
  • 101
  • 1
  • 7
  • `@JsonProperty` is no annotation from Spring Data Elasticsearch, but from Jackson. If you pass your entity out via REST to other services - as some people do - you might need them in addition to `@Field` – P.J.Meisch Dec 23 '20 at 13:44