Can i use a custom field to update a elasticsearch doc?

Say my doc looks something like this.
{ ... a: {...}, b: {...} }
and i need to partially update a and b asychronously and maintain the order of updates.
Since the exteranal version in elasticsearch is for the whole document i couldn't use it; since there may be requests to update just a or b field. So i decided add my own version to each of the fields.
like this:
{ ..., my_version: 0 a: {... , my_version: 0}, b: {..., my_version: 0} }

Now in my update_by_query i can say update doc where doc.a.my_version < my_database_udpatedAt.

I realize that this wont work like the inbuilt version in elasticsearch. But i believe that this can maintain the order of updates in my docs.

Would this work. Did i miss anything ?


yes, this could work fine, being protected by the underlying elasticsearch versioning (sequence numbers). You need to be on a relatively new version (with sequence numbers protecting the update) and should only use sequence number based updates on these docs. Also, your source database must increment its version on all updates.

If all your checks in the update-script results in no change to the doc, you should remember to set ctx.op = "noop".

1 Like

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.