Skip to content

Commit 8aa969c

Browse files
DSL migrating section
1 parent 1a7d83f commit 8aa969c

File tree

3 files changed

+42
-11
lines changed

3 files changed

+42
-11
lines changed

docs/reference/dsl_migrating.md

+35
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
# Migrating from the `elasticsearch-dsl` package [_migrating_from_elasticsearch_dsl_package]
2+
3+
In the past the Elasticsearch Python DSL module was distributed as a standalone package called `elasticsearch-dsl`. This package is now deprecated, since all its functionality has been integrated into the main Python client. We recommend all developers to migrate their applications and eliminate their dependency on the `elasticsearch-dsl` package.
4+
5+
To migrate your application, all references to `elasticsearch_dsl` as a top-level package must be changed to `elasticsearch.dsl`. In other words, the underscore from the package name should be replaced by a period.
6+
7+
Here are a few examples:
8+
9+
```python
10+
# from:
11+
from elasticsearch_dsl import Date, Document, InnerDoc, Text, connections
12+
# to:
13+
from elasticsearch.dsl import Date, Document, InnerDoc, Text, connections
14+
15+
# from:
16+
from elasticsearch_dsl.query import MultiMatch
17+
# to:
18+
from elasticsearch.dsl.query import MultiMatch
19+
20+
# from:
21+
import elasticsearch_dsl as dsl
22+
# to:
23+
from elasticsearch import dsl
24+
25+
# from:
26+
import elasticsearch_dsl
27+
# to:
28+
from elasticsearch import dsl as elasticsearch_dsl
29+
30+
# from:
31+
import elasticsearch_dsl
32+
# to:
33+
from elasticsearch import dsl
34+
# and replace all references to "elasticsearch_dsl" in the code with "dsl"
35+
```

docs/reference/dsl_tutorials.md

+6-11
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ for tag in response.aggregations.per_tag.buckets:
6868
print(tag.key, tag.max_lines.value)
6969
```
7070

71-
As you see, the library took care of:
71+
As you see, the DSL module took care of:
7272

7373
* creating appropriate `Query` objects from classes
7474
* composing queries into a compound `bool` query
@@ -101,7 +101,7 @@ class Article(Document):
101101
"number_of_shards": 2,
102102
}
103103

104-
def save(self, ** kwargs):
104+
def save(self, **kwargs):
105105
self.lines = len(self.body.split())
106106
return super(Article, self).save(** kwargs)
107107

@@ -127,7 +127,7 @@ print(connections.get_connection().cluster.health())
127127
In this example you can see:
128128

129129
* providing a default connection
130-
* defining fields with mapping configuration
130+
* defining fields with Python type hints and additional mapping configuration when necessary
131131
* setting index name
132132
* defining custom methods
133133
* overriding the built-in `.save()` method to hook into the persistence life cycle
@@ -141,12 +141,6 @@ You can see more in the `persistence` chapter.
141141

142142
If you have your `Document`s defined you can very easily create a faceted search class to simplify searching and filtering.
143143

144-
::::{note}
145-
This feature is experimental and may be subject to change.
146-
147-
::::
148-
149-
150144
```python
151145
from elasticsearch.dsl import FacetedSearch, TermsFacet, DateHistogramFacet
152146

@@ -208,11 +202,12 @@ Using the DSL, we can now express this query as such:
208202
```python
209203
from elasticsearch import Elasticsearch
210204
from elasticsearch.dsl import Search, UpdateByQuery
205+
from elasticsearch.dsl.query import Match
211206

212207
client = Elasticsearch()
213208
ubq = UpdateByQuery(using=client, index="my-index") \
214-
.query("match", title="python") \
215-
.exclude("match", description="beta") \
209+
.query(Match("title", "python")) \
210+
.exclude(Match("description", "beta")) \
216211
.script(source="ctx._source.likes++", lang="painless")
217212

218213
response = ubq.execute()

docs/reference/toc.yml

+1
Original file line numberDiff line numberDiff line change
@@ -16,4 +16,5 @@ toc:
1616
- file: dsl_tutorials.md
1717
- file: dsl_how_to_guides.md
1818
- file: dsl_examples.md
19+
- file: dsl_migrating.md
1920
- file: client-helpers.md

0 commit comments

Comments
 (0)