UNION-style search requests?


(Andrew Regan) #1

Is it possible to perform multiple, nested search queries (as per
BoolQueryBuilder), each nested query run against a potentially different set
of indices? Like a UNION in SQL: "return all hits where property=X in
(indexA,indexB) OR property=Y in (indexA,indexC)".

This used to be possible with Compass, but indices are specified at the
request- rather than the query level in ElasticSearch. I'd have to run each
search clause individually and UNION them up myself, which feels like a bad
idea.

Is there a better way to do this using ES?

(I should probably add that, though my indices represent different data
domains - so I can't replace them with one index and multiple types (unless
you disagree?) - they do have common properties so that they can be searched
together.)


(Shay Banon) #2

You can't do that in elasticsearch, but, we can introduce a new "index"
element in the query DSL, that will act as match_all if not executing on the
listed indices, and use the internal query if it does.

On Wed, Oct 19, 2011 at 11:07 AM, Andrew Regan aregan@gmail.com wrote:

Is it possible to perform multiple, nested search queries (as per
BoolQueryBuilder), each nested query run against a potentially different set
of indices? Like a UNION in SQL: "return all hits where property=X in
(indexA,indexB) OR property=Y in (indexA,indexC)".

This used to be possible with Compass, but indices are specified at the
request- rather than the query level in ElasticSearch. I'd have to run each
search clause individually and UNION them up myself, which feels like a bad
idea.

Is there a better way to do this using ES?

(I should probably add that, though my indices represent different data
domains - so I can't replace them with one index and multiple types (unless
you disagree?) - they do have common properties so that they can be searched
together.)


(Andrew Regan) #3

Thanks, Shay. Re, the 'we', is that something I can do myself, or would it
need a new plugin, perhaps?


(Shay Banon) #4

First you can open an issue :). It should be a built in query in
elasticsearch, so it can either be the royal we, and I can implement it
(should be simple), or the "commons" we, where I can help you implement it
:slight_smile:

On Thu, Oct 20, 2011 at 6:25 PM, Andrew Regan aregan@gmail.com wrote:

Thanks, Shay. Re, the 'we', is that something I can do myself, or would it
need a new plugin, perhaps?


(Andrew Regan) #5

OK, great. Have raised
https://github.com/elasticsearch/elasticsearch/issues/1416. Happy to help,
and to test, though not an expert on the ES internals.


(system) #6