Spring Elastic Search Custom Field names

三世轮回 提交于 2019-12-10 02:45:06

问题


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


回答1:


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



来源:https://stackoverflow.com/questions/33537229/spring-elastic-search-custom-field-names

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!