Skip to content

Store.save raises if document id provided in _id field #964

Open
@mariokostelac

Description

@mariokostelac

Store.save(document) with a document serializing _id field raises because ElasticSearch does not allow _id being serialized as part of the document body.

While investigating the fix, I've found interesting differences between update and save methods

  • update uses __extract_id_from_document, which
    • treats id as _id for routing
    • removes _id and id from the document
    • does not store id outside of _id field
    • treats id as _id for routing
  • save uses __get_id_from_document, which
    • treats id as _id for routing
    • does not remove _id or id from the document
    • tries to store id if it exists
    • makes the save call fail if document serializes _id.

Having this behaviour forces users to define :id field, instead of being able to define :_id only. Is this a bug or such behaviour is introduced on purpose?

If it's on purpose, I'd like to get some guidance on using :id and :_id field with this gem.

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