如何在 Spring 数据 elasticsearch 中映射嵌套对象列表

How to map List of nested objects in Spring data elasticsearch

如何在 Spring 数据 elasticsearch

中映射嵌套对象

我有对象 1 和对象 2 的列表。如何有效地映射它以便查询 elasticsearch 很容易?我想根据 ID 检索对象 2。

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

public class Obj2 {

    private Long id;
}

像这样使用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;