Its about parent-child relationship

can we have multiple child for a same parent relationship in elasticsearch ?? or can a single parent document have multiple child document ??

a child can have only one parent
a parent can have 0-n children

how do we obtain relationship of one parent with 'n' number of children

You index n documents with parent=the_parent_doc_id.

can it be in detain i didn't get it

can it be explained in detaili i didn't get it

May be I did not get your question?

Have a look at docs here:

If you still don't understand, may be you could explain with some examples what you are doing?

ya i got the link which u had sent.... but my doubt is for example i have places as the index name
and under that i have types to be restaurants and parks. In turn these two will have individual documents inside with different id's.

How can I make ‘places’ to be parent for both ‘restaurants’ child and ‘parks’ child document as well.

Places cannot be an index if that is what you want to do.
You will need a places document, with parks/restaurants as the children.

But that doesn't really make a lot of sense to me.

Parent-Child can be very useful if you have a parent entity that gets updated frequently and you want to avoid having to update this data on every child entity. In your case it sounds like the data is quite states, so it may be worthwhile considering denormalising it instead, which gives a flatter model that in many cases tend to scale and perform better.

Ya i got it 'places' should be 'type' and cannot be 'index'.
My doubt was how to create a parent child relationship if i have places as the parent document and child documents to be restaurants, parks and the theaters. how do i map all these documents

How can i map the parent document with 3 child documents.

Reading through the thread it seems to me like we should take a step back actually and first understand what exactly you want to do with these documents once they are indexed:

  • What types of queries do you want to execute against the finished index?
  • What types of updates will have to be applied to your documents, if any?


I want to perform union operation considering those documents. i.e. by using 'OR' operator

Hmm - I still don't get the full picture. Maybe it helps if you add a more detailed example? Leave out the technical details for now and focus just on the use case. Something along the lines of: "A user wants to know which parks and restaurants are close to their location."

If this requests sounds weird, here's why I'm asking: "Your question appears to be an "XY Problem" ... that is: you are dealing with "X", you are assuming "Y" will help you, and you are asking about "Y" without giving more details about the "X" so that we can understand the full issue. Perhaps the best solution doesn't involve "Y" at all? See Also:" (Disclaimer taken from )


I hope Kruthika got answer for her question by now.
If i understand the question correctly, I think you need the mapping file to map "places" to three different type of children.

> post  http://localhost:9200/sys
> {
>   "mappings": {
>     "places" : {},
>     "parks" : {
>         "_parent" : {
>             "type" : "places"
>         }
>     },
>     "restaurants" : {
>         "_parent" : {
>             "type" : "places"
>         }
>     },
>      "theaters" : {
>         "_parent" : {
>             "type" : "places"
>         }
>     }
>   }
> }

ya thank you