【问题标题】:Does spring data elasticsearch support saving a inner object as a new documentspring data elasticsearch是否支持将内部对象保存为新文档
【发布时间】:2016-02-13 19:47:38
【问题描述】:
@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;
}

在我保存作者时使用 spring data elasticsearch 我希望将书保存在不同的实体而不是子文档中。有可能吗?

【问题讨论】:

    标签: java spring elasticsearch spring-data


    【解决方案1】:

    是的,但您需要存储图书 ID 而不是图书实体。非关系型数据存储不支持 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 对此有很好的解释

    【讨论】:

      猜你喜欢
      • 2016-03-04
      • 2022-09-25
      • 2017-06-19
      • 2018-10-15
      • 2021-01-14
      • 2017-12-14
      • 2016-03-25
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多