Elasticsearch Python Client (5.x)

raw JSON →
5.5.6 verified Fri May 01 auth: no python maintenance

The official Python client for Elasticsearch version 5.x. This library is in maintenance mode and should not be used with newer Elasticsearch versions. Current version is 5.5.6, with no active development. Users should upgrade to the elasticsearch library (7.x/8.x) for compatibility with modern Elasticsearch clusters.

pip install elasticsearch==5.5.6
error elasticsearch.exceptions.ElasticsearchException: TransportError(400, 'illegal_argument_exception', 'request [PUT /test-index] contains unrecognized parameter: [include_type_name]')
cause A parameter from a newer Elasticsearch version was passed to a 5.x cluster.
fix
Remove any 'include_type_name' parameter. Elasticsearch 5.x always uses mapping types.
error AttributeError: module 'elasticsearch' has no attribute 'Elasticsearch'
cause The package is not properly installed or imported. pip may have installed a different package with the same name.
fix
Uninstall all elasticsearch packages, then run 'pip install elasticsearch==5.5.6' to get the official library.
error elasticsearch.exceptions.ConnectionError: ConnectionError(('Connection aborted.', OSError(0, 'Error'))) caused by: OSError(0, 'Error')
cause Network proxy or SSL issues. In 5.x, SSL is not enabled by default; self-signed certificates cause errors.
fix
Use 'Elasticsearch([host], verify_certs=False, ssl_show_warn=False)' for development. For production, configure proper SSL.
breaking This client is only compatible with Elasticsearch 5.x. Using it with Elasticsearch 6.x or later will cause serialization errors and unexpected behavior.
fix Upgrade to the elasticsearch-py library version 6.x, 7.x, or 8.x matching your Elasticsearch version.
breaking The 'delete_by_query' and 'update_by_query' APIs now require the 'conflicts' parameter to be explicitly set. If not provided, the default behaviour differs from earlier versions.
fix Always pass 'conflicts='proceed'' in delete/update_by_query calls to avoid unexpected failures.
deprecated Support for Python 2.7 is deprecated in this version. Future versions (>=6.0) require Python 3.
fix Migrate to Python 3 to use newer client versions.
gotcha The 'timeout' parameter for connections is in seconds but default is long (10 seconds). Errors may appear as connection timeouts on slow networks. Unlike later versions, 5.x does not support 'max_retries' for connection failures.
fix Set 'timeout' and 'max_retries' on the connection class manually, or upgrade to >=6.0.
pip install elasticsearch5

Connect to a local Elasticsearch 5.x instance, index a document, and perform a basic search.

from elasticsearch import Elasticsearch

# Connect to Elasticsearch (assuming default localhost:9200)
es = Elasticsearch()

# Index a document
res = es.index(index="test-index", id=1, body={"name": "John Doe", "age": 30})
print(res['result'])

# Search for documents
res = es.search(index="test-index", body={"query": {"match": {"name": "John"}}})
print(res['hits']['hits'])