# Help needed with Proper usage of scroll api using python: Getting the same results

**URL:** https://discuss.elastic.co/t/help-needed-with-proper-usage-of-scroll-api-using-python-getting-the-same-results/136063
**Category:** Elasticsearch
**Created:** [June 15, 2018, 9:15am UTC](https://discuss.elastic.co/t/help-needed-with-proper-usage-of-scroll-api-using-python-getting-the-same-results/136063 "2018-06-15T09:15:38Z")
**Posts on this page:** 6
**Page:** 1

<div class="post-metadata">

### Author: ![BoffinPanda](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/boffinpanda/32/26225_2.png) [@BoffinPanda](https://discuss.elastic.co/u/BoffinPanda)
#### Post date: [June 15, 2018, 9:15am UTC](https://discuss.elastic.co/t/help-needed-with-proper-usage-of-scroll-api-using-python-getting-the-same-results/136063/1 "2018-06-15T09:15:38Z")

</div>

Hello all.

I have to parse a document which has more than 10000 hits. The natural choice was to opt for scroll api.

I have read the documentation from elastic and have done the following:

import requests

resp=requests.post('[http://localhost:9200/netflow\*/\_search?pretty=true&size=100&scroll=5m](http://localhost:9200/netflow*/_search?pretty=true&size=100&scroll=5m)')

This gave me a scroll id.

I have stored that scrollID in a variable and did the following:

SearchExp="[http://localhost:9200/\_search/scroll?pretty=true&scroll=5m&scroll\_id=](http://localhost:9200/_search/scroll?pretty=true&scroll=5m&scroll_id=)"+ScrollID  
response = requests.post(SearchExp)

However, everytime I run the program, I get the same 100 results [since size=100].

What should I do to get the next set of results and read the full document above 10000 ??

---

<div class="post-metadata">

### Author: ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)
#### Post date: [June 15, 2018, 11:31am UTC](https://discuss.elastic.co/t/help-needed-with-proper-usage-of-scroll-api-using-python-getting-the-same-results/136063/2 "2018-06-15T11:31:01Z")

</div>

I never tried to pass those parameters as query params. I'm unsure if it's supposed to work.

The [documentation](https://www.elastic.co/guide/en/elasticsearch/reference/current/search-request-scroll.html) says:

```auto
POST /_search/scroll 
{
    "scroll" : "1m", 
    "scroll_id" : "DXF1ZXJ5QW5kRmV0Y2gBAAAAAAAAAD4WYm9laVYtZndUQlNsdDcwakFMNjU1QQ==" 
}

```

Could you try it that way instead?

If it does not work please share all details (responses and requests included).

---

<div class="post-metadata">

### Author: ![BoffinPanda](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/boffinpanda/32/26225_2.png) [@BoffinPanda](https://discuss.elastic.co/u/BoffinPanda)
#### Post date: [June 15, 2018, 12:58pm UTC](https://discuss.elastic.co/t/help-needed-with-proper-usage-of-scroll-api-using-python-getting-the-same-results/136063/3 "2018-06-15T12:58:28Z")

</div>

Hello. It does work this way but I have to use a request i.e. the url way.

The reason is the scroll\_id generated is so long that it doesnt support to be fit inside HTTP post method

---

<div class="post-metadata">

### Author: ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)
#### Post date: [June 15, 2018, 1:15pm UTC](https://discuss.elastic.co/t/help-needed-with-proper-usage-of-scroll-api-using-python-getting-the-same-results/136063/4 "2018-06-15T13:15:09Z")

</div>

> [@BoffinPanda](#):
>
> It does work this way

Great. So documentation says it all IMO.  
I believe this has been removed or was not supported. I did not check the code.  
May be the parameter name is a bit different? Like `_scroll_id` instead?

> The reason is the scroll\_id generated is so long that it doesnt support to be fit inside HTTP post method

I would expect the opposite as the length of a POST with body has no limit (or at least super high limit) but the URL length has a lower limit for sure.

---

<div class="post-metadata">

### Author: ![BoffinPanda](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/boffinpanda/32/26225_2.png) [@BoffinPanda](https://discuss.elastic.co/u/BoffinPanda)
#### Post date: [June 15, 2018, 2:26pm UTC](https://discuss.elastic.co/t/help-needed-with-proper-usage-of-scroll-api-using-python-getting-the-same-results/136063/5 "2018-06-15T14:26:42Z")

</div>

Yes. I was confused.

However, I fixed my issue as follows:

import requests,re,string,json

def main(args):

```
resp=requests.post('http://localhost:9200/netflow-2018.02.20/_search? pretty=true&size=100&scroll=5m')

resp =json.loads(resp.content)
#print (resp)
sid = resp['_scroll_id']
print (sid)
while(True): # continue this loop until hits become zero
	headers = {
	'Content-Type': 'application/json',
	}

	data = '\n{\n "scroll" : "1m", \n "scroll_id" : "'+sid+'" \n}'

	response = requests.post('http://localhost:9200/_search/scroll', headers=headers, data=data)
	response =json.loads(response.content)
	if not (response['hits']['hits']):
		break;
return 0

```

if **name** == ' **main**':  
import sys  
sys.exit(main(sys.argv))

---

<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 13, 2018, 2:26pm UTC](https://discuss.elastic.co/t/help-needed-with-proper-usage-of-scroll-api-using-python-getting-the-same-results/136063/6 "2018-07-13T14:26:43Z")

</div>

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.
