【发布时间】:2015-05-04 12:43:45
【问题描述】:
我正在使用 Spring Data ElasticSearch 来执行 CRUD 操作。默认情况下,当使用 @Document 注释的 POJO 写入 ElasticSearch 索引时,索引字段名称与 POJO 的 Java 属性名称相同。 如何将索引字段名称配置为不同? 例如,使用此 Document POJO:
@Document(indexName = "areas", type = "area")
public class Area {
@Id
private String id;
private String countyName;
private String postOfficeName;
private String stateName;
我该如何配置,以便 ElasticSearch 中的索引字段被序列化为county_name 而不是countyName?
【问题讨论】:
-
我通过在@Document 注释 POJO 中添加 Jackson 的 @JsonProperty("county_name") 找到了一种解决方法,但这具有失去 Spring Data 的 DSL findBy... 操作功能的缺点因为它们依赖于驼峰式 Java 属性名称。
-
@JspnProperty使用的更多细节在stackoverflow.com/questions/33537229/… 中讨论
标签: elasticsearch spring-data spring-data-elasticsearch