Update existing record shuffles the data

Elasticsearch will always return exactly the source document that was indexed, but JSON serialisation does not provide any guarantee around which order the fields will written. If you retrieved the document and made the change client side you can control how it is serialised, but this is not possible when you perform a scripted update. When the field is changed by the script, the document is deserialised before the field is changed and/or added and it is then serialised again before being stored. At this point no ordering is guaranteed, so what you are seeing is as far as I know expected.

3 Likes