0

I have this model:

public class Foo{
    @Field(type = FieldType.String, store = true)
    String color;
}

right now it maps to the field "color" in elasticsearch document. Can I map it to another field: "shirtColor"? Maybe through an annotation?

user1099123
  • 6,063
  • 5
  • 30
  • 35

1 Answers1

0

spring-data-elasticsearch uses Jackson Object Mapper to serialize the POJO into json. You can use @JsonProperty attribute if you want to change the name of field which is store in Elastic Search.

public class Foo{
   @Field(type = FieldType.String, store = true)
   @JsonProperty("shirtColor")
   String color;
}

However you will loose the benefit of using findBy* methods while querying the data back from elastic search and you will have to write your own custom queries to fetch the data.

Nitin Arora
  • 2,650
  • 1
  • 26
  • 27