# Constraining search results in terms of max occurrences of the same field value

**URL:** <https://discuss.elastic.co/t/constraining-search-results-in-terms-of-max-occurrences-of-the-same-field-value/8519>\
**Category:** Elasticsearch\
**Created:** [July 26, 2012, 9:01am UTC](https://discuss.elastic.co/t/constraining-search-results-in-terms-of-max-occurrences-of-the-same-field-value/8519 "2012-07-26T09:01:34Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![T\_Vinod\_Gupta](https://avatars.discourse-cdn.com/v4/letter/t/fbc32d/32.png) [@T\_Vinod\_Gupta](https://discuss.elastic.co/u/T_Vinod_Gupta)\
**Post date:** [July 26, 2012, 9:01am UTC](https://discuss.elastic.co/t/constraining-search-results-in-terms-of-max-occurrences-of-the-same-field-value/8519/1 "2012-07-26T09:01:34Z")

</div>

hi,  
is it possible to construct a search query such that the result set doesn't  
contain more than n documents where the same field value appears. let me  
explain this better..  
lets say i have a simple index of tweets. fields are just "handle",  
"tweet\_text". now i want to search on something in the tweet\_text field.  
but in the search results, the maximum number of times a handle is repeated  
shouldn't exceed 2.

is this possible?

thanks

---

<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:18am UTC](https://discuss.elastic.co/t/constraining-search-results-in-terms-of-max-occurrences-of-the-same-field-value/8519/2 "2017-07-06T03:18:57Z")

</div>


