# Global search, different filters per index in one query

**URL:** <https://discuss.elastic.co/t/global-search-different-filters-per-index-in-one-query/11451>\
**Category:** Elasticsearch\
**Created:** [April 4, 2013, 12:55pm UTC](https://discuss.elastic.co/t/global-search-different-filters-per-index-in-one-query/11451 "2013-04-04T12:55:45Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Antek\_Piechnik](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/antek_piechnik/32/1989_2.png) [@Antek\_Piechnik](https://discuss.elastic.co/u/Antek_Piechnik)\
**Post date:** [April 4, 2013, 12:55pm UTC](https://discuss.elastic.co/t/global-search-different-filters-per-index-in-one-query/11451/1 "2013-04-04T12:55:45Z")

</div>

Hi,

Due to accessibility levels in my organization, when performing a global  
search across all indices within Elasticsearch, I need to apply different  
filters for different indices and then combine this into one results pool.  
I am wondering whether that is possible in one huge query, so that I don't  
perform separate queries per index?

To clarify -- let's say I have a Post and Comment models. When fetching  
results, I should only match Comments by commenter\_id whereas Post by  
poster\_id. I have separate indices for posts and comments. Now, I'd just  
perform two queries, filtering separately and then combine results. But  
that's slow. Does anyone have any ideas?

Thanks!  
Antek

--  
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:** ![mattweber](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/mattweber/32/44940_2.png) [@mattweber](https://discuss.elastic.co/u/mattweber)\
**Post date:** [April 4, 2013, 7:01pm UTC](https://discuss.elastic.co/t/global-search-different-filters-per-index-in-one-query/11451/2 "2013-04-04T19:01:11Z")

</div>

Wrap an indices query in a query filter....

> **[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.

On Thursday, April 4, 2013, Antek Piechnik wrote:

> Hi,
> 
> Due to accessibility levels in my organization, when performing a global  
> search across all indices within Elasticsearch, I need to apply different  
> filters for different indices and then combine this into one results pool.  
> I am wondering whether that is possible in one huge query, so that I don't  
> perform separate queries per index?
> 
> To clarify -- let's say I have a Post and Comment models. When fetching  
> results, I should only match Comments by commenter\_id whereas Post by  
> poster\_id. I have separate indices for posts and comments. Now, I'd just  
> perform two queries, filtering separately and then combine results. But  
> that's slow. Does anyone have any ideas?
> 
> Thanks!  
> Antek
> 
> --  
> 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) \<javascript:\_e({},  
> 'cvml', 'elasticsearch%2Bunsubscribe@googlegroups.com');\>.  
> For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

--  
Thanks,  
Matt Weber

--  
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:** ![Antek\_Piechnik](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/antek_piechnik/32/1989_2.png) [@Antek\_Piechnik](https://discuss.elastic.co/u/Antek_Piechnik)\
**Post date:** [April 5, 2013, 9:29am UTC](https://discuss.elastic.co/t/global-search-different-filters-per-index-in-one-query/11451/3 "2013-04-05T09:29:33Z")

</div>

Hi,

Thanks! I actually looked at the indices query but it only gives me one  
alternative. If I have more models, is multi\_search my only option ?

Regards,  
Antek

On Thursday, April 4, 2013 9:01:11 PM UTC+2, Matt Weber wrote:

> Wrap an indices query in a query filter....
> 
> [Elasticsearch Platform — Find real-time answers at scale | Elastic](http://www.elasticsearch.org/guide/reference/query-dsl/indices-query/)
> 
> On Thursday, April 4, 2013, Antek Piechnik wrote:
> 
> > Hi,
> > 
> > Due to accessibility levels in my organization, when performing a global  
> > search across all indices within Elasticsearch, I need to apply different  
> > filters for different indices and then combine this into one results pool.  
> > I am wondering whether that is possible in one huge query, so that I  
> > don't perform separate queries per index?
> > 
> > To clarify -- let's say I have a Post and Comment models. When fetching  
> > results, I should only match Comments by commenter\_id whereas Post by  
> > poster\_id. I have separate indices for posts and comments. Now, I'd just  
> > perform two queries, filtering separately and then combine results. But  
> > that's slow. Does anyone have any ideas?
> > 
> > Thanks!  
> > Antek
> > 
> > --  
> > 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).
> 
> --  
> Thanks,  
> Matt Weber

--  
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:** ![Igor\_Motov](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/igor_motov/32/45193_2.png) [@Igor\_Motov](https://discuss.elastic.co/u/Igor_Motov)\
**Post date:** [April 5, 2013, 1:35pm UTC](https://discuss.elastic.co/t/global-search-different-filters-per-index-in-one-query/11451/4 "2013-04-05T13:35:23Z")

</div>

You can combine several indices queries together using bool query

On Friday, April 5, 2013 5:29:33 AM UTC-4, Antek Piechnik wrote:

> Hi,
> 
> Thanks! I actually looked at the indices query but it only gives me one  
> alternative. If I have more models, is multi\_search my only option ?
> 
> Regards,  
> Antek
> 
> On Thursday, April 4, 2013 9:01:11 PM UTC+2, Matt Weber wrote:
> 
> > Wrap an indices query in a query filter....
> > 
> > [Elasticsearch Platform — Find real-time answers at scale | Elastic](http://www.elasticsearch.org/guide/reference/query-dsl/indices-query/)
> > 
> > On Thursday, April 4, 2013, Antek Piechnik wrote:
> > 
> > > Hi,
> > > 
> > > Due to accessibility levels in my organization, when performing a global  
> > > search across all indices within Elasticsearch, I need to apply different  
> > > filters for different indices and then combine this into one results pool.  
> > > I am wondering whether that is possible in one huge query, so that I  
> > > don't perform separate queries per index?
> > > 
> > > To clarify -- let's say I have a Post and Comment models. When fetching  
> > > results, I should only match Comments by commenter\_id whereas Post by  
> > > poster\_id. I have separate indices for posts and comments. Now, I'd just  
> > > perform two queries, filtering separately and then combine results. But  
> > > that's slow. Does anyone have any ideas?
> > > 
> > > Thanks!  
> > > Antek
> > > 
> > > --  
> > > 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).
> > 
> > --  
> > Thanks,  
> > Matt Weber

--  
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:42am UTC](https://discuss.elastic.co/t/global-search-different-filters-per-index-in-one-query/11451/5 "2017-07-06T02:42:38Z")

</div>


