update_by_query

class opensearchpy.helpers.update_by_query.UpdateByQuery(**kwargs)[source]

Bases: Request

Update by query request to opensearch.

Parameters:
  • usingOpenSearch instance to use

  • index – limit the search to index

  • doc_type – only query this type.

  • kwargs (Any) –

All the parameters supplied (or omitted) at creation type can be later overridden by methods (using, index and doc_type respectively).

_clone()[source]

Return a clone of the current search request. Performs a shallow copy of all the underlying objects. Used internally by most state modifying APIs.

Return type:

Any

execute()[source]

Execute the search and return an instance of Response wrapping all the data.

Return type:

Any

classmethod from_dict(d)[source]

Construct a new UpdateByQuery instance from a raw dict containing the search body. Useful when migrating from raw dictionaries.

Example:

ubq = UpdateByQuery.from_dict({
    "query": {
        "bool": {
            "must": [...]
        }
    },
    "script": {...}
})
ubq = ubq.filter('term', published=True)
Parameters:

d (Any) –

Return type:

Any

response_class(cls)[source]

Override the default wrapper used for the response.

Parameters:

cls (Any) –

Return type:

Any

script(**kwargs)[source]

Define update action to take:

Note: the API only accepts a single script, so calling the script multiple times will overwrite.

Example:

ubq = Search()
ubq = ubq.script(source="ctx._source.likes++"")
ubq = ubq.script(source="ctx._source.likes += params.f"",
             lang="expression",
             params={'f': 3})
Parameters:

kwargs (Any) –

Return type:

Any

to_dict(**kwargs)[source]

Serialize the search into the dictionary that will be sent over as the request’ubq body.

All additional keyword arguments will be included into the dictionary.

Parameters:

kwargs (Any) –

Return type:

Any

update_from_dict(d)[source]

Apply options from a serialized body to the current instance. Modifies the object in-place. Used mostly by from_dict.

Parameters:

d (Any) –

Return type:

UpdateByQuery