7

I created two Spring-Data elasticsearch repositories for two parent/child related documents. You can see the document classes for both of them here.

The repositories are getting instantiated in XML with the help of repositories element like this

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

You can find a complete example of the issue in this github repo. My source code is based in the tests found in spring-data-elasticsearch repo. The source code consists of just two domain classes(parent,child), the related repositories, the xml configuration files and a unit test class.

Clone and run mvn test, throws java.lang.IllegalArgumentException: can't add a _parent field that points to an already existing type, that isn't already a parent

It seems that this parent/child relationship produces an elastic search exception which is clear in the Elasticsearch side, but I do not know how to prevent this from happening when executing the Spring Data test.

Community
  • 1
  • 1
ltsallas
  • 1,918
  • 1
  • 12
  • 25

1 Answers1

0

If you are still looking for the answer I solved this by Setting the createIndex=false in the @Document of the parent. And creating this in manually in the beans

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

This should create the parent first and then the associated children. Also do clear the document before you update the mapping.

Karthik
  • 929
  • 2
  • 12
  • 24