# Weird problem with has\_parent filter

**URL:** <https://discuss.elastic.co/t/weird-problem-with-has-parent-filter/13965>\
**Category:** Elasticsearch\
**Created:** [October 16, 2013, 8:35am UTC](https://discuss.elastic.co/t/weird-problem-with-has-parent-filter/13965 "2013-10-16T08:35:10Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Umit\_Seren](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/umit_seren/32/44933_2.png) [@Umit\_Seren](https://discuss.elastic.co/u/Umit_Seren)\
**Post date:** [October 16, 2013, 8:35am UTC](https://discuss.elastic.co/t/weird-problem-with-has-parent-filter/13965/1 "2013-10-16T08:35:10Z")

</div>

I have a weird issue with the has\_parent filter.

I have following 3 documents in grandparent-parent-child relationship (for  
all documents routing is set to doc1 which is the root document).

In additional to the parent setting I also define an object type (doc1) in  
doc2 that contains the id and the name of the doc1 (denormalize the  
document)

"doc1": {  
"properties": {  
"name": {"type":"string"},  
}  
}

"doc2": {  
"\_parent": {  
"type": "doc1"  
},  
"properties": {  
"name":{"type":"string"},  
"doc1": {  
"type":"object",  
"properties":{  
"id":{"type":"integer"},  
"name":{"type":"string"}  
}  
},  
"field1": {  
"type": "object",  
"properties":{  
"id":{"type":"integer"},  
"name":{"type":"string"}  
}  
}

"doc3": {  
"\_parent": {  
"type": "doc2"  
},  
}

I want to retrieve all doc3 documents that are grandchildren of a specific  
grandparent doc1. The easiert way would be to combine the has\_parent filter

- and the embeded doc1 field in the doc2 document to do it:

\_search against doc3

{  
"query" : {  
"constant\_score" : {  
"filter" : {  
"has\_parent" : {  
"filter" : {  
"term" : {  
"doc1.id" : "1"  
}  
},  
"parent\_type" : "doc2"  
}  
}  
}  
}  
}

Result: 0 hits

This queries returns nothing (I also tried to use the name field of the  
embedded doc1 field but this leads to the same result).

If I use the same query on a different object type field (u..e field1) in  
doc2 I get some hits.

If I use two has\_parent filters it also works fine.

\_search against doc3

{  
"query" : {  
"constant\_score" : {  
"filter" : {  
"has\_parent" : {  
"filter" : {  
"has\_parent": {  
"filter": {  
"term" : {  
"\_id" : "1"  
}  
},  
"parent\_type":"doc1"  
}  
},  
"parent\_type" : "doc2"  
}  
}  
}  
}  
}

Could it be that there is some collision between the field name (doc1) and  
the parent\_type/parent (doc1) ?

--  
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).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<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:12am UTC](https://discuss.elastic.co/t/weird-problem-with-has-parent-filter/13965/2 "2017-07-06T02:12:13Z")

</div>

Closed on July 6, 2017, 2:12am UTC


