Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Spring Elastic Search Custom Field names

I am new to Elastic Search and I am trying to implement it using Spring-data-elasticsearch.

I have fields with names such as "Transportation", "Telephone_Number" in our elastic search documents.

When I try to map my @Domain object fields with those, I don't get any data for those as I couldn't successfully map those fields.

Tried to use @Field, was disappointed as it didn't have 'name' property in it to map with custom field name.

Tried different variations of a GETTER function, none of those seem to be mapping to those fields.

I started wondering if there's something I'm missing here. How does a domain object field look like which should map to a filed called something like "Transportation" ?

Any help appreciated

like image 925
Vsoma Avatar asked Nov 05 '15 05:11

Vsoma


1 Answers

You can use custom name. Spring Data ES use Jackson. So, you can use @JsonProperty("your_custom_name") to enable custom name in ES Mapping

for example:

@Document(indexName = "your_index_name", type = "your_type_name")
public class YourEntity {
   ....
   @JsonProperty("my_transportation")
   @Field(type = FieldType.String, searchAnalyzer = "standard", indexAnalyzer = "standard", store = true) // just for example
   private String myTransportation;
   ....
}

Note: I'm sorry anyway, my english is bad.. :D

like image 172
Efriandika Pratama Avatar answered Oct 03 '22 22:10

Efriandika Pratama