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.
Thanks, @Christian_Dahlqvist for the detailed response. I had one more query in question while doing the update I can use script.inline or script.source both resulting in the correct update. What is the actual difference between them? I tried to find out the difference but no luck.
Also, is there any other way of updating a particular field without using the script?