I'm using Spring Data ElasticSearch to perform CRUD operations. By default, when a POJO annotated with @Document gets written to an ElasticSearch index, the index field names are the same as the POJO's Java property names. How can I configure the index field names to be different ? For example, with this Document POJO:
@Document(indexName = "areas", type = "area")
public class Area {
@Id
private String id;
private String countyName;
private String postOfficeName;
private String stateName;
how can I configure this so that the index field in ElasticSearch gets serialized as county_name instead of countyName ?
As Spring-data-elasticsearch uses fasterxml module to convert POJOs to json document, you could simply use,
@JsonProperty("country_name")
private String countryName
To achieve a different field name in the elasticsearch index.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With