Filtering Results from multiple indices


(jacorob) #1

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


(Karussell) #2

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?
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/indices-types.html
)

On 31 Mrz., 21:41, Bob 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


(Shay Banon) #3

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?
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/indices-types.html
)

On 31 Mrz., 21:41, Bob 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


(system) #4