@@ -3,7 +3,7 @@ Elasticsearch DSL
3
3
4
4
Elasticsearch DSL is a high-level library whose aim is to help with writing and
5
5
running queries against Elasticsearch. It is built on top of the official
6
- low-level client (`` elasticsearch-py `` ).
6
+ low-level client (`elasticsearch-py < https://github.com/elastic/elasticsearch-py >`_ ).
7
7
8
8
It provides a more convenient and idiomatic way to write and manipulate
9
9
queries. It stays close to the Elasticsearch JSON DSL, mirroring its
@@ -17,6 +17,13 @@ document data in user-defined classes.
17
17
To use the other Elasticsearch APIs (eg. cluster health) just use the
18
18
underlying client.
19
19
20
+ Installation
21
+ ------------
22
+
23
+ ::
24
+
25
+ pip install elasticsearch-dsl
26
+
20
27
Examples
21
28
--------
22
29
@@ -30,6 +37,9 @@ Compatibility
30
37
The library is compatible with all Elasticsearch versions since ``2.x `` but you
31
38
**have to use a matching major version **:
32
39
40
+ For **Elasticsearch 8.0 ** and later, use the major version 8 (``8.x.y ``) of the
41
+ library.
42
+
33
43
For **Elasticsearch 7.0 ** and later, use the major version 7 (``7.x.y ``) of the
34
44
library.
35
45
@@ -45,6 +55,9 @@ library.
45
55
The recommended way to set your requirements in your `setup.py ` or
46
56
`requirements.txt ` is::
47
57
58
+ # Elasticsearch 8.x
59
+ elasticsearch-dsl>=8.0.0,<9.0.0
60
+
48
61
# Elasticsearch 7.x
49
62
elasticsearch-dsl>=7.0.0,<8.0.0
50
63
@@ -58,7 +71,7 @@ The recommended way to set your requirements in your `setup.py` or
58
71
elasticsearch-dsl>=2.0.0,<3.0.0
59
72
60
73
61
- The development is happening on ``master ``, older branches only get bugfix releases
74
+ The development is happening on ``main ``, older branches only get bugfix releases
62
75
63
76
Search Example
64
77
--------------
@@ -68,20 +81,16 @@ Let's have a typical search request written directly as a ``dict``:
68
81
.. code :: python
69
82
70
83
from elasticsearch import Elasticsearch
71
- client = Elasticsearch()
84
+ client = Elasticsearch(" https://localhost:9200 " )
72
85
73
86
response = client.search(
74
87
index = " my-index" ,
75
88
body = {
76
89
" query" : {
77
- " filtered" : {
78
- " query" : {
79
- " bool" : {
80
- " must" : [{" match" : {" title" : " python" }}],
81
- " must_not" : [{" match" : {" description" : " beta" }}]
82
- }
83
- },
84
- " filter" : {" term" : {" category" : " search" }}
90
+ " bool" : {
91
+ " must" : [{" match" : {" title" : " python" }}],
92
+ " must_not" : [{" match" : {" description" : " beta" }}],
93
+ " filter" : [{" term" : {" category" : " search" }}]
85
94
}
86
95
},
87
96
" aggs" : {
@@ -114,7 +123,7 @@ Let's rewrite the example using the Python DSL:
114
123
from elasticsearch import Elasticsearch
115
124
from elasticsearch_dsl import Search
116
125
117
- client = Elasticsearch()
126
+ client = Elasticsearch(" https://localhost:9200 " )
118
127
119
128
s = Search(using = client, index = " my-index" ) \
120
129
.filter(" term" , category = " search" ) \
@@ -134,15 +143,11 @@ Let's rewrite the example using the Python DSL:
134
143
135
144
As you see, the library took care of:
136
145
137
- * creating appropriate ``Query `` objects by name (eq. "match")
138
-
139
- * composing queries into a compound ``bool `` query
140
-
141
- * creating a ``filtered `` query since ``.filter() `` was used
142
-
143
- * providing a convenient access to response data
144
-
145
- * no curly or square brackets everywhere
146
+ - creating appropriate ``Query `` objects by name (eq. "match")
147
+ - composing queries into a compound ``bool `` query
148
+ - putting the ``term `` query in a filter context of the ``bool `` query
149
+ - providing a convenient access to response data
150
+ - no curly or square brackets everywhere
146
151
147
152
148
153
Persistence Example
@@ -153,11 +158,10 @@ Let's have a simple Python class representing an article in a blogging system:
153
158
.. code :: python
154
159
155
160
from datetime import datetime
156
- from elasticsearch_dsl import Document, Date, Integer, Keyword, Text
157
- from elasticsearch_dsl.connections import connections
161
+ from elasticsearch_dsl import Document, Date, Integer, Keyword, Text, connections
158
162
159
163
# Define a default Elasticsearch client
160
- connections.create_connection(hosts = [ ' localhost' ] )
164
+ connections.create_connection(hosts = " https:// localhost:9200 " )
161
165
162
166
class Article (Document ):
163
167
title = Text(analyzer = ' snowball' , fields = {' raw' : Keyword()})
@@ -177,7 +181,7 @@ Let's have a simple Python class representing an article in a blogging system:
177
181
return super (Article, self ).save(** kwargs)
178
182
179
183
def is_published (self ):
180
- return datetime.now() >= self .published_from
184
+ return datetime.now() > self .published_from
181
185
182
186
# create the mappings in elasticsearch
183
187
Article.init()
@@ -197,20 +201,14 @@ Let's have a simple Python class representing an article in a blogging system:
197
201
198
202
In this example you can see:
199
203
200
- * providing a :ref: `default connection `
201
-
202
- * defining fields with mapping configuration
203
-
204
- * setting index name
205
-
206
- * defining custom methods
207
-
208
- * overriding the built-in ``.save() `` method to hook into the persistence
209
- life cycle
210
-
211
- * retrieving and saving the object into Elasticsearch
212
-
213
- * accessing the underlying client for other APIs
204
+ - providing a default connection
205
+ - defining fields with mapping configuration
206
+ - setting index name
207
+ - defining custom methods
208
+ - overriding the built-in ``.save() `` method to hook into the persistence
209
+ life cycle
210
+ - retrieving and saving the object into Elasticsearch
211
+ - accessing the underlying client for other APIs
214
212
215
213
You can see more in the :ref: `persistence ` chapter.
216
214
@@ -284,7 +282,7 @@ Writing this as a ``dict``, we would have the following code:
284
282
},
285
283
)
286
284
287
- Using the DSL, we can now express this query as such:
285
+ Using the DSL, we can now express this query as such:
288
286
289
287
.. code :: python
290
288
0 commit comments