# Elastic search query after update returning old non updated document

**URL:** <https://discuss.elastic.co/t/elastic-search-query-after-update-returning-old-non-updated-document/64858>\
**Category:** Elasticsearch\
**Created:** [November 3, 2016, 12:18pm UTC](https://discuss.elastic.co/t/elastic-search-query-after-update-returning-old-non-updated-document/64858 "2016-11-03T12:18:05Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Pranjal\_Gupta](https://avatars.discourse-cdn.com/v4/letter/p/9fc29f/32.png) [@Pranjal\_Gupta](https://discuss.elastic.co/u/Pranjal_Gupta)\
**Post date:** [November 3, 2016, 12:18pm UTC](https://discuss.elastic.co/t/elastic-search-query-after-update-returning-old-non-updated-document/64858/1 "2016-11-03T12:18:05Z")

</div>

I am updating a document in my index where I am changing its status from 0 to 1. When I do an update and again query for any document having status 0, it again returns the same document, so I end up doing the same thing again. This operation gets repeated twice or thrice randomly. There seems to be some lag on part of elastic search client because if I do the same operation with a settimeout, it doesn't repeat. This problem gets magnified when I update a say 5000 documents, which runs around 5500 times on an average.

function getData(){  
client.search({  
index: 'es\_dummy',  
type: 'log',  
size: 1,  
body: {  
"query" : {  
"match" : {  
"status" : "0"  
}  
}  
}  
},  
function(err, resp){  
console.log(resp.hits.hits.length);  
if(resp.hits.hits.length)  
updateIndexData(resp.hits.hits, 0, resp.hits.hits.length);  
else  
console.log("done");  
});  
}  
getData();  
function updateIndexData(resp, index, length){  
client.update({  
index: 'es\_dummy',  
type: 'log',  
id: resp[index].\_id,  
script: 'ctx.\_source.status = 1'  
},  
function(err1, resp1){  
if(!err1 && resp1){  
console.log("updated" + " " + update);  
var milliseconds = (new Date).getTime();  
console.log("time " + milliseconds);  
update++;  
getData();  
}  
else  
console.log(err1);  
})

}

---

<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 5, 2017, 10:06pm UTC](https://discuss.elastic.co/t/elastic-search-query-after-update-returning-old-non-updated-document/64858/2 "2017-07-05T22:06:58Z")

</div>


