Skip to content

Commit 65f2a18

Browse files
committed
Merge branch 'master' of github.com:elastic/elasticsearch-dsl-py
2 parents 6450153 + e77ea75 commit 65f2a18

File tree

9 files changed

+62
-23
lines changed

9 files changed

+62
-23
lines changed

docs/index.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ Compatibility
3030
The library is compatible with all Elasticsearch versions since ``2.x`` but you
3131
**have to use a matching major version**:
3232

33-
For **Elasticsearch 6.0** and later, use the major version 7 (``7.x.y``) of the
33+
For **Elasticsearch 7.0** and later, use the major version 7 (``7.x.y``) of the
3434
library.
3535

3636
For **Elasticsearch 6.0** and later, use the major version 6 (``6.x.y``) of the

docs/search_dsl.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -462,7 +462,7 @@ If you need to limit the fields being returned by elasticsearch, use the
462462
# don't return any fields, just the metadata
463463
s = s.source(False)
464464
# explicitly include/exclude fields
465-
s = s.source(include=["title"], exclude=["user.*"])
465+
s = s.source(includes=["title"], excludes=["user.*"])
466466
# reset the field selection
467467
s = s.source(None)
468468

docs/update_by_query.rst

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,17 @@ explicitly:
8080
8181
print(ubq.to_dict())
8282
83+
Also, to use variables in script see below example:
84+
85+
.. code:: python
86+
87+
ubq.script(
88+
source="ctx._source.messages.removeIf(x -> x.somefield == params.some_var)",
89+
params={
90+
'some_var': 'some_string_val'
91+
}
92+
)
93+
8394
Serialization and Deserialization
8495
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
8596

@@ -94,7 +105,7 @@ the data from the dict:
94105
95106
ubq = UpdateByQuery.from_dict({"query": {"match": {"title": "python"}}})
96107
97-
If you wish to modify an existing ``Update By Query`` object, overriding it'ubq
108+
If you wish to modify an existing ``Update By Query`` object, overriding it's
98109
properties, instead use the ``update_from_dict`` method that alters an instance
99110
**in-place**:
100111

elasticsearch_dsl/document.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,7 @@ def get(cls, id, using=None, index=None, **kwargs):
170170
"""
171171
Retrieve a single document from elasticsearch using it's ``id``.
172172
173-
:arg id: ``id`` of the document to be retireved
173+
:arg id: ``id`` of the document to be retrieved
174174
:arg index: elasticsearch index to use, if the ``Document`` is
175175
associated with an index this can be omitted.
176176
:arg using: connection alias to use, defaults to ``'default'``
@@ -195,7 +195,7 @@ def mget(cls, docs, using=None, index=None, raise_on_error=True,
195195
Retrieve multiple document by their ``id``\s. Returns a list of instances
196196
in the same order as requested.
197197
198-
:arg docs: list of ``id``\s of the documents to be retireved or a list
198+
:arg docs: list of ``id``\s of the documents to be retrieved or a list
199199
of document specifications as per
200200
https://www.elastic.co/guide/en/elasticsearch/reference/current/docs-multi-get.html
201201
:arg index: elasticsearch index to use, if the ``Document`` is
@@ -274,6 +274,12 @@ def delete(self, using=None, index=None, **kwargs):
274274
for k in DOC_META_FIELDS
275275
if k in self.meta
276276
}
277+
278+
# Optimistic concurrency control
279+
if 'seq_no' in self.meta and 'primary_term' in self.meta:
280+
doc_meta['if_seq_no'] = self.meta['seq_no']
281+
doc_meta['if_primary_term'] = self.meta['primary_term']
282+
277283
doc_meta.update(kwargs)
278284
es.delete(
279285
index=self._get_index(index),

elasticsearch_dsl/index.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -318,7 +318,7 @@ def analyze(self, using=None, **kwargs):
318318

319319
def refresh(self, using=None, **kwargs):
320320
"""
321-
Preforms a refresh operation on the index.
321+
Performs a refresh operation on the index.
322322
323323
Any additional keyword arguments will be passed to
324324
``Elasticsearch.indices.refresh`` unchanged.
@@ -327,7 +327,7 @@ def refresh(self, using=None, **kwargs):
327327

328328
def flush(self, using=None, **kwargs):
329329
"""
330-
Preforms a flush operation on the index.
330+
Performs a flush operation on the index.
331331
332332
Any additional keyword arguments will be passed to
333333
``Elasticsearch.indices.flush`` unchanged.

elasticsearch_dsl/search.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -441,7 +441,7 @@ def update_from_dict(self, d):
441441
s.setdefault('text', text)
442442
if 'script_fields' in d:
443443
self._script_fields = d.pop('script_fields')
444-
self._extra = d
444+
self._extra.update(d)
445445
return self
446446

447447
def script_fields(self, **kwargs):
@@ -478,19 +478,19 @@ def source(self, fields=None, **kwargs):
478478
:arg fields: wildcard string, array of wildcards, or dictionary of includes and excludes
479479
480480
If ``fields`` is None, the entire document will be returned for
481-
each hit. If fields is a dictionary with keys of 'include' and/or
482-
'exclude' the fields will be either included or excluded appropriately.
481+
each hit. If fields is a dictionary with keys of 'includes' and/or
482+
'excludes' the fields will be either included or excluded appropriately.
483483
484484
Calling this multiple times with the same named parameter will override the
485485
previous values with the new ones.
486486
487487
Example::
488488
489489
s = Search()
490-
s = s.source(include=['obj1.*'], exclude=["*.description"])
490+
s = s.source(includes=['obj1.*'], excludes=["*.description"])
491491
492492
s = Search()
493-
s = s.source(include=['obj1.*']).source(exclude=["*.description"])
493+
s = s.source(includes=['obj1.*']).source(excludes=["*.description"])
494494
495495
"""
496496
s = self._clone()

elasticsearch_dsl/update_by_query.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ def update_from_dict(self, d):
8585
self.query._proxied = Q(d.pop('query'))
8686
if 'script' in d:
8787
self._script = d.pop('script')
88-
self._extra = d
88+
self._extra.update(d)
8989
return self
9090

9191
def script(self, **kwargs):

test_elasticsearch_dsl/test_integration/test_document.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -288,6 +288,13 @@ def test_save_automatically_uses_seq_no_and_primary_term(data_client):
288288
with raises(ConflictError):
289289
elasticsearch_repo.save()
290290

291+
def test_delete_automatically_uses_seq_no_and_primary_term(data_client):
292+
elasticsearch_repo = Repository.get('elasticsearch-dsl-py')
293+
elasticsearch_repo.meta.seq_no += 1
294+
295+
with raises(ConflictError):
296+
elasticsearch_repo.delete()
297+
291298
def assert_doc_equals(expected, actual):
292299
for f in expected:
293300
assert f in actual

test_elasticsearch_dsl/test_search.py

Lines changed: 25 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -421,32 +421,32 @@ def test_source():
421421

422422
assert {
423423
'_source': {
424-
'include': ['foo.bar.*'],
425-
'exclude': ['foo.one']
424+
'includes': ['foo.bar.*'],
425+
'excludes': ['foo.one']
426426
}
427-
} == search.Search().source(include=['foo.bar.*'], exclude=['foo.one']).to_dict()
427+
} == search.Search().source(includes=['foo.bar.*'], excludes=['foo.one']).to_dict()
428428

429429
assert {
430430
'_source': False
431431
} == search.Search().source(False).to_dict()
432432

433433
assert {
434434
'_source': ['f1', 'f2']
435-
} == search.Search().source(include=['foo.bar.*'], exclude=['foo.one']).source(['f1', 'f2']).to_dict()
435+
} == search.Search().source(includes=['foo.bar.*'], excludes=['foo.one']).source(['f1', 'f2']).to_dict()
436436

437437
def test_source_on_clone():
438438
assert {
439439
'_source': {
440-
'include': ['foo.bar.*'],
441-
'exclude': ['foo.one']
440+
'includes': ['foo.bar.*'],
441+
'excludes': ['foo.one']
442442
},
443443
'query': {
444444
'bool': {
445445
'filter': [{'term': {'title': 'python'}}],
446446
}
447447
}
448-
} == search.Search().source(include=['foo.bar.*']).\
449-
source(exclude=['foo.one']).\
448+
} == search.Search().source(includes=['foo.bar.*']).\
449+
source(excludes=['foo.one']).\
450450
filter('term', title='python').to_dict()\
451451

452452
assert {'_source': False,
@@ -459,8 +459,8 @@ def test_source_on_clone():
459459

460460
def test_source_on_clear():
461461
assert {
462-
} == search.Search().source(include=['foo.bar.*']).\
463-
source(include=None, exclude=None).to_dict()
462+
} == search.Search().source(includes=['foo.bar.*']).\
463+
source(includes=None, excludes=None).to_dict()
464464

465465
def test_suggest_accepts_global_text():
466466
s = search.Search.from_dict({
@@ -530,3 +530,18 @@ def test_delete_by_query(mock_client):
530530
index=None,
531531
body={"query": {"match": {"lang": "java"}}}
532532
)
533+
534+
def test_update_from_dict():
535+
s = search.Search()
536+
s.update_from_dict({"indices_boost": [{"important-documents": 2}]})
537+
s.update_from_dict({"_source": ["id", "name"]})
538+
539+
assert {
540+
'indices_boost': [{
541+
'important-documents': 2
542+
}],
543+
'_source': [
544+
'id',
545+
'name'
546+
]
547+
} == s.to_dict()

0 commit comments

Comments
 (0)