Skip to content

Inconsistent handling of empty lists in Document partial updates. #1819

Closed
@albertisfu

Description

@albertisfu

Hi! At work we are currently developing an API that relies on Elasticsearch responses. Within our document mapping, we have defined multi-value fields, which we aim to represent as empty arrays ([]) in the API response when these fields are empty. When initially indexing the document, it successfully store empty lists into ES as [] by passing these fields with skip_empty=False.

However, we are encountering an issue with partial updates. After updating a field to become empty, it is stored as None instead of [], even though we are passing the field values as [].

The root cause appears to be within the current implementation of the Document.update method for partial document updates. This method prepares data for Elasticsearch by invoking the to_dict method, which, by default, ignores empty fields. Consequently, empty lists are treated as None and updated accordingly.

Proposed Fix:
To address this issue, I propose modifying the update method to accept skip_empty=False and passing this parameter to the to_dict method. This adjustment will ensure that empty lists are included in the update payload as empty lists instead of being interpreted as None.

Steps to Reproduce:

  1. Save a document with multi-value fields.
  2. Perform a partial update using the Document.update method, passing multi-value fields as empty lists [].
  3. Verify that the empty lists are updated as None instead of remaining as empty lists.

I am willing to contribute to fixing this issue if you believe it should be fixed in this way.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions