# Retry\_on\_conflict when using partial update

**URL:** <https://discuss.elastic.co/t/retry-on-conflict-when-using-partial-update/124193>\
**Category:** Elasticsearch\
**Created:** [March 16, 2018, 3:20am UTC](https://discuss.elastic.co/t/retry-on-conflict-when-using-partial-update/124193 "2018-03-16T03:20:21Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![chuckoh](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/chuckoh/32/26752_2.png) [@chuckoh](https://discuss.elastic.co/u/chuckoh)\
**Post date:** [March 16, 2018, 3:20am UTC](https://discuss.elastic.co/t/retry-on-conflict-when-using-partial-update/124193/1 "2018-03-16T03:20:21Z")

</div>

```
PUT /intro_limits
{
  "settings": {
    "index": {
      "number_of_shards": 1
    },
    "auto_expand_replicas": "0-all"
  },
  "mappings": {
    "doc": {
      "properties": {
        "id": { "type": "long" },
        "list": { "type": "long" }
      }
    }
  }
}

```

I need to partial-update the index above in a concurrent manner.

The `list` contains array of long type data (maintains up to 1000s of them) and, a new long type data will be appended into it frequently.

I observed that the partial update has occasionally failed with a status code of 409.

So, I ended up setting `retry_on_conflict=5` like this;

```
public function setIntroLimitAddParams(int $id, int $id_to_be_added)
{
    return [
        'id' => $id,
        'index' => 'intro_limits',
        'type' => 'doc',
        'retry_on_conflict' => 5,
        'body' => [
            'script' => [
                'source' =><<<EOT
if (ctx._source.list.contains(params.x)) {ctx.op = 'noop'}
ctx._source.list.add(params.x)
EOT
                ,
                'lang' => 'painless',
                'params' => [
                    'x' => $id_to_be_added
                ]
            ],
            'upsert' => [
                'id' => $id,
                'list' => [$id_to_be_added]
            ]
        ]
    ];
}

```

Ever since I set the retry\_on\_conflict parameter, 409 error has been completely gone. But, within my use case, the integrity of data entries is very important. No missing data entry is allowed.

My question here is that letting Elasticsearch resolute the conflict with the retry\_on\_conflict parameter guarantees "I will never experience any chances of data loss?"

I've just experienced that one of list data is NOT appended while I was testing my application... even though I get all 200 status (no 409 status) responses from Elasticsearch. What makes me frustrate is that now I can't reproduce the case again.

So, I'm wondering if it's sensible to presume that using retry\_on\_conflict parameter is appropriate in my use case. Or, instead of using retry\_on\_conflict parameter, I should deal with the 409 error manually by sending requests until I get 200 on application level.

Any advice will greatly be appreciated. Btw, I'm using Elasticsearch 6.0.1

Thanks.

Chuck.

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [April 13, 2018, 3:20am UTC](https://discuss.elastic.co/t/retry-on-conflict-when-using-partial-update/124193/2 "2018-04-13T03:20:23Z")

</div>

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.
