2016-02-13 35 views
0
@Document(indexName = "test", type = "author") 
public class Author { 
    private String authorId; 
    private List<Book> books; 
} 

@Document(indexName = "test", type = "book") 
public class Book { 
    private String bookId; 
} 

当我保存作者时使用弹簧数据elasticsearch,我希望书籍保存在不同的实体而不是子文档中。可能吗?弹簧数据弹性搜索是否支持将内部对象保存为新文档

回答

0

是的,但您需要存储Book ID而不是Book实体。非关系数据存储不支持像RDB这样的外键。

@Document(indexName = "test", type = "author") 
public class Author { 
    private String authorId; 
    private List<String> bookIds; 
} 

此外,通过这样做书籍不与作者一起索引。如果您尝试搜索“编写具有特定标题的书籍的作者”,则会得到性能损失,而如果您嵌套它,ES将索引author.book.title。

Denormalizing your Data section of ES doc对此有一个很好的解释