diff --git a/Changelog.rst b/Changelog.rst index d2075e89a..42d70ffdc 100644 --- a/Changelog.rst +++ b/Changelog.rst @@ -3,6 +3,13 @@ Changelog ========= +8.0.0 (?) +------------------ + +* Fixed DeprecationWarning from elasticsearch-py (`#1558`_) + + .. _#1558: https://github.com/elastic/elasticsearch-dsl-py/pull/1558 + 7.4.0 (2021-07-15) ------------------ diff --git a/README b/README index 3c4eb9d8f..bcf21b6fe 100644 --- a/README +++ b/README @@ -80,22 +80,20 @@ Let's have a typical search request written directly as a ``dict``: response = client.search( index="my-index", - body={ - "query": { + query={ "bool": { - "must": [{"match": {"title": "python"}}], - "must_not": [{"match": {"description": "beta"}}], - "filter": [{"term": {"category": "search"}}] + "must": [{"match": {"title": "python"}}], + "must_not": [{"match": {"description": "beta"}}], + "filter": [{"term": {"category": "search"}}] } - }, - "aggs" : { + }, + aggs={ "per_tag": { - "terms": {"field": "tags"}, - "aggs": { - "max_lines": {"max": {"field": "lines"}} - } + "terms": {"field": "tags"}, + "aggs": { + "max_lines": {"max": {"field": "lines"}} + } } - } } ) diff --git a/elasticsearch_dsl/document.py b/elasticsearch_dsl/document.py index 4324742fe..d1858a31c 100644 --- a/elasticsearch_dsl/document.py +++ b/elasticsearch_dsl/document.py @@ -18,6 +18,7 @@ import collections.abc from fnmatch import fnmatch +import elasticsearch from elasticsearch.exceptions import NotFoundError, RequestError from .connections import get_connection @@ -475,11 +476,17 @@ def save( doc_meta["if_primary_term"] = self.meta["primary_term"] doc_meta.update(kwargs) + + if elasticsearch.__version__ >= (7, 14, 0): + key = 'document' + else: + key = 'body' meta = es.index( index=self._get_index(index), - body=self.to_dict(skip_empty=skip_empty), + **{key: self.to_dict(skip_empty=skip_empty)}, **doc_meta, ) + # update meta information from ES for k in META_FIELDS: if "_" + k in meta: diff --git a/elasticsearch_dsl/index.py b/elasticsearch_dsl/index.py index 8e8dd369b..556fab000 100644 --- a/elasticsearch_dsl/index.py +++ b/elasticsearch_dsl/index.py @@ -277,7 +277,7 @@ def create(self, using=None, **kwargs): ``Elasticsearch.indices.create`` unchanged. """ return self._get_connection(using).indices.create( - index=self._name, body=self.to_dict(), **kwargs + index=self._name, **self.to_dict(), **kwargs ) def is_closed(self, using=None): diff --git a/elasticsearch_dsl/search.py b/elasticsearch_dsl/search.py index c07fe7e71..3dd312f76 100644 --- a/elasticsearch_dsl/search.py +++ b/elasticsearch_dsl/search.py @@ -707,7 +707,7 @@ def execute(self, ignore_cache=False): es = get_connection(self._using) self._response = self._response_class( - self, es.search(index=self._index, body=self.to_dict(), **self._params) + self, es.search(index=self._index, **self.to_dict(), **self._params) ) return self._response