# Elasticsearch Result Size

**URL:** <https://discuss.elastic.co/t/elasticsearch-result-size/26180>\
**Category:** Elasticsearch\
**Created:** [July 23, 2015, 5:52pm UTC](https://discuss.elastic.co/t/elasticsearch-result-size/26180 "2015-07-23T17:52:04Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Sivaprakash\_Shanmuga](https://avatars.discourse-cdn.com/v4/letter/s/ecae2f/32.png) [@Sivaprakash\_Shanmuga](https://discuss.elastic.co/u/Sivaprakash_Shanmuga)\
**Post date:** [July 23, 2015, 5:52pm UTC](https://discuss.elastic.co/t/elasticsearch-result-size/26180/1 "2015-07-23T17:52:04Z")

</div>

Hi

I'm using Python Library to integrate with Elasticsearch

> es = Elasticsearch([{'host': 'localhost', 'port': 9200}])  
> res = es.search(index="college", doc\_type='people', body=doc)

It returns only 10 records where as I have 30K+ matching records

> es = Elasticsearch([{'host': 'localhost', 'port': 9200}])  
> res = es.search(index="college", doc\_type='people', body=doc, size = 30450)

This retrieves all records. But I want to retrieve all the matching records without specifying size parameter (I might know it upfront). How to get it?

---

<div class="post-metadata">

**Author:** ![pemontto](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/pemontto/32/3908_2.png) [@pemontto](https://discuss.elastic.co/u/pemontto)\
**Post date:** [July 23, 2015, 10:39pm UTC](https://discuss.elastic.co/t/elasticsearch-result-size/26180/2 "2015-07-23T22:39:45Z")

</div>

You want to do a [scan and scroll](https://www.elastic.co/guide/en/elasticsearch/guide/current/scan-scroll.html) search. I've just had to do the same thing in python, it might look something like this for you

```
es = Elasticsearch([{'host': 'localhost', 'port': 9200}])
res = es.search(index="college", doc_type='people', body=doc, scroll='60s', search_type='scan')

results = []
scroll_size = res['hits']['total']

while (scroll_size > 0):
    try:
        scroll_id = res['_scroll_id']
        res = es.scroll(scroll_id=scroll_id, scroll='60s')
        results += res['hits']['hits']
        scroll_size = len(res['hits']['hits'])
    except: 
        break

```

You could also look at using the [scan](http://elasticsearch-py.readthedocs.org/en/latest/helpers.html#elasticsearch.helpers.scan) helper

---

<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, 11:59pm UTC](https://discuss.elastic.co/t/elasticsearch-result-size/26180/3 "2017-07-05T23:59:22Z")

</div>


