How to define ElasticSearch index field names for a POJO using Spring Data ElasticSearch
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.
I think that you have to use properties of @Field
annotation, I'm almost sure of this.Please See here.
As from documentation:
@Field: Applied at the field level and defines properties of thefield, most of the attributes map to the respective ElasticsearchMapping definitions (the following list is not complete, check theannotation Javadoc for a complete reference):
name: The name of the field as it will be represented in theElasticsearch document, if not set, the Java field name is used.
type: the field type, can be one of Text, Keyword, Long, Integer,Short, Byte, Double, Float, Half_Float, Scaled_Float, Date,Date_Nanos, Boolean, Binary, Integer_Range, Float_Range, Long_Range,Double_Range, Date_Range, Ip_Range, Object, Nested, Ip, TokenCount,Percolator, Flattened, Search_As_You_Type. See Elasticsearch MappingTypes
format and pattern definitions for the Date type. format must bedefined for date types.
store: Flag wether the original field value should be store inElasticsearch, default value is false.
analyzer, searchAnalyzer, normalizer for specifying custom customanalyzers and normalizer.