# Recursive document hierarchy

**URL:** <https://discuss.elastic.co/t/recursive-document-hierarchy/23581>\
**Category:** Elasticsearch\
**Created:** [May 6, 2015, 10:40pm UTC](https://discuss.elastic.co/t/recursive-document-hierarchy/23581 "2015-05-06T22:40:18Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![sridevi\_venugopal](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/sridevi_venugopal/32/714_2.png) [@sridevi\_venugopal](https://discuss.elastic.co/u/sridevi_venugopal)\
**Post date:** [May 6, 2015, 10:40pm UTC](https://discuss.elastic.co/t/recursive-document-hierarchy/23581/1 "2015-05-06T22:40:18Z")

</div>

Hi,

I am seeing problems in querying documents with recursive parents. I want  
to implement a grandparent-parent-child relation with the documents of the  
same type.  
Here is the mapping:  
PUT /test\_version1  
{  
"mappings": {  
"title": {  
"\_parent": {  
"type": "title"  
},  
,  
"dynamic\_templates" : [ {  
"title\_template" : {  
"mapping" : {  
"type" : "multi\_field",  
"fields" : {  
"{name}" : {  
"type" : "{dynamic\_type}",  
"index" : "not\_analyzed"  
},  
"standard" : {  
"type" : "{dynamic\_type}",  
"index" : "analyzed"  
}  
}  
},  
"match\_mapping\_type" : "string",  
"patch\_match" : "\*"  
}  
} ],

```
       "properties" : {
        "region": {"type": "string" }
       }
     }

```

}  
}

I am able to obtain the hierarchy using "has\_child" relation but I want to  
use the "has\_parent" relation. Here is some of the sample data and the  
"has\_parent" query:  
PUT /test\_version1/title/6001?parent=null  
{ "region" : "US" }

PUT /test\_version1/title/6000?parent=6001  
{"region" : "US" }

PUT /test\_version1/title/600?parent=6000&routing=6001  
{"region" : "US" }

and the query:

GET /test\_version1/title/\_search  
{  
"query": {  
"filtered": {

```
    "filter" : {
        "has_parent": {
            "parent_type": "title",
             "query": {
                 "filtered": {
                   
                    "filter": {
                        "has_parent": {
                            "parent_type": "title",
                            "query": {
                                "match": {
                                   "region" : "US"
                                }
                            }
                        }
                 }
               }
             }
        }
    }
}

```

}  
}

Is there any error in my "has\_parent" query or is there a bug/ constraint  
with recursive relations?

## -- Please update your bookmarks! We moved to [https://discuss.elastic.co/](https://discuss.elastic.co/)

You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
To view this discussion on the web visit [https://groups.google.com/d/msgid/elasticsearch/811405c0-ffa3-42aa-8838-e126efd1f2a7%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/811405c0-ffa3-42aa-8838-e126efd1f2a7%40googlegroups.com).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

<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:15am UTC](https://discuss.elastic.co/t/recursive-document-hierarchy/23581/2 "2017-07-06T00:15:17Z")

</div>


