Elasticsearch Python Client

9.3.0 · active · verified Tue Mar 24

Official Python client for Elasticsearch. Current version: 9.3.0 (Mar 2026). v8.0 was a major breaking change from v7.x: 'body' parameter removed in favor of named keyword arguments, doc_type removed, transport layer rewritten. Client version must match Elasticsearch server major version. Multiple packages on PyPI: elasticsearch (latest), elasticsearch8, elasticsearch7 for pinning to specific major versions.

Warnings

Install

Imports

Quickstart

Elasticsearch v8/v9 Python client with named params (no body=).

# pip install elasticsearch
from elasticsearch import Elasticsearch

# Elastic Cloud
es = Elasticsearch(
    cloud_id='my-deployment:dXMtZ...',
    api_key='my-api-key'
)

# Self-hosted
es = Elasticsearch(
    'https://localhost:9200',
    basic_auth=('elastic', 'password'),
    verify_certs=False  # dev only
)

# Index a document — no body=, no doc_type
es.index(index='products', id='1', document={
    'name': 'Widget',
    'price': 9.99
})

# Search
resp = es.search(
    index='products',
    query={'match': {'name': 'Widget'}}
)
for hit in resp['hits']['hits']:
    print(hit['_source'])

es.close()

view raw JSON →