|
25 | 25 | from elasticsearch.exceptions import NotFoundError, RequestError
|
26 | 26 | from six import add_metaclass, iteritems
|
27 | 27 |
|
28 |
| -from .connections import get_connection |
| 28 | +from .connections import CLIENT_HAS_NAMED_BODY_PARAMS, get_connection |
29 | 29 | from .exceptions import IllegalOperation, ValidationException
|
30 | 30 | from .field import Field
|
31 | 31 | from .index import Index
|
@@ -416,22 +416,29 @@ def update(
|
416 | 416 | body["doc"] = {k: values.get(k) for k in fields.keys()}
|
417 | 417 |
|
418 | 418 | # extract routing etc from meta
|
419 |
| - doc_meta = {k: self.meta[k] for k in DOC_META_FIELDS if k in self.meta} |
| 419 | + params = {k: self.meta[k] for k in DOC_META_FIELDS if k in self.meta} |
420 | 420 |
|
421 | 421 | if retry_on_conflict is not None:
|
422 |
| - doc_meta["retry_on_conflict"] = retry_on_conflict |
| 422 | + params["retry_on_conflict"] = retry_on_conflict |
423 | 423 |
|
424 | 424 | # Optimistic concurrency control
|
425 | 425 | if (
|
426 | 426 | retry_on_conflict in (None, 0)
|
427 | 427 | and "seq_no" in self.meta
|
428 | 428 | and "primary_term" in self.meta
|
429 | 429 | ):
|
430 |
| - doc_meta["if_seq_no"] = self.meta["seq_no"] |
431 |
| - doc_meta["if_primary_term"] = self.meta["primary_term"] |
| 430 | + params["if_seq_no"] = self.meta["seq_no"] |
| 431 | + params["if_primary_term"] = self.meta["primary_term"] |
| 432 | + |
| 433 | + params["refresh"] = refresh |
| 434 | + |
| 435 | + if CLIENT_HAS_NAMED_BODY_PARAMS: |
| 436 | + params.update(body) |
| 437 | + else: |
| 438 | + params["body"] = body |
432 | 439 |
|
433 | 440 | meta = self._get_connection(using).update(
|
434 |
| - index=self._get_index(index), body=body, refresh=refresh, **doc_meta |
| 441 | + index=self._get_index(index), **params |
435 | 442 | )
|
436 | 443 | # update meta information from ES
|
437 | 444 | for k in META_FIELDS:
|
@@ -474,19 +481,20 @@ def save(
|
474 | 481 |
|
475 | 482 | es = self._get_connection(using)
|
476 | 483 | # extract routing etc from meta
|
477 |
| - doc_meta = {k: self.meta[k] for k in DOC_META_FIELDS if k in self.meta} |
| 484 | + params = {k: self.meta[k] for k in DOC_META_FIELDS if k in self.meta} |
478 | 485 |
|
479 | 486 | # Optimistic concurrency control
|
480 | 487 | if "seq_no" in self.meta and "primary_term" in self.meta:
|
481 |
| - doc_meta["if_seq_no"] = self.meta["seq_no"] |
482 |
| - doc_meta["if_primary_term"] = self.meta["primary_term"] |
| 488 | + params["if_seq_no"] = self.meta["seq_no"] |
| 489 | + params["if_primary_term"] = self.meta["primary_term"] |
483 | 490 |
|
484 |
| - doc_meta.update(kwargs) |
485 |
| - meta = es.index( |
486 |
| - index=self._get_index(index), |
487 |
| - body=self.to_dict(skip_empty=skip_empty), |
488 |
| - **doc_meta |
489 |
| - ) |
| 491 | + if CLIENT_HAS_NAMED_BODY_PARAMS: |
| 492 | + params["document"] = self.to_dict(skip_empty=skip_empty) |
| 493 | + else: |
| 494 | + params["body"] = self.to_dict(skip_empty=skip_empty) |
| 495 | + |
| 496 | + params.update(kwargs) |
| 497 | + meta = es.index(index=self._get_index(index), **params) |
490 | 498 | # update meta information from ES
|
491 | 499 | for k in META_FIELDS:
|
492 | 500 | if "_" + k in meta:
|
|
0 commit comments