Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix DeprecationWarning's from elasticsearch-py. #1558

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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