# Filtering Results from multiple indices

**URL:** <https://discuss.elastic.co/t/filtering-results-from-multiple-indices/4176>\
**Category:** Elasticsearch\
**Created:** [March 31, 2011, 7:41pm UTC](https://discuss.elastic.co/t/filtering-results-from-multiple-indices/4176 "2011-03-31T19:41:54Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![jacorob](https://avatars.discourse-cdn.com/v4/letter/j/dec6dc/32.png) [@jacorob](https://discuss.elastic.co/u/jacorob)\
**Post date:** [March 31, 2011, 7:41pm UTC](https://discuss.elastic.co/t/filtering-results-from-multiple-indices/4176/1 "2011-03-31T19:41:54Z")

</div>

I have 2 indices. The first is my committed index, the second is a  
'working' index. Some of the documents in the working index could be  
updates to documents that already exist in the committed index (a  
particular document will have the same "\_id" in both indices).

When the user performs a search I want to search both indices and then  
combine the results such that if a document exists in both the working  
and committed index only the working one is returned.

Is this possible in a single search without requiring any post-  
processing? I'd like to avoid the post-processing to avoid headaches  
with pagination. I'm a newb at ES so am just learning how to apply the  
various things.

Any hints/tips appreciated.

Thanks,  
Bob

---

<div class="post-metadata">

**Author:** ![Karussell1](https://avatars.discourse-cdn.com/v4/letter/k/50afbb/32.png) [@Karussell1](https://discuss.elastic.co/u/Karussell1)\
**Post date:** [March 31, 2011, 10:18pm UTC](https://discuss.elastic.co/t/filtering-results-from-multiple-indices/4176/2 "2011-03-31T22:18:56Z")

</div>

I'm not sure if this only applies to shards or to different indices  
too. But try this:

curl - XGET '[http://localhost:9200/index1,index2/yourIndexType/\_search](http://localhost:9200/index1,index2/yourIndexType/_search)?  
q=tag:wow'

and see if this works.

Regards,  
Peter.

(  
[http://elasticsearch.karmi.cz/guide/reference/api/search/search-type.html](http://elasticsearch.karmi.cz/guide/reference/api/search/search-type.html)  
[http://elasticsearch.karmi.cz/guide/reference/api/search/indices-types.html](http://elasticsearch.karmi.cz/guide/reference/api/search/indices-types.html)  
)

On 31 Mrz., 21:41, Bob [jaco...@gmail.com](mailto:jaco...@gmail.com) wrote:

> I have 2 indices. The first is my committed index, the second is a  
> 'working' index. Some of the documents in the working index could be  
> updates to documents that already exist in the committed index (a  
> particular document will have the same "\_id" in both indices).
> 
> When the user performs a search I want to search both indices and then  
> combine the results such that if a document exists in both the working  
> and committed index only the working one is returned.
> 
> Is this possible in a single search without requiring any post-  
> processing? I'd like to avoid the post-processing to avoid headaches  
> with pagination. I'm a newb at ES so am just learning how to apply the  
> various things.
> 
> Any hints/tips appreciated.
> 
> Thanks,  
> Bob

---

<div class="post-metadata">

**Author:** ![kimchy](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/kimchy/32/44952_2.png) [@kimchy](https://discuss.elastic.co/u/kimchy)\
**Post date:** [April 1, 2011, 1:23am UTC](https://discuss.elastic.co/t/filtering-results-from-multiple-indices/4176/3 "2011-04-01T01:23:01Z")

</div>

To answer the original question, its not possible to say override results from one index to another. When searching on two indices (as Peter suggested), it will simply return the results from both indices, and you will get "duplicates". You do get the index the result came from back, so possibly you can filter duplicates out.  
On Friday, April 1, 2011 at 12:18 AM, Karussell wrote:

> I'm not sure if this only applies to shards or to different indices  
> too. But try this:
> 
> curl - XGET '[http://localhost:9200/index1,index2/yourIndexType/\_search](http://localhost:9200/index1,index2/yourIndexType/_search)?  
> q=tag:wow'
> 
> and see if this works.
> 
> Regards,  
> Peter.
> 
> (  
> [http://elasticsearch.karmi.cz/guide/reference/api/search/search-type.html](http://elasticsearch.karmi.cz/guide/reference/api/search/search-type.html)  
> [http://elasticsearch.karmi.cz/guide/reference/api/search/indices-types.html](http://elasticsearch.karmi.cz/guide/reference/api/search/indices-types.html)  
> )
> 
> On 31 Mrz., 21:41, Bob [jaco...@gmail.com](mailto:jaco...@gmail.com) wrote:
> 
> > I have 2 indices. The first is my committed index, the second is a  
> > 'working' index. Some of the documents in the working index could be  
> > updates to documents that already exist in the committed index (a  
> > particular document will have the same "\_id" in both indices).
> > 
> > When the user performs a search I want to search both indices and then  
> > combine the results such that if a document exists in both the working  
> > and committed index only the working one is returned.
> > 
> > Is this possible in a single search without requiring any post-  
> > processing? I'd like to avoid the post-processing to avoid headaches  
> > with pagination. I'm a newb at ES so am just learning how to apply the  
> > various things.
> > 
> > Any hints/tips appreciated.
> > 
> > Thanks,  
> > Bob

---

<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, 4:08am UTC](https://discuss.elastic.co/t/filtering-results-from-multiple-indices/4176/4 "2017-07-06T04:08:59Z")

</div>


