# Optimize has\_child query / filter

**URL:** <https://discuss.elastic.co/t/optimize-has-child-query-filter/19296>\
**Category:** Elasticsearch\
**Created:** [August 14, 2014, 10:42pm UTC](https://discuss.elastic.co/t/optimize-has-child-query-filter/19296 "2014-08-14T22:42:18Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![kisi](https://avatars.discourse-cdn.com/v4/letter/k/ecd19e/32.png) [@kisi](https://discuss.elastic.co/u/kisi)\
**Post date:** [August 14, 2014, 10:42pm UTC](https://discuss.elastic.co/t/optimize-has-child-query-filter/19296/1 "2014-08-14T22:42:18Z")

</div>

Hi,

i'm currently thinking if i could write a has\_child filter differently to  
performe a faster search.

I want all products (parents) with the term "printer" and which have set  
the field "Client3.Type" to "K".

Currently i'm executing this query. But i think this way elasticsearch is  
first searching for the query and then filtering the results. I would  
preffere first to filter and then query the matching documents.

{

- index: "columns",
- type: "mainarticle",
- body:  
{
  - query:  
{
    - has\_child:  
{
      - type: "product",
      - query:  
{
        - filtered:  
{
          - query:  
{
            - multi\_match:  
{
              - query: "printer",
              - fields:  
[
                - "Title",
                - "Description"  
]  
}  
},

          - filter:  
{
            - 
## and: [
{  
- term:  
{  
- Client3.Type: "K"  
}  
}  
]  
}  
}  
}  
}  
}  
}

}

--  
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/80196832-a157-4347-8461-f64f8adbb188%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/80196832-a157-4347-8461-f64f8adbb188%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:08am UTC](https://discuss.elastic.co/t/optimize-has-child-query-filter/19296/2 "2017-07-06T01:08:22Z")

</div>


