# How to se the max number of hits?

**URL:** <https://discuss.elastic.co/t/how-to-se-the-max-number-of-hits/12744>\
**Category:** Elasticsearch\
**Created:** [July 10, 2013, 2:57pm UTC](https://discuss.elastic.co/t/how-to-se-the-max-number-of-hits/12744 "2013-07-10T14:57:09Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![dantuff](https://avatars.discourse-cdn.com/v4/letter/d/e79b87/32.png) [@dantuff](https://discuss.elastic.co/u/dantuff)\
**Post date:** [July 10, 2013, 2:57pm UTC](https://discuss.elastic.co/t/how-to-se-the-max-number-of-hits/12744/1 "2013-07-10T14:57:09Z")

</div>

Is there a way to set the max number of hits via the Java API? I'm using  
the size parameter for itemsPerPage, but I need to cap the max hits that  
are returned.

--  
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](mailto:elasticsearch+unsubscribe@googlegroups.com).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<div class="post-metadata">

**Author:** ![spinscale](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/spinscale/32/25011_2.png) [@spinscale](https://discuss.elastic.co/u/spinscale)\
**Post date:** [July 10, 2013, 3:54pm UTC](https://discuss.elastic.co/t/how-to-se-the-max-number-of-hits/12744/2 "2013-07-10T15:54:14Z")

</div>

Hey,

sorry I cannot follow you. Using size and from parameters helps you to  
define the amount of SearchHits being returned. Of what different kind of  
max hits are you speaking? Can you provide an example maybe?

--Alex

On Wed, Jul 10, 2013 at 4:57 PM, dan [dan.tuffery@gmail.com](mailto:dan.tuffery@gmail.com) wrote:

> Is there a way to set the max number of hits via the Java API? I'm using  
> the size parameter for itemsPerPage, but I need to cap the max hits that  
> are returned.
> 
> --  
> 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](mailto:elasticsearch+unsubscribe@googlegroups.com).  
> For more options, visit [https://groups.google.com/groups/opt\_out](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](mailto:elasticsearch+unsubscribe@googlegroups.com).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<div class="post-metadata">

**Author:** ![dantuff](https://avatars.discourse-cdn.com/v4/letter/d/e79b87/32.png) [@dantuff](https://discuss.elastic.co/u/dantuff)\
**Post date:** [July 10, 2013, 4:08pm UTC](https://discuss.elastic.co/t/how-to-se-the-max-number-of-hits/12744/3 "2013-07-10T16:08:40Z")

</div>

If I do a search for "book" and there are 5000 book items in my index but I  
only want user to only be able to search over the fist 2000 hundred I need  
a way to cap the totalHits. This is different from the 'from' and 'size'  
parameters as that is what I use for pagination, i.e. the 'from' is the  
page the user is starting from, say '21' and the 'size' is the items per  
page say '20'.

On Wednesday, July 10, 2013 4:54:14 PM UTC+1, Alexander Reelsen wrote:

> Hey,
> 
> sorry I cannot follow you. Using size and from parameters helps you to  
> define the amount of SearchHits being returned. Of what different kind of  
> max hits are you speaking? Can you provide an example maybe?
> 
> --Alex
> 
> On Wed, Jul 10, 2013 at 4:57 PM, dan \<[dan.t...@gmail.com](mailto:dan.t...@gmail.com) \<javascript:\>\>wrote:
> 
> > Is there a way to set the max number of hits via the Java API? I'm using  
> > the size parameter for itemsPerPage, but I need to cap the max hits that  
> > are returned.
> > 
> > --  
> > 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 [elasticsearc...@googlegroups.com](mailto:elasticsearc...@googlegroups.com) \<javascript:\>.  
> > For more options, visit [https://groups.google.com/groups/opt\_out](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](mailto:elasticsearch+unsubscribe@googlegroups.com).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<div class="post-metadata">

**Author:** ![dantuff](https://avatars.discourse-cdn.com/v4/letter/d/e79b87/32.png) [@dantuff](https://discuss.elastic.co/u/dantuff)\
**Post date:** [July 10, 2013, 4:09pm UTC](https://discuss.elastic.co/t/how-to-se-the-max-number-of-hits/12744/4 "2013-07-10T16:09:59Z")

</div>

If I do a search for "book" and there are 5000 book items in my index but I  
only want user to only be able to search over the fist 2000 I need a way to  
cap the 'totalHits'. This is different from the 'from' and 'size'  
parameters as that is what I use for pagination, i.e. the 'from' is the  
page the user is starting from, say '21' and the 'size' is the items per  
page say '20'.

On Wednesday, July 10, 2013 4:54:14 PM UTC+1, Alexander Reelsen wrote:

> Hey,
> 
> sorry I cannot follow you. Using size and from parameters helps you to  
> define the amount of SearchHits being returned. Of what different kind of  
> max hits are you speaking? Can you provide an example maybe?
> 
> --Alex
> 
> On Wed, Jul 10, 2013 at 4:57 PM, dan \<[dan.t...@gmail.com](mailto:dan.t...@gmail.com) \<javascript:\>\>wrote:
> 
> > Is there a way to set the max number of hits via the Java API? I'm using  
> > the size parameter for itemsPerPage, but I need to cap the max hits that  
> > are returned.
> > 
> > --  
> > 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 [elasticsearc...@googlegroups.com](mailto:elasticsearc...@googlegroups.com) \<javascript:\>.  
> > For more options, visit [https://groups.google.com/groups/opt\_out](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](mailto:elasticsearch+unsubscribe@googlegroups.com).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<div class="post-metadata">

**Author:** ![spinscale](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/spinscale/32/25011_2.png) [@spinscale](https://discuss.elastic.co/u/spinscale)\
**Post date:** [July 10, 2013, 4:15pm UTC](https://discuss.elastic.co/t/how-to-se-the-max-number-of-hits/12744/5 "2013-07-10T16:15:16Z")

</div>

Hey,

this is an application issue and should be solved there as well. Simply  
exchange the values from the JSON response if you need to and do not allow  
to page that far (which should be easy as this is user input).  
There is now way to tell elasticsearch to hide found hits... (doesnt make  
sense for a search engine to hide results which are clearly hits).

--Alex

On Wed, Jul 10, 2013 at 6:09 PM, dan [dan.tuffery@gmail.com](mailto:dan.tuffery@gmail.com) wrote:

> If I do a search for "book" and there are 5000 book items in my index but  
> I only want user to only be able to search over the fist 2000 I need a way  
> to cap the 'totalHits'. This is different from the 'from' and 'size'  
> parameters as that is what I use for pagination, i.e. the 'from' is the  
> page the user is starting from, say '21' and the 'size' is the items per  
> page say '20'.
> 
> On Wednesday, July 10, 2013 4:54:14 PM UTC+1, Alexander Reelsen wrote:
> 
> > Hey,
> > 
> > sorry I cannot follow you. Using size and from parameters helps you to  
> > define the amount of SearchHits being returned. Of what different kind of  
> > max hits are you speaking? Can you provide an example maybe?
> > 
> > --Alex
> > 
> > On Wed, Jul 10, 2013 at 4:57 PM, dan [dan.t...@gmail.com](mailto:dan.t...@gmail.com) wrote:
> > 
> > > Is there a way to set the max number of hits via the Java API? I'm using  
> > > the size parameter for itemsPerPage, but I need to cap the max hits that  
> > > are returned.
> > > 
> > > --  
> > > 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 elasticsearc...@\*\*[googlegroups.com](http://googlegroups.com).
> > > 
> > > For more options, visit [https://groups.google.com/\*\*groups/opt\_out](https://groups.google.com/**groups/opt_out)[https://groups.google.com/groups/opt\_out](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](mailto:elasticsearch+unsubscribe@googlegroups.com).  
> > For more options, visit [https://groups.google.com/groups/opt\_out](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](mailto:elasticsearch+unsubscribe@googlegroups.com).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<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, 2:27am UTC](https://discuss.elastic.co/t/how-to-se-the-max-number-of-hits/12744/6 "2017-07-06T02:27:08Z")

</div>


