Possible to get top N results each from 2 separate indexes in single query?

I have the same query that I want to run against 2 separate indexes. I want
to get the top N results from each index. Right now I'm running as 2
separate queries. I know I can specify multiple indexes for a query, but
that's not quite what I mean.

So if I want to get the top 10 results from each index, running 2 separate
queries I want to get 20 results back. Is it possible to combine the
queries into a single one and still get the top 10 results from each index?
I don't want the top 10 results from both indexes combined, I need to top
10 results from each index using the same query for each.

I assume I can use a multi-query to issue both queries at the same time,
which should be more efficient than running the queries sequentially. Just
wanted to see if anyone had any suggestions for running the same query
against both indexes and getting the top N from each. Maybe that would be
no faster than the multi-query anyway.

Thanks!

  • Craig

--
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.
For more options, visit https://groups.google.com/groups/opt_out.

Hi,

as you already pointed out, you can use multi-query and I think this can be
the best option for you. Just go with it.

I do not know your specific use case (so what I say now might not apply to
you) but you might also consider running a single query against two indices
and use query_and_fetch [1] query type, this will return you 10 results
from each index shard (in case your indices have only a single shard then
this would result into 20 search hits for two indices) then you could use
_index field value to identify source index on the client.

Regards,
Lukas

[1] Elasticsearch Platform — Find real-time answers at scale | Elastic

On Thu, Apr 4, 2013 at 6:44 AM, Craig Brown cbrown@youwho.com wrote:

I have the same query that I want to run against 2 separate indexes. I
want to get the top N results from each index. Right now I'm running as 2
separate queries. I know I can specify multiple indexes for a query, but
that's not quite what I mean.

So if I want to get the top 10 results from each index, running 2 separate
queries I want to get 20 results back. Is it possible to combine the
queries into a single one and still get the top 10 results from each index?
I don't want the top 10 results from both indexes combined, I need to top
10 results from each index using the same query for each.

I assume I can use a multi-query to issue both queries at the same time,
which should be more efficient than running the queries sequentially. Just
wanted to see if anyone had any suggestions for running the same query
against both indexes and getting the top N from each. Maybe that would be
no faster than the multi-query anyway.

Thanks!

  • Craig

--
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.
For more options, visit https://groups.google.com/groups/opt_out.

--
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.
For more options, visit https://groups.google.com/groups/opt_out.

Thanks Lukas! I'll give both a shot. BTW, love BigDesk! Thanks for
contributing!

  • Craig

On Wed, Apr 3, 2013 at 11:52 PM, Lukáš Vlček lukas.vlcek@gmail.com wrote:

Hi,

as you already pointed out, you can use multi-query and I think this can
be the best option for you. Just go with it.

I do not know your specific use case (so what I say now might not apply to
you) but you might also consider running a single query against two indices
and use query_and_fetch [1] query type, this will return you 10 results
from each index shard (in case your indices have only a single shard then
this would result into 20 search hits for two indices) then you could use
_index field value to identify source index on the client.

Regards,
Lukas

[1] Elasticsearch Platform — Find real-time answers at scale | Elastic

On Thu, Apr 4, 2013 at 6:44 AM, Craig Brown cbrown@youwho.com wrote:

I have the same query that I want to run against 2 separate indexes. I
want to get the top N results from each index. Right now I'm running as 2
separate queries. I know I can specify multiple indexes for a query, but
that's not quite what I mean.

So if I want to get the top 10 results from each index, running 2
separate queries I want to get 20 results back. Is it possible to combine
the queries into a single one and still get the top 10 results from each
index? I don't want the top 10 results from both indexes combined, I need
to top 10 results from each index using the same query for each.

I assume I can use a multi-query to issue both queries at the same time,
which should be more efficient than running the queries sequentially. Just
wanted to see if anyone had any suggestions for running the same query
against both indexes and getting the top N from each. Maybe that would be
no faster than the multi-query anyway.

Thanks!

  • Craig

--
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.
For more options, visit https://groups.google.com/groups/opt_out.

--
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.
For more options, visit https://groups.google.com/groups/opt_out.

--

CRAIG BROWN
Search Architect
youwho, Inc.

www.youwho.com

M: 801.680.7300

--
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.
For more options, visit https://groups.google.com/groups/opt_out.

thanks!

On Thu, Apr 4, 2013 at 5:50 PM, Craig Brown cbrown@youwho.com wrote:

Thanks Lukas! I'll give both a shot. BTW, love BigDesk! Thanks for
contributing!

  • Craig

On Wed, Apr 3, 2013 at 11:52 PM, Lukáš Vlček lukas.vlcek@gmail.comwrote:

Hi,

as you already pointed out, you can use multi-query and I think this can
be the best option for you. Just go with it.

I do not know your specific use case (so what I say now might not apply
to you) but you might also consider running a single query against two
indices and use query_and_fetch [1] query type, this will return you 10
results from each index shard (in case your indices have only a single
shard then this would result into 20 search hits for two indices) then you
could use _index field value to identify source index on the client.

Regards,
Lukas

[1] Elasticsearch Platform — Find real-time answers at scale | Elastic

On Thu, Apr 4, 2013 at 6:44 AM, Craig Brown cbrown@youwho.com wrote:

I have the same query that I want to run against 2 separate indexes. I
want to get the top N results from each index. Right now I'm running as 2
separate queries. I know I can specify multiple indexes for a query, but
that's not quite what I mean.

So if I want to get the top 10 results from each index, running 2
separate queries I want to get 20 results back. Is it possible to combine
the queries into a single one and still get the top 10 results from each
index? I don't want the top 10 results from both indexes combined, I need
to top 10 results from each index using the same query for each.

I assume I can use a multi-query to issue both queries at the same time,
which should be more efficient than running the queries sequentially. Just
wanted to see if anyone had any suggestions for running the same query
against both indexes and getting the top N from each. Maybe that would be
no faster than the multi-query anyway.

Thanks!

  • Craig

--
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.
For more options, visit https://groups.google.com/groups/opt_out.

--
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.
For more options, visit https://groups.google.com/groups/opt_out.

--

CRAIG BROWN
Search Architect
youwho, Inc.

www.youwho.com

M: 801.680.7300

--
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.
For more options, visit https://groups.google.com/groups/opt_out.

--
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.
For more options, visit https://groups.google.com/groups/opt_out.