Official Elasticsearch Python client · index · search · aggregate · bulk · verified against elasticsearch-py 9.x (2026)

Elasticsearch Python cheat sheet

The official elasticsearch client is a thin, typed wrapper over the Elasticsearch REST API. Create an Elasticsearch client, index JSON documents, and run Query DSL searches & aggregations — every REST endpoint is a method. Bulk-load with helpers.bulk, scroll huge result sets with helpers.scan, and write fluent queries with the integrated elasticsearch.dsl. Big v9 change: the old body= argument is gone — pass explicit keyword args (query=, mappings=…). Targets elasticsearch-py 9.x, Python 3.10+.

connect & index search mappings & index admin DSL & async ops & ecosystem gotcha / migration most common

Verified 2026-08-31 against elasticsearch-py.readthedocs.io & elastic.co docs (elasticsearch 9.5.0, released 2026-08-04; Python 3.10–3.14). Match the client's major to your cluster's major (9.x client → 9.x cluster). API responses are dict-like ObjectApiResponse objects — index into them like JSON.

Outline

Connect, index documents, then search with the Query DSL. Bulk helpers for volume; elasticsearch.dsl for fluent queries; the async client for concurrency.

Connect & index

  1. 1Install & connect
  2. 2Index & CRUD docs
  3. 3Bulk & helpers

Search

  1. 4Search basics
  2. 5Query types
  3. 6Aggregations

Mappings & admin

  1. 7Mappings & settings
  2. 8text vs keyword

DSL & async

  1. 9elasticsearch.dsl
  2. 10Async client

Ops & ecosystem

  1. 11Scroll, paging & vectors
  2. 12Migration & ecosystem

Connect & Index

Authenticate to a cluster, then create, read, update, and bulk-load documents.

1Install & connectthe client
2Index & CRUD docsdocuments
3Bulk & helpersload at volume
5Query typesthe DSL
6Aggregationsanalytics

Mappings & Index Admin

Define field types up front; understand text vs keyword.

7Mappings & settingsindex schema
8text vs keywordthe #1 mapping choice

DSL & Async

Write queries fluently in Python; go concurrent with the async client.

9elasticsearch.dslfluent queries
10Async clientconcurrency

Ops & Ecosystem

Read everything without exploding memory; know what changed and what's around.

11Scroll, paging & vectorslarge result sets
12Migration & ecosystemwhat changed

Worth memorizing

Elasticsearch(url, api_key=)the client; version-match the cluster
es.index(index=, document=)create/replace a doc
helpers.bulk / streaming_bulkload many — check the errors
es.search(index=, query=)query= NOT body= (v9)
hits.hits[]._sourcewhere the results live
bool: must/filter/should/must_notfilters are unscored + cached
match vs termfull-text vs exact (text vs keyword)
size=0 + aggs=aggregations only, no hits
text.raw multi-fieldsearch text + sort/aggregate keyword
elasticsearch.dslSearch().query().filter() fluent builder
helpers.scanstream a whole index (past 10k)
body= REMOVED in 9.xlift keys into kwargs