TypeError: Elasticsearch.__init__() got an unexpected keyword argument 'timeout'
Fixes elasticsearch-py v8 code passing the removed timeout argument. Use when the constructor raises TypeError on timeout. Not for v7 installs.
TL;DR: elasticsearch-py 8 renamed timeout to requesttimeout. Change Elasticsearch(hosts, timeout=30) to Elasticsearch(hosts, requesttimeout=30) and the TypeError goes away.
TypeError: Elasticsearch.__init__() got an unexpected keyword argument 'timeout'Fix it
- Rename the argument: request_timeout=30. Expected: constructor accepts it.
- Grep for other v7-isms in the same call: httpauth= becomes basicauth=, connection_class= goes away. Expected: no more TypeErrors.
- Verify with a cheap call: es.info(). Expected: cluster info dict.
- Pin elasticsearch>=8 in requirements so a fresh install does not pull v7.
When this applies
- The TypeError names timeout and elasticsearch is 8.x.
When it doesn't
- elasticsearch is 7.x: timeout= is correct there; something else is wrong.
- The error names a different argument: check the v8 migration guide for its rename.
Compatibility
- elasticsearch-py >= 8.0.
Why it happens
The v8 rewrite renamed several constructor arguments for consistency. timeout was ambiguous (connect vs request), so it became the explicit request_timeout.
Edge cases
- request_timeout can also be a per-request kwarg on search/get calls, which is often the better place for it.
- maxretries and retryon_timeout still exist; only the name timeout was taken.
Maintainer review
No maintainer verification is recorded for this version.
This records the version a maintainer checked. It does not assert that the version is the latest upstream release.