Salamander
Salamander

Reputation: 189

How to obtain all the hits in elasticsearch for python?

I am currently trying to run a query using a python package for elasticsearch. However, whenever I call es.search(), I only get 10 results, when there should be more than 1M. Can anyone tell me how I can obtain all the hits?

Upvotes: 3

Views: 3516

Answers (1)

davide
davide

Reputation: 1948

Using the elasticsearch and elasticsearch-dsl libraries:

from elasticsearch import Elasticsearch
from elasticsearch_dsl import Search

client = Elasticsearch(host="localhost")

s = Search(using=client, index="my_index")

for hit in s.scan():
    print(hit.title)

See the documentation about pagination.

Upvotes: 2

Related Questions