Elasticsearch DSL
Elasticsearch DSL is a high-level library whose aim is to help with writing and running queries against Elasticsearch. It is built on top of the official low-level client (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. It exposes the whole range of the DSL from Python either directly using defined classes or a queryset-like expressions. Here is an example:
from elasticsearch_dsl import Search
s = Search(index="my-index") \
.filter("term", category="search") \
.query("match", title="python") \
.exclude("match", description="beta")
for hit in s:
print(hit.title)
Or with asynchronous Python:
from elasticsearch_dsl import AsyncSearch
async def run_query():
s = AsyncSearch(index="my-index") \
.filter("term", category="search") \
.query("match", title="python") \
.exclude("match", description="beta")
async for hit in s:
print(hit.title)
It also provides an optional wrapper for working with documents as Python objects: defining mappings, retrieving and saving documents, wrapping the document data in user-defined classes.
To use the other Elasticsearch APIs (eg. cluster health) just use the underlying client.
Installation
Install the elasticsearch-dsl
package with pip:
pip install elasticsearch-dsl
For asynchronous applications, install with the async
extra:
pip install elasticsearch-dsl[async]
Read more about how to use asyncio with this project.
Examples
Please see the examples
directory to see some complex examples using elasticsearch-dsl
.
Compatibility
The library is compatible with all Elasticsearch versions since 2.x
but you
have to use a matching major version:
For Elasticsearch 8.0 and later, use the major version 8 (8.x.y
) of the
library.
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.
The recommended way to set your requirements in your setup.py or requirements.txt is:
# Elasticsearch 8.x
elasticsearch-dsl>=8.0.0,<9.0.0
# Elasticsearch 7.x
elasticsearch-dsl>=7.0.0,<8.0.0
# Elasticsearch 6.x
elasticsearch-dsl>=6.0.0,<7.0.0
# Elasticsearch 5.x
elasticsearch-dsl>=5.0.0,<6.0.0
# Elasticsearch 2.x
elasticsearch-dsl>=2.0.0,<3.0.0
The development is happening on main
, older branches only get bugfix releases
License
Copyright 2013 Elasticsearch
Licensed under the Apache License, Version 2.0 (the “License”); you may not use this file except in compliance with the License. You may obtain a copy of the License at
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an “AS IS” BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
Contents
- Contribution Guide
- Changelog
- 8.16.0 (2024-11-13)
- 8.15.4 (2024-10-07)
- 8.15.3 (2024-09-12)
- 8.15.2 (2024-09-04)
- 8.15.1 (2024-08-19)
- 8.15.0 (2024-08-09)
- 8.14.0 (2024-06-10)
- 8.13.1 (2024-04-30)
- 8.13.0 (2024-04-03)
- 8.12.0 (2024-01-18)
- 8.11.0 (2023-11-13)
- 8.9.0 (2023-09-07)
- 7.4.1 (2023-03-01)
- 7.4.0 (2021-07-15)
- 7.3.0 (2020-09-16)
- 7.2.1 (2020-06-02)
- 7.2.0 (2020-05-04)
- 7.1.0 (2019-10-23)
- 7.0.0 (2019-04-26)
- 6.4.0 (2019-04-26)
- 6.3.1 (2018-12-05)
- 6.3.0 (2018-11-21)
- 6.2.1 (2018-07-03)
- 6.2.0 (2018-07-03)
- 6.1.0 (2018-01-09)
- 6.0.1 (2018-01-02)
- 6.0.0 (2018-01-01)
- 5.4.0 (2017-12-06)
- 5.3.0 (2017-05-18)
- 5.2.0 (2017-03-26)
- 5.1.0 (2017-01-08)
- 5.0.0 (2016-11-04)
- 2.2.0 (2016-11-04)
- 2.1.0 (2016-06-29)
- 2.0.0 (2016-02-18)
- 0.0.10 (2016-01-24)
- 0.0.9 (2015-10-26)
- 0.0.8 (2015-08-28)
- 0.0.5 (2015-08-27)
- 0.0.4 (2015-04-24)
- 0.0.3 (2015-01-23)
- 0.0.2 (2014-08-27)
- 0.0.1 (2014-08-27)