如何在 Spring data elasticsearch 中映射嵌套对象
我的对象 1 包含对象 2 的列表。如何有效地映射它以便轻松查询回 elasticsearch?我想根据ID检索对象2。
@Document(indexName = xxx, type = xxx)
public class Object1 {
private List<Obj2> lstObj2;
}
public class Obj2 {
private Long id;
}
最佳答案
像这样使用嵌套对象
:
@Document(indexName = xxx, type = xxx)
public class Object1 {
@Field(type = FieldType.Nested)
private List<Obj2> lstObj2;
}
public class Obj2 {
private Long id;
}
根据您的要求,您似乎也可以使用内部对象
。像这样使用内部对象
。
@Field(type = FieldType.Object)
private List<Obj2> lstObj2;
关于java - 如何在Spring数据elasticsearch中映射嵌套对象列表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35292301/