# Is there a way to get n hits from each of my indices in one shoot?

**URL:** https://discuss.elastic.co/t/is-there-a-way-to-get-n-hits-from-each-of-my-indices-in-one-shoot/6959
**Category:** Elasticsearch
**Created:** [March 9, 2012, 2:19pm UTC](https://discuss.elastic.co/t/is-there-a-way-to-get-n-hits-from-each-of-my-indices-in-one-shoot/6959 "2012-03-09T14:19:13Z")
**Posts on this page:** 7
**Page:** 1

<div class="post-metadata">

### Author: ![Mauricio\_Alarcon](https://avatars.discourse-cdn.com/v4/letter/m/cab0a1/32.png) [@Mauricio\_Alarcon](https://discuss.elastic.co/u/Mauricio_Alarcon)
#### Post date: [March 9, 2012, 2:19pm UTC](https://discuss.elastic.co/t/is-there-a-way-to-get-n-hits-from-each-of-my-indices-in-one-shoot/6959/1 "2012-03-09T14:19:13Z")

</div>

Hi Guys,

I know ES supports cross index searches and we're in love with it, but is  
there a way to tell ES to return at most "n" hits per index in just one  
shoot? or do I need to do a search per index?

Our problem is that some documents got higher score, eclipsing the hits  
from its neighborhood which are also important for this use case.

Cheers

---

<div class="post-metadata">

### Author: ![Nick\_Dimiduk](https://avatars.discourse-cdn.com/v4/letter/n/c77e96/32.png) [@Nick\_Dimiduk](https://discuss.elastic.co/u/Nick_Dimiduk)
#### Post date: [March 9, 2012, 6:08pm UTC](https://discuss.elastic.co/t/is-there-a-way-to-get-n-hits-from-each-of-my-indices-in-one-shoot/6959/2 "2012-03-09T18:08:23Z")

</div>

I believe the limit filter does what you require.

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

-n

On Fri, Mar 9, 2012 at 6:19 AM, maverick [mauricio.alarcon@gmail.com](mailto:mauricio.alarcon@gmail.com) wrote:

> Hi Guys,
> 
> I know ES supports cross index searches and we're in love with it, but is  
> there a way to tell ES to return at most "n" hits per index in just one  
> shoot? or do I need to do a search per index?
> 
> Our problem is that some documents got higher score, eclipsing the hits  
> from its neighborhood which are also important for this use case.
> 
> Cheers

---

<div class="post-metadata">

### Author: ![egaumer](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/egaumer/32/2365_2.png) [@egaumer](https://discuss.elastic.co/u/egaumer)
#### Post date: [March 9, 2012, 6:42pm UTC](https://discuss.elastic.co/t/is-there-a-way-to-get-n-hits-from-each-of-my-indices-in-one-shoot/6959/3 "2012-03-09T18:42:15Z")

</div>

The limit filter works at a shard level. Shards are essentially index  
partitions so a shard does not represent an entire index.

What you want is more classically known as "field collapsing" which is the  
ability to collapse search results based on a unique key/field (a domain  
name for instance).

There's been many requests for this feature and I think 0.19 actually  
provides a solution called "Multi Search". It allows you submit a group of  
queries as a single request and returns an array of "grouped" matches. With  
this, you could construct a query against each index and limit the number  
of results to N.

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

This should meet the requirement of field collapsing providing you have a  
relatively small number of groups. I assume this is the case since each is  
currently represented by its own index.

Of course you could do this manually at the cost of several round trip  
requests and having to federate results. With multi-search, the engine  
handles this for you.

-Eric

On Friday, March 9, 2012 1:08:23 PM UTC-5, Nick Dimiduk wrote:

> I believe the limit filter does what you require.  
> [Elasticsearch Platform — Find real-time answers at scale | Elastic](http://www.elasticsearch.org/guide/reference/query-dsl/limit-filter.html)
> 
> -n
> 
> On Fri, Mar 9, 2012 at 6:19 AM, maverick [mauricio.alarcon@gmail.com](mailto:mauricio.alarcon@gmail.com)wrote:
> 
> > Hi Guys,
> > 
> > I know ES supports cross index searches and we're in love with it, but is  
> > there a way to tell ES to return at most "n" hits per index in just one  
> > shoot? or do I need to do a search per index?
> > 
> > Our problem is that some documents got higher score, eclipsing the hits  
> > from its neighborhood which are also important for this use case.
> > 
> > Cheers

---

<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: [March 9, 2012, 7:13pm UTC](https://discuss.elastic.co/t/is-there-a-way-to-get-n-hits-from-each-of-my-indices-in-one-shoot/6959/4 "2012-03-09T19:13:14Z")

</div>

Yea, multi search is the way to go for this.

On Friday, March 9, 2012 at 8:42 PM, egaumer wrote:

> The limit filter works at a shard level. Shards are essentially index partitions so a shard does not represent an entire index.
> 
> What you want is more classically known as "field collapsing" which is the ability to collapse search results based on a unique key/field (a domain name for instance).
> 
> There's been many requests for this feature and I think 0.19 actually provides a solution called "Multi Search". It allows you submit a group of queries as a single request and returns an array of "grouped" matches. With this, you could construct a query against each index and limit the number of results to N.
> 
> [Elasticsearch Platform — Find real-time answers at scale | Elastic](http://www.elasticsearch.org/guide/reference/api/multi-search.html)
> 
> This should meet the requirement of field collapsing providing you have a relatively small number of groups. I assume this is the case since each is currently represented by its own index.
> 
> Of course you could do this manually at the cost of several round trip requests and having to federate results. With multi-search, the engine handles this for you.
> 
> -Eric
> 
> On Friday, March 9, 2012 1:08:23 PM UTC-5, Nick Dimiduk wrote:
> 
> > I believe the limit filter does what you require. [Elasticsearch Platform — Find real-time answers at scale | Elastic](http://www.elasticsearch.org/guide/reference/query-dsl/limit-filter.html)
> > 
> > -n
> > 
> > On Fri, Mar 9, 2012 at 6:19 AM, maverick \<[mauricio.alarcon@gmail.com](mailto:mauricio.alarcon@gmail.com) ([mailto:mauricio.alarcon@gmail.com](mailto:mauricio.alarcon@gmail.com))\> wrote:
> > 
> > > Hi Guys,
> > > 
> > > I know ES supports cross index searches and we're in love with it, but is there a way to tell ES to return at most "n" hits per index in just one shoot? or do I need to do a search per index?
> > > 
> > > Our problem is that some documents got higher score, eclipsing the hits from its neighborhood which are also important for this use case.
> > > 
> > > Cheers

---

<div class="post-metadata">

### Author: ![Mauricio\_Alarcon](https://avatars.discourse-cdn.com/v4/letter/m/cab0a1/32.png) [@Mauricio\_Alarcon](https://discuss.elastic.co/u/Mauricio_Alarcon)
#### Post date: [March 9, 2012, 7:22pm UTC](https://discuss.elastic.co/t/is-there-a-way-to-get-n-hits-from-each-of-my-indices-in-one-shoot/6959/5 "2012-03-09T19:22:54Z")

</div>

This is just perfect!, Thank you Eric

On Friday, March 9, 2012 1:42:15 PM UTC-5, egaumer wrote:

> The limit filter works at a shard level. Shards are essentially index  
> partitions so a shard does not represent an entire index.
> 
> What you want is more classically known as "field collapsing" which is the  
> ability to collapse search results based on a unique key/field (a domain  
> name for instance).
> 
> There's been many requests for this feature and I think 0.19 actually  
> provides a solution called "Multi Search". It allows you submit a group of  
> queries as a single request and returns an array of "grouped" matches. With  
> this, you could construct a query against each index and limit the number  
> of results to N.
> 
> [Elasticsearch Platform — Find real-time answers at scale | Elastic](http://www.elasticsearch.org/guide/reference/api/multi-search.html)
> 
> This should meet the requirement of field collapsing providing you have a  
> relatively small number of groups. I assume this is the case since each is  
> currently represented by its own index.
> 
> Of course you could do this manually at the cost of several round trip  
> requests and having to federate results. With multi-search, the engine  
> handles this for you.
> 
> -Eric
> 
> On Friday, March 9, 2012 1:08:23 PM UTC-5, Nick Dimiduk wrote:
> 
> > I believe the limit filter does what you require.  
> > [Elasticsearch Platform — Find real-time answers at scale | Elastic](http://www.elasticsearch.org/guide/reference/query-dsl/limit-filter.html)
> > 
> > -n
> > 
> > On Fri, Mar 9, 2012 at 6:19 AM, maverick [mauricio.alarcon@gmail.com](mailto:mauricio.alarcon@gmail.com)wrote:
> > 
> > > Hi Guys,
> > > 
> > > I know ES supports cross index searches and we're in love with it, but  
> > > is there a way to tell ES to return at most "n" hits per index in just one  
> > > shoot? or do I need to do a search per index?
> > > 
> > > Our problem is that some documents got higher score, eclipsing the hits  
> > > from its neighborhood which are also important for this use case.
> > > 
> > > Cheers

---

<div class="post-metadata">

### Author: ![Mauricio\_Alarcon](https://avatars.discourse-cdn.com/v4/letter/m/cab0a1/32.png) [@Mauricio\_Alarcon](https://discuss.elastic.co/u/Mauricio_Alarcon)
#### Post date: [March 9, 2012, 7:25pm UTC](https://discuss.elastic.co/t/is-there-a-way-to-get-n-hits-from-each-of-my-indices-in-one-shoot/6959/6 "2012-03-09T19:25:39Z")

</div>

awesome, thanks Shay, I'm still running 0.18 so an update is needed. But  
I'll go this way

On Friday, March 9, 2012 2:13:14 PM UTC-5, kimchy wrote:

> Yea, multi search is the way to go for this.
> 
> On Friday, March 9, 2012 at 8:42 PM, egaumer wrote:
> 
> The limit filter works at a shard level. Shards are essentially index  
> partitions so a shard does not represent an entire index.
> 
> What you want is more classically known as "field collapsing" which is the  
> ability to collapse search results based on a unique key/field (a domain  
> name for instance).
> 
> There's been many requests for this feature and I think 0.19 actually  
> provides a solution called "Multi Search". It allows you submit a group of  
> queries as a single request and returns an array of "grouped" matches. With  
> this, you could construct a query against each index and limit the number  
> of results to N.
> 
> [Elasticsearch Platform — Find real-time answers at scale | Elastic](http://www.elasticsearch.org/guide/reference/api/multi-search.html)
> 
> This should meet the requirement of field collapsing providing you have a  
> relatively small number of groups. I assume this is the case since each is  
> currently represented by its own index.
> 
> Of course you could do this manually at the cost of several round trip  
> requests and having to federate results. With multi-search, the engine  
> handles this for you.
> 
> -Eric
> 
> On Friday, March 9, 2012 1:08:23 PM UTC-5, Nick Dimiduk wrote:
> 
> I believe the limit filter does what you require.  
> [Elasticsearch Platform — Find real-time answers at scale | Elastic](http://www.elasticsearch.org/guide/reference/query-dsl/limit-filter.html)
> 
> -n
> 
> On Fri, Mar 9, 2012 at 6:19 AM, maverick [mauricio.alarcon@gmail.com](mailto:mauricio.alarcon@gmail.com)wrote:
> 
> Hi Guys,
> 
> I know ES supports cross index searches and we're in love with it, but is  
> there a way to tell ES to return at most "n" hits per index in just one  
> shoot? or do I need to do a search per index?
> 
> Our problem is that some documents got higher score, eclipsing the hits  
> from its neighborhood which are also important for this use case.
> 
> Cheers

---

<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, 3:36am UTC](https://discuss.elastic.co/t/is-there-a-way-to-get-n-hits-from-each-of-my-indices-in-one-shoot/6959/7 "2017-07-06T03:36:29Z")

</div>


