I am trying to update the size field of a document using script however, instead of adding 2 to the existing value (9) of the size field, it is appending it.
It looks like when you originally added the data, the size contained a string "size" : "9" instead of a number "size" : 9. As a result this field was mapped as a string field instead of a long. The string + operation concatenates string, as a result you are getting back the string "92" instead of the number 11. The simplest way to solve this issue is to reindex your data while making sure that the field size is mapped as a number.
Alternatively, you can also convert from a string to integer and back to string on the fly in your script by doing something like this ctx._source.size = (Integer.parseInt(ctx._source.size) + 2).toString()
Apache, Apache Lucene, Apache Hadoop, Hadoop, HDFS and the yellow elephant
logo are trademarks of the
Apache Software Foundation
in the United States and/or other countries.