如何映射Spring数据elasticsearch

时间:2016-02-09 12:37:45

标签: java spring elasticsearch spring-data spring-data-elasticsearch

如何在Spring数据弹性搜索中映射嵌套对象

我有对象1有对象列表2.如何有效地映射这个以便查询弹性搜索很容易?我想根据ID检索对象2.

@Document(indexName = xxx, type = xxx)
public class Object1 {
    private List<Obj2> lstObj2;
} 

public class Obj2 {

    private Long id;
}

1 个答案:

答案 0 :(得分:0)

USe nested Object是这样的:

@Document(indexName = xxx, type = xxx)
public class Object1 {
@Field(type = FieldType.Nested)
private List<Obj2> lstObj2;
} 

public class Obj2 {

  private Long id;
 }

根据您的要求,您似乎也可以使用inner Object。像这样使用inner object

@Field(type = FieldType.Object)
private List<Obj2> lstObj2;