1

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 Answer 1

1

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

1
  • Still i have one more issue. If both the values in the context and the value in the params are int then it still over flows. i.e if the value in the context is 2147483647 and the value in the param is 2 then it still over flows to the negative value. Any idea how it can be fixed ?
    – Rock
    May 2, 2017 at 11:56

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.