# Parent child for unique index on complex beans

**URL:** <https://discuss.elastic.co/t/parent-child-for-unique-index-on-complex-beans/10469>\
**Category:** Elasticsearch\
**Created:** [January 23, 2013, 10:50am UTC](https://discuss.elastic.co/t/parent-child-for-unique-index-on-complex-beans/10469 "2013-01-23T10:50:41Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Matthew\_Young](https://avatars.discourse-cdn.com/v4/letter/m/a6a055/32.png) [@Matthew\_Young](https://discuss.elastic.co/u/Matthew_Young)\
**Post date:** [January 23, 2013, 10:50am UTC](https://discuss.elastic.co/t/parent-child-for-unique-index-on-complex-beans/10469/1 "2013-01-23T10:50:41Z")

</div>

Haven't experimented with ElasticSearch (only read about it).....

Use Neo4j as a store which by default utilizes Lucene to index nodes (and  
relationships). One thing that has always troubled me is how to \*unique \*index  
complex beans. Neo4j has nodes and the relationships between them. There  
is a great SDN module (Spring) that allows domain beans to roll back and  
forth into Neo4j nodes and parent/child relationships. This is great. I  
can create a complex bean like Software with a name property (simple, just  
a string) and an organisation property (complex pointing to another bean).  
Software might have a name "core" and an organisation (via a Neo4j  
relation under the covers) with a name "org.matthew". Unique indexes in  
the SDN exposes Lucene indexes direct (iow, flat documents). So I can put  
a unique index on Software.name but in my world Software isn't unique just  
on it's name but rather a combination of name plus the name of the  
organisation. It is a complex index reacting to changes to the "child".  
For example, if organisation "org.matthew" becomes "org.young" then the  
unique index on Software must be checked for duplicates. Or if the  
organisation "org.matthew" is deleted the request can't be allowed since it  
might kill the index on Software beans.

Each node in Neo4j has a unique id. Could I use the ElasticSearch  
parent/child stuff to make "complex" \*unique \*indexes? How deep can the  
parent/child path get?

--

---

<div class="post-metadata">

**Author:** ![Matthew\_Young](https://avatars.discourse-cdn.com/v4/letter/m/a6a055/32.png) [@Matthew\_Young](https://discuss.elastic.co/u/Matthew_Young)\
**Post date:** [January 24, 2013, 1:14pm UTC](https://discuss.elastic.co/t/parent-child-for-unique-index-on-complex-beans/10469/2 "2013-01-24T13:14:48Z")

</div>

Installed ES....

And played around with the examples from:

[http://www.spacevatican.org/2012/6/3/fun-with-elasticsearch-s-children-and-nested-documents/](http://www.spacevatican.org/2012/6/3/fun-with-elasticsearch-s-children-and-nested-documents/)

If I had read the blog better the first time around I would have noticed  
the restriction on indexing books (children to authors). Namely that an  
author (parent) has to be stated in the creation of the book index. Hum.

In my case with Software then I have to register Organisation first and  
that "bean" has to have a "simple" index (iow. no parent/child) then I can  
register Software with a parent mapping to Organisation. Breaks the case  
when the Organisation reference in the Software can be null but works in  
theory otherwise. Surprised that I could delete the author indexes!? And  
even more surprised when I do GETs that I don't see the mapping information  
in the response.

Weird that the mapping is required to create the book's index but then the  
associated author index can be deleted. Maybe the parent-child mapping can  
be made more restrictive?

--

---

<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, 2:54am UTC](https://discuss.elastic.co/t/parent-child-for-unique-index-on-complex-beans/10469/3 "2017-07-06T02:54:46Z")

</div>


