Reputation: 299
I have a python script that should print all the ID's of people in my JSON files stored in elasticsearch. But I only get ten results(truncated), as I know that by default only 10 results are shown.
from elasticsearch import Elasticsearch
import sys
es = Elasticsearch()
res = es.search(index="my_docs", body={"query": {"match_all": {}}})
print("%d documents found" % res['hits']['total'])
for doc in res['hits']['hits']:
print (" Doc ID: %s" % (doc['_id']))
It says 5000 Documents found but returns 10 ID's only.
What is the way to get all documents' Doc ID's printed from my collection in Elasticsearch?
Upvotes: 1
Views: 5446
Reputation: 61
Upvotes: 0
Reputation: 59416
You need to tell ES to return more than ten results (which is the default):
body={"query": {"match_all": {}}, 'results': 1000}
For very large amounts of results you need to get all results in a paging manner; ES provides means to do this.
Upvotes: 1