This is the official low-level Python client for Elasticsearch. Its goal is to provide common ground for all Elasticsearch-related code in Python. For this reason, the client is designed to be unopinionated and extendable. Full documentation is available on Read the Docs.


Current development happens in the master branch.

The library is compatible with all Elasticsearch versions since 0.90.x but you have to use a matching major version:

For Elasticsearch 7.0 and later, use the major version 7 (7.x.y) of the library.

For Elasticsearch 6.0 and later, use the major version 6 (6.x.y) of the library.

For Elasticsearch 5.0 and later, use the major version 5 (5.x.y) of the library.

For Elasticsearch 2.0 and later, use the major version 2 (2.x.y) of the library, and so on.

The recommended way to set your requirements in your setup.py or requirements.txt is::

# Elasticsearch 7.x
# Elasticsearch 6.x
# Elasticsearch 5.x
# Elasticsearch 2.x

If you have a need to have multiple versions installed at the same time older versions are also released as elasticsearch2 and elasticsearch5.

Example useedit

Simple use-case:

>>> from datetime import datetime
>>> from elasticsearch import Elasticsearch

# By default we connect to localhost:9200
>>> es = Elasticsearch()

# Datetimes will be serialized...
>>> es.index(index="my-index-000001", doc_type="test-type", id=42, body={"any": "data", "timestamp": datetime.now()})
{'_id': '42', '_index': 'my-index-000001', '_type': 'test-type', '_version': 1, 'ok': True}

# ...but not deserialized
>>> es.get(index="my-index-000001", doc_type="test-type", id=42)['_source']
{'any': 'data', 'timestamp': '2013-05-12T19:45:31.804229'}

All the API calls map the raw REST API as closely as possible, including the distinction between required and optional arguments to the calls. This means that the code makes distinction between positional and keyword arguments; we, however, recommend that people use keyword arguments for all calls for consistency and safety.


The client’s features include:

  • Translating basic Python data types to and from JSON
  • Configurable automatic discovery of cluster nodes
  • Persistent connections
  • Load balancing (with pluggable selection strategy) across all available nodes
  • Failed connection penalization (time based - failed connections won’t be retried until a timeout is reached)
  • Thread safety
  • Pluggable architecture

The client also contains a convenient set of helpers for some of the more engaging tasks like bulk indexing and reindexing.

Elasticsearch DSLedit

For a more high level client library with more limited scope, have a look at elasticsearch-dsl - a more Pythonic library sitting on top of elasticsearch-py.

It provides a more convenient and idiomatic way to write and manipulate queries. It stays close to the Elasticsearch JSON DSL, mirroring its terminology and structure while exposing the whole range of the DSL from Python either directly using defined classes or a queryset-like expressions.

It also provides an optional persistence layer for working with documents as Python objects in an ORM-like fashion: defining mappings, retrieving and saving documents, wrapping the document data in user-defined classes.