# Documents doesn't get updated after the version is updated & response is successful in ES

**URL:** <https://discuss.elastic.co/t/documents-doesnt-get-updated-after-the-version-is-updated-response-is-successful-in-es/276742>\
**Category:** Elasticsearch\
**Created:** [June 23, 2021, 8:18am UTC](https://discuss.elastic.co/t/documents-doesnt-get-updated-after-the-version-is-updated-response-is-successful-in-es/276742 "2021-06-23T08:18:29Z")\
**Posts on this page:** 15\
**Page:** 1

<div class="post-metadata">

**Author:** ![Farah\_Zaidi](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/farah_zaidi/32/83575_2.png) [@Farah\_Zaidi](https://discuss.elastic.co/u/Farah_Zaidi)\
**Post date:** [June 23, 2021, 8:18am UTC](https://discuss.elastic.co/t/documents-doesnt-get-updated-after-the-version-is-updated-response-is-successful-in-es/276742/1 "2021-06-23T08:18:29Z")

</div>

Hi ,  
I am facing an issue on AWS Elastic search instance.  
I am sending POST api request to create/update the document in ES , somehow the version gets updated but on querying the record , it still shows the old record.

I am getting the below response :Response:  
{  
"\_index": "test",  
"\_type": "\_doc",  
"\_id": "22492123",  
"\_version": 4,  
"result": "updated",  
"\_shards": {  
"total": 2,  
"successful": 2,  
"failed": 0  
},  
"\_seq\_no": 197,  
"\_primary\_term": 1  
}

Can help to guide on the same.

Thanks

---

<div class="post-metadata">

**Author:** ![Christian\_Dahlqvist](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/christian_dahlqvist/32/4617_2.png) [@Christian\_Dahlqvist](https://discuss.elastic.co/u/Christian_Dahlqvist)\
**Post date:** [June 23, 2021, 8:21am UTC](https://discuss.elastic.co/t/documents-doesnt-get-updated-after-the-version-is-updated-response-is-successful-in-es/276742/2 "2021-06-23T08:21:16Z")

</div>

How did you retrieve the document you showed? Did you use the GET API? If not, did you ensure a refresh was performed before retrieving the document?

---

<div class="post-metadata">

**Author:** ![Farah\_Zaidi](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/farah_zaidi/32/83575_2.png) [@Farah\_Zaidi](https://discuss.elastic.co/u/Farah_Zaidi)\
**Post date:** [June 23, 2021, 8:28am UTC](https://discuss.elastic.co/t/documents-doesnt-get-updated-after-the-version-is-updated-response-is-successful-in-es/276742/3 "2021-06-23T08:28:39Z")

</div>

Hi Christian,

This response I get when I am making POST call through API , something like  
POST /test-index/\_doc/920

Currently we need to update the status field in each document . We are making multiple calls to update documents but somehow they are not reflecting in ES although from logs I can see response is successful.

I added ?refresh=true but still same.

---

<div class="post-metadata">

**Author:** ![Christian\_Dahlqvist](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/christian_dahlqvist/32/4617_2.png) [@Christian\_Dahlqvist](https://discuss.elastic.co/u/Christian_Dahlqvist)\
**Post date:** [June 23, 2021, 8:33am UTC](https://discuss.elastic.co/t/documents-doesnt-get-updated-after-the-version-is-updated-response-is-successful-in-es/276742/4 "2021-06-23T08:33:51Z")

</div>

The response says the document was updated. How do you determine it was not? What query do you run?

---

<div class="post-metadata">

**Author:** ![Farah\_Zaidi](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/farah_zaidi/32/83575_2.png) [@Farah\_Zaidi](https://discuss.elastic.co/u/Farah_Zaidi)\
**Post date:** [June 23, 2021, 8:38am UTC](https://discuss.elastic.co/t/documents-doesnt-get-updated-after-the-version-is-updated-response-is-successful-in-es/276742/5 "2021-06-23T08:38:23Z")

</div>

Yes the response say its updated but when I query

GET /test-index/\_doc/920  
{  
"from": 0,  
"size": 400,  
"query": {  
"match\_all": {}  
}  
The version is updated but the status (field inside document) is old.

---

<div class="post-metadata">

**Author:** ![Christian\_Dahlqvist](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/christian_dahlqvist/32/4617_2.png) [@Christian\_Dahlqvist](https://discuss.elastic.co/u/Christian_Dahlqvist)\
**Post date:** [June 23, 2021, 8:44am UTC](https://discuss.elastic.co/t/documents-doesnt-get-updated-after-the-version-is-updated-response-is-successful-in-es/276742/6 "2021-06-23T08:44:01Z")

</div>

Can you please provide the exact steps required to recreate this issue, e.g. through Kibana dev tools? This would allow us to test and troubleshoot this against a standard Elasticsearch cluster. AWS Elasticsearch are running a forked version so we need to reproduce this on standard Elasticsearch in order to be able to help.

---

<div class="post-metadata">

**Author:** ![Farah\_Zaidi](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/farah_zaidi/32/83575_2.png) [@Farah\_Zaidi](https://discuss.elastic.co/u/Farah_Zaidi)\
**Post date:** [June 23, 2021, 8:51am UTC](https://discuss.elastic.co/t/documents-doesnt-get-updated-after-the-version-is-updated-response-is-successful-in-es/276742/7 "2021-06-23T08:51:19Z")

</div>

Sure .

Currently we have records in Dynamodb which we are streaming into ElasticSearch through Lambda .  
Any new or modified records in db triggers lambda which makes POST call to Elastic Search .

Below is the snippet for Post Request -

```
request.path = path.join('/',esDomain.index,esDomain.doctype,id);
request.body = JSON.stringify(doc);
request.headers['Content-Length'] = Buffer.byteLength(request.body);
 request.method = 'POST';
request.path = path.join('/',esDomain.index,esDomain.doctype,id+'?refresh=true');
console.log("API call",request.path)
request.body = JSON.stringify(doc);
request.headers['Content-Length'] = Buffer.byteLength(request.body);
const send = new AWS.HttpClient();
setTimeout(function () {
    send.handleRequest(request, null, function(httpResp) {
    var respBody = '';
    httpResp.on('data', function (chunk) {
        respBody += chunk;
    });
    httpResp.on('end', function (chunk) {
        console.log('Response: ' + respBody);
        context.succeed('Lambda added document ' + doc);
    });
}, function(err) {
    console.log('Error: ' + err);
    context.fail('Lambda failed with error ' + err);
});},3000)

```

}

I tried adding timeout as well so that when record is updated, version shouldn't conflict but no luck.

---

<div class="post-metadata">

**Author:** ![Farah\_Zaidi](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/farah_zaidi/32/83575_2.png) [@Farah\_Zaidi](https://discuss.elastic.co/u/Farah_Zaidi)\
**Post date:** [June 23, 2021, 8:57am UTC](https://discuss.elastic.co/t/documents-doesnt-get-updated-after-the-version-is-updated-response-is-successful-in-es/276742/8 "2021-06-23T08:57:31Z")

</div>

Also I tested through Kibana Dev Tools too but i see the same record.

---

<div class="post-metadata">

**Author:** ![Christian\_Dahlqvist](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/christian_dahlqvist/32/4617_2.png) [@Christian\_Dahlqvist](https://discuss.elastic.co/u/Christian_Dahlqvist)\
**Post date:** [June 23, 2021, 9:02am UTC](https://discuss.elastic.co/t/documents-doesnt-get-updated-after-the-version-is-updated-response-is-successful-in-es/276742/9 "2021-06-23T09:02:32Z")

</div>

Can you please provide an example we can run through Kibana dev console that replicates the issue?

---

<div class="post-metadata">

**Author:** ![Farah\_Zaidi](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/farah_zaidi/32/83575_2.png) [@Farah\_Zaidi](https://discuss.elastic.co/u/Farah_Zaidi)\
**Post date:** [June 23, 2021, 9:06am UTC](https://discuss.elastic.co/t/documents-doesnt-get-updated-after-the-version-is-updated-response-is-successful-in-es/276742/10 "2021-06-23T09:06:05Z")

</div>

The below query when I executed on Kibana dev tools -

GET /test-index/\_doc/920  
{  
"from": 0,  
"size": 400,  
"query": {  
"match\_all": {}  
}

I got below response -

{  
"\_index" : "test-index",  
"\_type" : "\_doc",  
"\_id" : "920",  
"\_version" : 4,  
"\_seq\_no" : 206,  
"\_primary\_term" : 1,  
"found" : true,  
"\_source" : {  
"Status" : "Processing",  
}  
}

So the version is 4 here but status is still old .

As per logs the status should be "Finished"

---

<div class="post-metadata">

**Author:** ![Christian\_Dahlqvist](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/christian_dahlqvist/32/4617_2.png) [@Christian\_Dahlqvist](https://discuss.elastic.co/u/Christian_Dahlqvist)\
**Post date:** [June 23, 2021, 9:08am UTC](https://discuss.elastic.co/t/documents-doesnt-get-updated-after-the-version-is-updated-response-is-successful-in-es/276742/11 "2021-06-23T09:08:31Z")

</div>

Please show all the steps/requests, e.g.

1. Insert initial document
2. Update document
3. Run refresh
4. Get updated document and check status

---

<div class="post-metadata">

**Author:** ![Farah\_Zaidi](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/farah_zaidi/32/83575_2.png) [@Farah\_Zaidi](https://discuss.elastic.co/u/Farah_Zaidi)\
**Post date:** [June 23, 2021, 9:18am UTC](https://discuss.elastic.co/t/documents-doesnt-get-updated-after-the-version-is-updated-response-is-successful-in-es/276742/12 "2021-06-23T09:18:01Z")

</div>

As mentioned above , I am adding through Post API so this happens through this flow .  
If i add or update through Dev Tools , it works .

Only via Api , document is not getting updated . Creating of new documents works fine.

From Kibana Dev Tools , the same works -

POST /test-index/\_doc/1?refresh=true  
{  
"DataSourceStatus" : "Processing"  
}

POST /test-index/\_doc/1?refresh=true  
{  
"DataSourceStatus" : "Processing\_1"  
}

GET /test-index/\_doc/1 gives correct result-  
{  
"\_index" : "test-index-000001",  
"\_type" : "\_doc",  
"\_id" : "1",  
"\_version" : 3,  
"\_seq\_no" : 2,  
"\_primary\_term" : 1,  
"found" : true,  
"\_source" : {  
"DataSourceStatus" : "Processing\_1"  
}  
}

---

<div class="post-metadata">

**Author:** ![Christian\_Dahlqvist](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/christian_dahlqvist/32/4617_2.png) [@Christian\_Dahlqvist](https://discuss.elastic.co/u/Christian_Dahlqvist)\
**Post date:** [June 23, 2021, 9:19am UTC](https://discuss.elastic.co/t/documents-doesnt-get-updated-after-the-version-is-updated-response-is-successful-in-es/276742/13 "2021-06-23T09:19:28Z")

</div>

Are you sure your update process generates the requests you expect? If you are not able to reproduce it outside your application I would suspect there is something wrong there.

---

<div class="post-metadata">

**Author:** ![Farah\_Zaidi](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/farah_zaidi/32/83575_2.png) [@Farah\_Zaidi](https://discuss.elastic.co/u/Farah_Zaidi)\
**Post date:** [June 23, 2021, 9:22am UTC](https://discuss.elastic.co/t/documents-doesnt-get-updated-after-the-version-is-updated-response-is-successful-in-es/276742/15 "2021-06-23T09:22:34Z")

</div>

Currently I am using the same Post request (POST /test-index/\_doc/1?refresh=true) for both Updating & Creating the record . Will that make any difference.

Also we are updating same record multiple time within seconds

---

<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:** [July 21, 2021, 9:22am UTC](https://discuss.elastic.co/t/documents-doesnt-get-updated-after-the-version-is-updated-response-is-successful-in-es/276742/16 "2021-07-21T09:22:49Z")

</div>

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