Cyber_Tron
Cyber_Tron

Reputation: 299

Elasticsearch results limit issue

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

Answers (2)

Seenivasan Kannan
Seenivasan Kannan

Reputation: 61

  1. Use Scroll api if Number of documents exceeds 10000.
  2. Use Search api with limit to get specified count.

Upvotes: 0

Alfe
Alfe

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

Related Questions