@@ -331,6 +331,7 @@ def update(
331
331
script_id = None ,
332
332
scripted_upsert = False ,
333
333
upsert = None ,
334
+ return_doc_meta = False ,
334
335
** fields
335
336
):
336
337
"""
@@ -356,6 +357,8 @@ def update(
356
357
:arg doc_as_upsert: Instead of sending a partial doc plus an upsert
357
358
doc, setting doc_as_upsert to true will use the contents of doc as
358
359
the upsert value
360
+ :arg return_doc_meta: set to ``True`` to return all metadata from the
361
+ index API call instead of only the operation result
359
362
360
363
:return operation result noop/updated
361
364
"""
@@ -415,9 +418,17 @@ def update(
415
418
if "_" + k in meta :
416
419
setattr (self .meta , k , meta ["_" + k ])
417
420
418
- return meta ["result" ]
421
+ return meta if return_doc_meta else meta ["result" ]
419
422
420
- def save (self , using = None , index = None , validate = True , skip_empty = True , ** kwargs ):
423
+ def save (
424
+ self ,
425
+ using = None ,
426
+ index = None ,
427
+ validate = True ,
428
+ skip_empty = True ,
429
+ return_doc_meta = False ,
430
+ ** kwargs
431
+ ):
421
432
"""
422
433
Save the document into elasticsearch. If the document doesn't exist it
423
434
is created, it is overwritten otherwise. Returns ``True`` if this
@@ -430,6 +441,8 @@ def save(self, using=None, index=None, validate=True, skip_empty=True, **kwargs)
430
441
:arg skip_empty: if set to ``False`` will cause empty values (``None``,
431
442
``[]``, ``{}``) to be left on the document. Those values will be
432
443
stripped out otherwise as they make no difference in elasticsearch.
444
+ :arg return_doc_meta: set to ``True`` to return all metadata from the
445
+ update API call instead of only the operation result
433
446
434
447
Any additional keyword arguments will be passed to
435
448
``Elasticsearch.index`` unchanged.
@@ -459,4 +472,4 @@ def save(self, using=None, index=None, validate=True, skip_empty=True, **kwargs)
459
472
if "_" + k in meta :
460
473
setattr (self .meta , k , meta ["_" + k ])
461
474
462
- return meta ["result" ]
475
+ return meta if return_doc_meta else meta ["result" ]
0 commit comments