简体   繁体   English

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

[英]How to map List of nested objects in Spring data elasticsearch

How to map Nested objects in Spring data elasticsearch如何在 Spring 数据弹性搜索中映射嵌套对象

I have object 1 having list of object 2. How to efficiently map this so that querying back elasticsearch is easy ?我有对象 1 有对象 2 的列表。如何有效地映射它以便查询回 elasticsearch 很容易? I want to retrieve object 2 based on ID.我想根据 ID 检索对象 2。

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

public class Obj2 {

    private Long id;
}

Use nested Object like this:像这样使用nested Object

@Document(indexName = xxx, type = xxx)
public class Object1 {

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

public class Obj2 {
  private Long id;
}

As per your requirement it seems that you can use inner Object as well.根据您的要求,您似乎也可以使用inner Object Use inner object like this.像这样使用inner object

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM