O'Reilly logo

Elasticsearch Essentials by Bharvi Dixit

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Search requests using Python

All the queries that we have discussed can be performed with the Elasticsearch Python client using the search function. To do this, first store the query inside a variable that is query in the following example:

query = {
     "query": {
        "match_all": {}
     },
   }

Call the search function with all the parameters including the index name, document type, and query. The size parameter used in the following search request can also be included inside the query itself:

response = es.search(index='twitter', doc_type='tweets', body=query, size=2, request_timeout=20)

Note

To search against more than one index, instead of using a string value, you need to use a list of index names. The same applies for document types too.

The response data comes ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required