# Performance problems with has parent filter

**URL:** <https://discuss.elastic.co/t/performance-problems-with-has-parent-filter/16698>\
**Category:** Elasticsearch\
**Created:** [March 30, 2014, 7:28am UTC](https://discuss.elastic.co/t/performance-problems-with-has-parent-filter/16698 "2014-03-30T07:28:33Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Lauri](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/lauri/32/1675_2.png) [@Lauri](https://discuss.elastic.co/u/Lauri)\
**Post date:** [March 30, 2014, 7:28am UTC](https://discuss.elastic.co/t/performance-problems-with-has-parent-filter/16698/1 "2014-03-30T07:28:33Z")

</div>

Hi,

I'm having performance problems with has parent filter.

The for the child document is:  
{  
"program": {  
"\_parent": { "type": "series" },  
...  
}  
}

And for the parent document:  
{  
"series": {  
...  
"properties": {  
...  
"subject":{  
"type": "object",  
"properties": {  
...  
"\_path": {  
"type": "object",  
"properties": {  
"id": { "type": "string", "analyzer": "path\_analyzer" }  
...  
}  
}  
}  
},  
...  
}  
}  
}

If I search documents of type program (the child) like this:  
{  
"from": 0,  
"size": 25,  
"query": {  
"filtered": {  
"query": { "match\_all": {} },  
"filter": {  
"has\_parent": {  
"filter": {  
"terms" : {  
"subject.\_path.id" : ["5-162"]  
}  
},  
"parent\_type" : "series"  
}  
}  
}  
}  
}

It takes constantly around 160 milliseconds to run and it returns finds  
about 60k documents.

If I search documents of type series (the parent) like this:  
{  
"from" : 0,  
"size" : 25,  
"query" : {  
"filtered": {  
"query": { "match\_all": {} },  
"filter": {  
"terms": {  
"subject.\_path.id": ["5-162"]  
}  
}  
}  
}  
}

It takes around 5 milliseconds and returns about 400 documents.

The total count of program objects is about 1,7M and series objects 11k.  
The index is fully optimized and the cluster is not doing anything else.  
The index has 3 shards and 1 replica of each shard. There are three nodes  
in the cluster. The nodes have twice the ram that is the index size. Half  
of the ram is assigned to Elasticsearch. Elasticsearch version is 1.0. If I  
use bigdesk plugin, it looks like there is more than enough ram. I'm not  
seeing cache evictions or something like that.

So for me it looks like there is something weird going on as the has parent  
filter runs more than 30 times slower than the actual parent query. Is  
there anything I can do to make it faster?

Thanks,  
Lauri

--  
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/e2c05acb-99e3-4f00-816f-7d1e33d7bbfa%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/e2c05acb-99e3-4f00-816f-7d1e33d7bbfa%40googlegroups.com).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

<div class="post-metadata">

**Author:** ![Binh\_Ly\_2](https://avatars.discourse-cdn.com/v4/letter/b/d07c76/32.png) [@Binh\_Ly\_2](https://discuss.elastic.co/u/Binh_Ly_2)\
**Post date:** [March 31, 2014, 8:13pm UTC](https://discuss.elastic.co/t/performance-problems-with-has-parent-filter/16698/2 "2014-03-31T20:13:42Z")

</div>

Looking briefly, sounds normal to me. Remember has\_parent is a "join"  
whereas your other query is a straight to one type/no join query. The only  
thing I can think of is if you feel you have spare capacity per node, try  
increasing the number of shards a bit (like maybe 6 shards) and see if it  
makes any difference.

--  
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/29e65cfa-03c6-4acf-a6cd-7e882be22ce5%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/29e65cfa-03c6-4acf-a6cd-7e882be22ce5%40googlegroups.com).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

<div class="post-metadata">

**Author:** ![Karol\_Gwaj](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/karol_gwaj/32/1324_2.png) [@Karol\_Gwaj](https://discuss.elastic.co/u/Karol_Gwaj)\
**Post date:** [April 1, 2014, 8:34am UTC](https://discuss.elastic.co/t/performance-problems-with-has-parent-filter/16698/3 "2014-04-01T08:34:20Z")

</div>

there is not that much you can really do here  
parent/child queries tend to be very slow & eat a lot of heap space

i had similar performance problem  
in my case i had 3 level relationship (parent/child/grandchild) and query  
time was in average x10 slower for every level

so my suggestion will be to switch to using nested documents + update api  
if your query time is more important than update time, that will be the way  
to go  
(in my case query performance improvement was x100 times)

> **[Elasticsearch Platform — Find real-time answers at scale](https://www.elastic.co)**
>
> Power insights and outcomes with the Elasticsearch Platform and AI. See into your data and find answers that matter with enterprise solutions designed to help you build, observe, and protect. Try Elasticsearch free today.

> **[Elasticsearch Platform — Find real-time answers at scale](https://www.elastic.co)**
>
> Power insights and outcomes with the Elasticsearch Platform and AI. See into your data and find answers that matter with enterprise solutions designed to help you build, observe, and protect. Try Elasticsearch free today.

Regards,  
Karol Gwaj

On Sunday, March 30, 2014 8:28:33 AM UTC+1, Lauri wrote:

> Hi,
> 
> I'm having performance problems with has parent filter.
> 
> The for the child document is:  
> {  
> "program": {  
> "\_parent": { "type": "series" },  
> ...  
> }  
> }
> 
> And for the parent document:  
> {  
> "series": {  
> ...  
> "properties": {  
> ...  
> "subject":{  
> "type": "object",  
> "properties": {  
> ...  
> "\_path": {  
> "type": "object",  
> "properties": {  
> "id": { "type": "string", "analyzer": "path\_analyzer" }  
> ...  
> }  
> }  
> }  
> },  
> ...  
> }  
> }  
> }
> 
> If I search documents of type program (the child) like this:  
> {  
> "from": 0,  
> "size": 25,  
> "query": {  
> "filtered": {  
> "query": { "match\_all": {} },  
> "filter": {  
> "has\_parent": {  
> "filter": {  
> "terms" : {  
> "subject.\_path.id" : ["5-162"]  
> }  
> },  
> "parent\_type" : "series"  
> }  
> }  
> }  
> }  
> }
> 
> It takes constantly around 160 milliseconds to run and it returns finds  
> about 60k documents.
> 
> If I search documents of type series (the parent) like this:  
> {  
> "from" : 0,  
> "size" : 25,  
> "query" : {  
> "filtered": {  
> "query": { "match\_all": {} },  
> "filter": {  
> "terms": {  
> "subject.\_path.id": ["5-162"]  
> }  
> }  
> }  
> }  
> }
> 
> It takes around 5 milliseconds and returns about 400 documents.
> 
> The total count of program objects is about 1,7M and series objects 11k.  
> The index is fully optimized and the cluster is not doing anything else.  
> The index has 3 shards and 1 replica of each shard. There are three nodes  
> in the cluster. The nodes have twice the ram that is the index size. Half  
> of the ram is assigned to Elasticsearch. Elasticsearch version is 1.0. If I  
> use bigdesk plugin, it looks like there is more than enough ram. I'm not  
> seeing cache evictions or something like that.
> 
> So for me it looks like there is something weird going on as the has  
> parent filter runs more than 30 times slower than the actual parent query.  
> Is there anything I can do to make it faster?
> 
> Thanks,  
> Lauri

--  
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/91c59820-c9e6-40fc-8f7f-b2ee1a4cd19e%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/91c59820-c9e6-40fc-8f7f-b2ee1a4cd19e%40googlegroups.com).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

<div class="post-metadata">

**Author:** ![Lauri](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/lauri/32/1675_2.png) [@Lauri](https://discuss.elastic.co/u/Lauri)\
**Post date:** [April 1, 2014, 2:40pm UTC](https://discuss.elastic.co/t/performance-problems-with-has-parent-filter/16698/4 "2014-04-01T14:40:31Z")

</div>

Hi,

Thank you for your replies!

I was afraid that the answer would be something like that. I was just  
amazed how slow the has parent filter is as any other queries take just a  
few milliseconds to execute. I guess I have to find out how I could  
denormalize my data. The problem is that the parents may update frequently  
and they can potentially have thousands of children.

Best,  
Lauri

On Tue, Apr 1, 2014 at 11:34 AM, Karol Gwaj [karol@gwaj.me](mailto:karol@gwaj.me) wrote:

> there is not that much you can really do here  
> parent/child queries tend to be very slow & eat a lot of heap space
> 
> i had similar performance problem  
> in my case i had 3 level relationship (parent/child/grandchild) and query  
> time was in average x10 slower for every level
> 
> so my suggestion will be to switch to using nested documents + update api  
> if your query time is more important than update time, that will be the  
> way to go  
> (in my case query performance improvement was x100 times)
> 
> [Elasticsearch Platform — Find real-time answers at scale | Elastic](http://www.elasticsearch.org/blog/managing-relations-inside-elasticsearch/)
> 
> [Elasticsearch Platform — Find real-time answers at scale | Elastic](http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/docs-update.html)
> 
> Regards,  
> Karol Gwaj
> 
> On Sunday, March 30, 2014 8:28:33 AM UTC+1, Lauri wrote:
> 
> > Hi,
> > 
> > I'm having performance problems with has parent filter.
> > 
> > The for the child document is:  
> > {  
> > "program": {  
> > "\_parent": { "type": "series" },  
> > ...  
> > }  
> > }
> > 
> > And for the parent document:  
> > {  
> > "series": {  
> > ...  
> > "properties": {  
> > ...  
> > "subject":{  
> > "type": "object",  
> > "properties": {  
> > ...  
> > "\_path": {  
> > "type": "object",  
> > "properties": {  
> > "id": { "type": "string", "analyzer": "path\_analyzer" }  
> > ...  
> > }  
> > }  
> > }  
> > },  
> > ...  
> > }  
> > }  
> > }
> > 
> > If I search documents of type program (the child) like this:  
> > {  
> > "from": 0,  
> > "size": 25,  
> > "query": {  
> > "filtered": {  
> > "query": { "match\_all": {} },  
> > "filter": {  
> > "has\_parent": {  
> > "filter": {  
> > "terms" : {  
> > "subject.\_path.id" : ["5-162"]  
> > }  
> > },  
> > "parent\_type" : "series"  
> > }  
> > }  
> > }  
> > }  
> > }
> > 
> > It takes constantly around 160 milliseconds to run and it returns finds  
> > about 60k documents.
> > 
> > If I search documents of type series (the parent) like this:  
> > {  
> > "from" : 0,  
> > "size" : 25,  
> > "query" : {  
> > "filtered": {  
> > "query": { "match\_all": {} },  
> > "filter": {  
> > "terms": {  
> > "subject.\_path.id": ["5-162"]  
> > }  
> > }  
> > }  
> > }  
> > }
> > 
> > It takes around 5 milliseconds and returns about 400 documents.
> > 
> > The total count of program objects is about 1,7M and series objects 11k.  
> > The index is fully optimized and the cluster is not doing anything else.  
> > The index has 3 shards and 1 replica of each shard. There are three nodes  
> > in the cluster. The nodes have twice the ram that is the index size. Half  
> > of the ram is assigned to Elasticsearch. Elasticsearch version is 1.0. If I  
> > use bigdesk plugin, it looks like there is more than enough ram. I'm not  
> > seeing cache evictions or something like that.
> > 
> > So for me it looks like there is something weird going on as the has  
> > parent filter runs more than 30 times slower than the actual parent query.  
> > Is there anything I can do to make it faster?
> > 
> > Thanks,  
> > Lauri
> > 
> > --  
> > 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/91c59820-c9e6-40fc-8f7f-b2ee1a4cd19e%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/91c59820-c9e6-40fc-8f7f-b2ee1a4cd19e%40googlegroups.com)[https://groups.google.com/d/msgid/elasticsearch/91c59820-c9e6-40fc-8f7f-b2ee1a4cd19e%40googlegroups.com?utm\_medium=email&utm\_source=footer](https://groups.google.com/d/msgid/elasticsearch/91c59820-c9e6-40fc-8f7f-b2ee1a4cd19e%40googlegroups.com?utm_medium=email&utm_source=footer)  
> > .
> 
> For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

--  
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/CA%2BMBRY%2BR17LhZrL%2B5pOFWLCwXOrZs4Foaw2Y67QmhhUaZn2zMg%40mail.gmail.com](https://groups.google.com/d/msgid/elasticsearch/CA%2BMBRY%2BR17LhZrL%2B5pOFWLCwXOrZs4Foaw2Y67QmhhUaZn2zMg%40mail.gmail.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, 1:39am UTC](https://discuss.elastic.co/t/performance-problems-with-has-parent-filter/16698/5 "2017-07-06T01:39:01Z")

</div>


