Eager
Eager

Reputation: 1701

Elasticsearch, join data type: single mapping type for parent and child fields

I want to implement Parent/Child relationships between two entities X and Y with completely different set of fileds each, in Elasticsearch 6.3.2. I was going to create two mapping files for each of the associations and define _parent field on child side.

But according to ES documentation, starting with 6.x multiple types are no longer supported in a single index.

So with this restriction, should I put all the fields for entity X and Y into a single mapping file? If so, what if I have same field, say name in both entities. Should I name them x.name and y.name? What is the approach here?

Upvotes: 1

Views: 1009

Answers (1)

jaspreet chahal
jaspreet chahal

Reputation: 9109

Parent child documents reside in the same index.

Example

Parent document:
Post index-name/_doc/1  
{
  "my_id": "1",
  "text": "This is a question",
  "my_join_field": "question" 
}

Child Document:
Post index-name/_doc/2
{
  "my_id": "2",
  "text": "This is answer",
  "my_join_field": {
    "name": "answer", 
    "parent": "1" 
  }
}

Above have same fields, they can have different fields. In which case fields will be null in one document and have value in other. Join type is used to identify parent and child document

Upvotes: 1

Related Questions