# Has\_parent slow in filter, fast in query?

**URL:** <https://discuss.elastic.co/t/has-parent-slow-in-filter-fast-in-query/19102>\
**Category:** Elasticsearch\
**Created:** [August 5, 2014, 8:03pm UTC](https://discuss.elastic.co/t/has-parent-slow-in-filter-fast-in-query/19102 "2014-08-05T20:03:06Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![jekstrom](https://avatars.discourse-cdn.com/v4/letter/j/f19dbf/32.png) [@jekstrom](https://discuss.elastic.co/u/jekstrom)\
**Post date:** [August 5, 2014, 8:03pm UTC](https://discuss.elastic.co/t/has-parent-slow-in-filter-fast-in-query/19102/1 "2014-08-05T20:03:06Z")

</div>

We ran into a problem with a slow query. Turns out having a has\_child (or  
has\_parent) query in the "filter" part of a "filtered" query is a lot  
slower than having the same has\_child filter in the "query" part of the  
"filtered" query.

The faster of the two queries runs in under 100ms, while the slower one  
takes 250-300ms. I don't understand why these would have different run  
times, any ideas?

The index is around 2GB. The child with about 600,000 docs, the parent with  
about 3,000,000 docs.

These are the two queries:

Slower:

"query": {  
"filtered": {  
"filter": {  
"and": {  
"filters": [  
{  
"range": {  
"price": {  
"gt": "0"  
}  
}  
},  
{  
"has\_parent": {  
"type": "product",  
"query": {  
"match\_all": {}  
}  
}  
}  
]  
}  
}  
}  
}

Faster:

"query": {  
"filtered": {  
"query": {  
"has\_parent": {  
"type": "product",  
"query": {  
"match\_all": {}  
}  
}  
},  
"filter": {  
"and": {  
"filters": [  
{  
"range": {  
"price": {  
"gt": "0"  
}  
}  
}  
]  
}  
}  
}  
}

--  
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/d811bca1-9798-49c5-b1f6-79cb5857f547%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/d811bca1-9798-49c5-b1f6-79cb5857f547%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, 1:10am UTC](https://discuss.elastic.co/t/has-parent-slow-in-filter-fast-in-query/19102/2 "2017-07-06T01:10:39Z")

</div>


