2

I'm trying to add a new type as a child of an existing type. From ElasticSearch documentation, it looks like this is possible but there is no details about how to do it.

Here's what the documentation says:

This must be done at index creation time, or with the update-mapping API before the child type has been created.

There are no details about setting up a parent-child relationship in the update-mapping API documentation.

Intuitively, I think a parent-child relationship should be allowed to be established after a parent already exists since the parent does not need to know anything about the child.

Here's the error I'm getting when I create a new type as a child:

{
"error": {
  "root_cause": [
    {
      "type": "illegal_argument_exception",
      "reason": "can't add a _parent field that points to an already existing type"
    }
  ],
  "type": "illegal_argument_exception",
  "reason": "can't add a _parent field that points to an already existing type"
},
"status": 400
}
vishal
  • 895
  • 1
  • 9
  • 25

3 Answers3

5

This is not allowed in ElasticSearch, so it mandates to create both parent and child in the same request or call.

Subhasis Khatua
  • 136
  • 1
  • 4
0

Answering my own question. Found this post that explains why this isn't possible. The documentation is still misleading as it claims that this is possible.

Community
  • 1
  • 1
vishal
  • 895
  • 1
  • 9
  • 25
0

For anyone using Spring Data Elasticsearch 3.0.x (ES 5.x): this error can occur when you have a separate repository for parent and child entity (document) and the parent repository gets instantiated first (which in turn defines the parent mapping first).

The workaround is to fix order in which the repos get created, e.g. like this:

/**
 * Workaround: Child ES type must be defined before the parent. The order matters!
 */
@Configuration
@DependsOn({"childRepository", "parentRepository"})
public class ElasticConfig {
}
stuchl4n3k
  • 588
  • 5
  • 14