# Displaying top 1000 results only in elastic search

**URL:** <https://discuss.elastic.co/t/displaying-top-1000-results-only-in-elastic-search/59479>\
**Category:** Elasticsearch\
**Created:** [August 31, 2016, 11:54pm UTC](https://discuss.elastic.co/t/displaying-top-1000-results-only-in-elastic-search/59479 "2016-08-31T23:54:18Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![subbu.nv](https://avatars.discourse-cdn.com/v4/letter/s/439d5e/32.png) [@subbu.nv](https://discuss.elastic.co/u/subbu.nv)\
**Post date:** [August 31, 2016, 11:54pm UTC](https://discuss.elastic.co/t/displaying-top-1000-results-only-in-elastic-search/59479/1 "2016-08-31T23:54:18Z")

</div>

i have a simple search query, where i am searching all the documents that falls in a data range. i have more than 50K results, with in which i want to display only top 1000 results based on date. this way my query can also be faster, as the user will also be interested to see only the 1000 results max at a time.

how can i archive this? please help.

---

<div class="post-metadata">

**Author:** ![Joshua\_Rich](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/joshua_rich/32/44953_2.png) [@Joshua\_Rich](https://discuss.elastic.co/u/Joshua_Rich)\
**Post date:** [September 1, 2016, 4:47am UTC](https://discuss.elastic.co/t/displaying-top-1000-results-only-in-elastic-search/59479/2 "2016-09-01T04:47:52Z")

</div>

Can you show us the query you currently have?

---

<div class="post-metadata">

**Author:** ![subbu.nv](https://avatars.discourse-cdn.com/v4/letter/s/439d5e/32.png) [@subbu.nv](https://discuss.elastic.co/u/subbu.nv)\
**Post date:** [September 1, 2016, 5:03am UTC](https://discuss.elastic.co/t/displaying-top-1000-results-only-in-elastic-search/59479/3 "2016-09-01T05:03:56Z")

</div>

i am using the below query, and thought that it would return 1000 records (as i mentioned size:1000 in agg), but it returns all.

{  
"query" : {  
"bool" : {  
"must" : {  
"range" : {  
"filetimestamp" : {  
"from" : "2016-01-01T00:00:00.000-0800",  
"to" : "2016-08-31T17:11:37.393-0700",  
"include\_lower" : true,  
"include\_upper" : true  
}  
}  
}  
}  
},  
"fields" : "filename",  
"sort" : [ {  
"filetimestamp" : {  
"order" : "desc"  
}  
} ],  
"aggregations" : {  
"filenames" : {  
"terms" : {  
"field" : "filename",  
"size" : 1000  
}  
}  
}  
}

---

<div class="post-metadata">

**Author:** ![mainec](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/mainec/32/5557_2.png) [@mainec](https://discuss.elastic.co/u/mainec)\
**Post date:** [September 1, 2016, 9:37am UTC](https://discuss.elastic.co/t/displaying-top-1000-results-only-in-elastic-search/59479/4 "2016-09-01T09:37:17Z")

</div>

I believe you misread what size refers to here. According to

> **[Terms aggregation | Elasticsearch Guide \[8.11\] | Elastic](https://www.elastic.co/guide/en/elasticsearch/reference/current/search-aggregations-bucket-terms-aggregation.html)**

> The size parameter can be set to define how many term buckets should be returned out of the overall terms list.

I think what might help you is using the following:

> **[Sampler aggregation | Elasticsearch Guide \[8.11\] | Elastic](https://www.elastic.co/guide/en/elasticsearch/reference/current/search-aggregations-bucket-sampler-aggregation.html)**

Hope this helps,  
Isabel

---

<div class="post-metadata">

**Author:** ![1222kkk](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/1222kkk/32/23635_2.png) [@1222kkk](https://discuss.elastic.co/u/1222kkk)\
**Post date:** [September 1, 2016, 9:59am UTC](https://discuss.elastic.co/t/displaying-top-1000-results-only-in-elastic-search/59479/5 "2016-09-01T09:59:11Z")

</div>

```
{ 
  "size":1000,
  "query" : {  
      "bool" : {     
          "must" : { 
                      ...
```

---

<div class="post-metadata">

**Author:** ![subbu.nv](https://avatars.discourse-cdn.com/v4/letter/s/439d5e/32.png) [@subbu.nv](https://discuss.elastic.co/u/subbu.nv)\
**Post date:** [October 31, 2016, 7:00pm UTC](https://discuss.elastic.co/t/displaying-top-1000-results-only-in-elastic-search/59479/6 "2016-10-31T19:00:15Z")

</div>

Hi,  
thanks for the response. but i dont think this is helping. though i give 1000 in size, it is returning all the results in console.  
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 5, 2017, 10:08pm UTC](https://discuss.elastic.co/t/displaying-top-1000-results-only-in-elastic-search/59479/7 "2017-07-05T22:08:06Z")

</div>


