Skip to content

Commit

Permalink
Fix DeprecationWarning's from elasticsearch-py.
Browse files Browse the repository at this point in the history
  • Loading branch information
arnau126 committed Oct 7, 2022
1 parent f7f85a5 commit 41c95e0
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 15 deletions.
7 changes: 7 additions & 0 deletions Changelog.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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)
------------------

Expand Down
22 changes: 10 additions & 12 deletions README
Original file line number Diff line number Diff line change
Expand Up @@ -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"}}
}
}
}
}
)

Expand Down
9 changes: 8 additions & 1 deletion elasticsearch_dsl/document.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import collections.abc
from fnmatch import fnmatch

import elasticsearch
from elasticsearch.exceptions import NotFoundError, RequestError

from .connections import get_connection
Expand Down Expand Up @@ -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:
Expand Down
2 changes: 1 addition & 1 deletion elasticsearch_dsl/index.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
2 changes: 1 addition & 1 deletion elasticsearch_dsl/search.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down

0 comments on commit 41c95e0

Please sign in to comment.