【问题标题】:Spring Data Elasticsearch Parent/Child Document Repositories / Test execution errorSpring Data Elasticsearch父/子文档存储库/测试执行错误
【发布时间】:2017-03-13 16:52:59
【问题描述】:

我为两个父/子相关文档创建了两个 Spring-Data elasticsearch 存储库。您可以看到它们的文档类here

在这样的 repositories 元素的帮助下,存储库正在 XML 中实例化

<elasticsearch:repositories base-package="com.acme.repositories" />

您可以在this github repo 中找到该问题的完整示例。我的源代码基于spring-data-elasticsearch repo 中的测试。源代码仅包含两个域类(父、子)、相关存储库、xml 配置文件和一个unit test class

克隆并运行mvn test,抛出java.lang.IllegalArgumentException: can't add a _parent field that points to an already existing type, that isn't already a parent

似乎这种父/子关系产生了一个弹性搜索异常,在Elasticsearch side 中很清楚,但我不知道在执行 Spring Data 测试时如何防止这种情况发生。

【问题讨论】:

    标签: spring-data spring-data-elasticsearch


    【解决方案1】:

    如果您仍在寻找答案,我通过在父级的 @Document 中设置 createIndex=false 解决了这个问题。 并在 bean 中手动创建它

                elasticSearchTemplate.createIndex(Parent.class);
                elasticSearchTemplate.putMapping(parent.class);
                elasticSearchTemplate.createIndex(Child1.class);
                elasticSearchTemplate.createIndex(Child2.class);
    

    这应该首先创建父级,然后是关联的子级。 在更新映射之前,请务必清除文档。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2014-06-19
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-09-19
      • 2016-08-21
      • 2019-01-23
      • 1970-01-01
      相关资源
      最近更新 更多