1
votes

I am currently using Elastic search 5.2 and trying to perform upsert operation using the following rest api:

This api does the following things:

1.) If the index is not found in the elastic search then creates an index with the json provided inside the upsert field.
2.) If the index exist then it performs the partial update by running the painless script provided in the document.

Issue:
I have created the elastic search index mapping for counter as long.

This update works fine until the counter value is within the integer range.(i.e)2,147,483,647
Beyond this value, it overflows and becomes the negative value which in case the expected value it positive long value(as the corresponding index map is long). Is there a way to solve this int overflow issue while using painless script?

1

1 Answers

1
votes

You simply need to modify your script a little bit and not use the += operator. If you modify your script to ctx._source.size = ctx._source.size + params.size instead of ctx._source.size += params.size, then it will work as you expect:

POST indexname/typename/id/_update
{
  "script" : {
    "inline": "ctx._source.size = ctx._source.size + params.size",
    "lang": "painless",
    "params" :{
      "size" : 14889114000
    }
  },
  "upsert" : {
    "size" : 1488911400
  }
}

First the document will be upserted with size: 1488911400 and then on the second update it will contain the value size: 16378025400 which is 1488911400 + 14889114000