# Possible to have optional \_parent field in future?

**URL:** <https://discuss.elastic.co/t/possible-to-have-optional--parent-field-in-future/427>\
**Category:** Elasticsearch\
**Created:** [May 8, 2015, 11:03pm UTC](https://discuss.elastic.co/t/possible-to-have-optional--parent-field-in-future/427 "2015-05-08T23:03:40Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![jaddison](https://avatars.discourse-cdn.com/v4/letter/j/e5b9ba/32.png) [@jaddison](https://discuss.elastic.co/u/jaddison)\
**Post date:** [May 8, 2015, 11:03pm UTC](https://discuss.elastic.co/t/possible-to-have-optional--parent-field-in-future/427/1 "2015-05-08T23:03:40Z")

</div>

Would it ever be feasible to have a parent/child relationship where the child mapping's `_parent` field was optional? Last time I tried it, the results weren't pretty.

I have this exactly scenario, where it's possible to have a child document without a matching parent document - we treat them somewhat differently in our product, but they're still valid to us.

To achieve this currently, I'm forced to have a separate document type for the parent/child specific documents and another for everything, resulting in having to index documents twice - one for each of the two types.

Is this possible to achieve in future releases? Thanks  
James

---

<div class="post-metadata">

**Author:** ![jpountz](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/jpountz/32/45836_2.png) [@jpountz](https://discuss.elastic.co/u/jpountz)\
**Post date:** [May 10, 2015, 9:43pm UTC](https://discuss.elastic.co/t/possible-to-have-optional--parent-field-in-future/427/2 "2015-05-10T21:43:23Z")

</div>

Maybe you could use a fake parent document for these orphan documents?

---

<div class="post-metadata">

**Author:** ![jaddison](https://avatars.discourse-cdn.com/v4/letter/j/e5b9ba/32.png) [@jaddison](https://discuss.elastic.co/u/jaddison)\
**Post date:** [May 10, 2015, 10:12pm UTC](https://discuss.elastic.co/t/possible-to-have-optional--parent-field-in-future/427/3 "2015-05-10T22:12:54Z")

</div>

Ewww! I suppose faking a parent could work, but it's such a hack. Are optional parents going to be possible in future? Or is this use case completely ridiculous?

---

<div class="post-metadata">

**Author:** ![mvg](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/mvg/32/98890_2.png) [@mvg](https://discuss.elastic.co/u/mvg)\
**Post date:** [May 11, 2015, 8:33am UTC](https://discuss.elastic.co/t/possible-to-have-optional--parent-field-in-future/427/4 "2015-05-11T08:33:37Z")

</div>

The reason why your need to define a parent when indexing a child type is because it is used for routing. ES routes the parent and child docs into the same shard.

I don't fully understand why you need to to index all your documents twice. A document either is a child of a parent or isn't a child of a parent. Can you maybe explain a bit more why you're doing this?

I think we can change the indexing of a child document, so that it also accepts a null parent and then it is an orphan child. But if these orphan child docs ever need to be associated with a parent, it first needs to be deleted and then indexed again. (the update api won't work, because the parent maybe in a different shard)

---

<div class="post-metadata">

**Author:** ![jaddison](https://avatars.discourse-cdn.com/v4/letter/j/e5b9ba/32.png) [@jaddison](https://discuss.elastic.co/u/jaddison)\
**Post date:** [May 12, 2015, 3:56am UTC](https://discuss.elastic.co/t/possible-to-have-optional--parent-field-in-future/427/5 "2015-05-12T03:56:11Z")

</div>

The reason is simple (to me, at least) - sometimes we have orphaned child documents, and this is valid in our system. Ideally parents would always be set, but given the nature of the problem we're solving, our data inputs don't always have parents. But orphan child documents are still useful and valid in our product.

You explain the routing problems associated with switching from orphaned to parented well - in particular the update API concern. I hadn't thought of such complications.

I know we would truly benefit from the optional parent mapping, but it does present problems to which I wish I had the answers...

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [July 6, 2017, 12:14am UTC](https://discuss.elastic.co/t/possible-to-have-optional--parent-field-in-future/427/6 "2017-07-06T00:14:29Z")

</div>


