# Print all documents - Python API

**URL:** <https://discuss.elastic.co/t/print-all-documents-python-api/69061>\
**Category:** Elasticsearch\
**Created:** [December 14, 2016, 5:54pm UTC](https://discuss.elastic.co/t/print-all-documents-python-api/69061 "2016-12-14T17:54:14Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![inancarin](https://avatars.discourse-cdn.com/v4/letter/i/2acd7d/32.png) [@inancarin](https://discuss.elastic.co/u/inancarin)\
**Post date:** [December 14, 2016, 5:54pm UTC](https://discuss.elastic.co/t/print-all-documents-python-api/69061/1 "2016-12-14T17:54:15Z")

</div>

Hi guys,

I have 329998 documents in my _twitter_ index where I store tweet documents inside it. I want to print texts of all tweets into a txt file. Although, I can find the total number of documents correctly (329998), I am only able to write 19 of them into the file.

I think, I should look for the helpers.scan, however I couldn't figure it out. Here is my code:

```
from elasticsearch import Elasticsearch
import codecs

out = codecs.open("/.../output.txt", encoding='utf-8', mode='w+')

es = Elasticsearch()
res = es.search(index="twitter", body={"query": {"match_all": {}}})
print("%d documents found" % res['hits']['total'])

for doc in res['hits']['hits']:
	text = doc['_source']['text'].lower().replace('\n', ' ').replace('\r', '').replace('\t', ' ')
	out.write(text + "\n")
    	
out.close()

```

By the way, I am using ElasticSearch 5.0.0

Thanks,  
Inanc

---

<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:** [January 11, 2017, 5:54pm UTC](https://discuss.elastic.co/t/print-all-documents-python-api/69061/2 "2017-01-11T17:54:39Z")

</div>

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