Skip to content

Commit 85d2c2d

Browse files
committed
Fix DeprecationWarning's from elasticsearch-py.
1 parent 5874ff6 commit 85d2c2d

File tree

5 files changed

+27
-15
lines changed

5 files changed

+27
-15
lines changed

Changelog.rst

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,13 @@
33
Changelog
44
=========
55

6+
8.0.0 (?)
7+
------------------
8+
9+
* Fixed DeprecationWarning from elasticsearch-py (`#1558`_)
10+
11+
.. _#1558: https://github.com/elastic/elasticsearch-dsl-py/pull/1558
12+
613
7.4.0 (2021-07-15)
714
------------------
815

README

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -80,22 +80,20 @@ Let's have a typical search request written directly as a ``dict``:
8080

8181
response = client.search(
8282
index="my-index",
83-
body={
84-
"query": {
83+
query={
8584
"bool": {
86-
"must": [{"match": {"title": "python"}}],
87-
"must_not": [{"match": {"description": "beta"}}],
88-
"filter": [{"term": {"category": "search"}}]
85+
"must": [{"match": {"title": "python"}}],
86+
"must_not": [{"match": {"description": "beta"}}],
87+
"filter": [{"term": {"category": "search"}}]
8988
}
90-
},
91-
"aggs" : {
89+
},
90+
aggs={
9291
"per_tag": {
93-
"terms": {"field": "tags"},
94-
"aggs": {
95-
"max_lines": {"max": {"field": "lines"}}
96-
}
92+
"terms": {"field": "tags"},
93+
"aggs": {
94+
"max_lines": {"max": {"field": "lines"}}
95+
}
9796
}
98-
}
9997
}
10098
)
10199

elasticsearch_dsl/document.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
import collections.abc
1919
from fnmatch import fnmatch
2020

21+
import elasticsearch
2122
from elasticsearch.exceptions import NotFoundError, RequestError
2223

2324
from .connections import get_connection
@@ -475,11 +476,17 @@ def save(
475476
doc_meta["if_primary_term"] = self.meta["primary_term"]
476477

477478
doc_meta.update(kwargs)
479+
480+
if elasticsearch.__version__ >= (7, 14, 0):
481+
key = 'document'
482+
else:
483+
key = 'body'
478484
meta = es.index(
479485
index=self._get_index(index),
480-
body=self.to_dict(skip_empty=skip_empty),
486+
**{key: self.to_dict(skip_empty=skip_empty)},
481487
**doc_meta,
482488
)
489+
483490
# update meta information from ES
484491
for k in META_FIELDS:
485492
if "_" + k in meta:

elasticsearch_dsl/index.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -277,7 +277,7 @@ def create(self, using=None, **kwargs):
277277
``Elasticsearch.indices.create`` unchanged.
278278
"""
279279
return self._get_connection(using).indices.create(
280-
index=self._name, body=self.to_dict(), **kwargs
280+
index=self._name, **self.to_dict(), **kwargs
281281
)
282282

283283
def is_closed(self, using=None):

elasticsearch_dsl/search.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -707,7 +707,7 @@ def execute(self, ignore_cache=False):
707707
es = get_connection(self._using)
708708

709709
self._response = self._response_class(
710-
self, es.search(index=self._index, body=self.to_dict(), **self._params)
710+
self, es.search(index=self._index, **self.to_dict(), **self._params)
711711
)
712712
return self._response
713713

0 commit comments

Comments
 (0)