# Java API - IndexRequest with refresh

**URL:** https://discuss.elastic.co/t/java-api-indexrequest-with-refresh/12114
**Category:** Elasticsearch
**Created:** [May 24, 2013, 3:12pm UTC](https://discuss.elastic.co/t/java-api-indexrequest-with-refresh/12114 "2013-05-24T15:12:37Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![Andrei\_Tolnai](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/andrei_tolnai/32/2314_2.png) [@Andrei\_Tolnai](https://discuss.elastic.co/u/Andrei_Tolnai)
#### Post date: [May 24, 2013, 3:12pm UTC](https://discuss.elastic.co/t/java-api-indexrequest-with-refresh/12114/1 "2013-05-24T15:12:37Z")

</div>

Hello.

Does \*ElasticSearch \*ensure that after one makes an index request and sets _refresh_ to _true_, the refresh is being completed by the time we get the response back or the refresh is done asynchronously and it is not guaranteed that refresh is completed by the time the response is sent back?

Sample code:  
val request = new IndexRequest(indexName, typeName)  
.refresh(true)  
.id(someId)  
.source(someJson.toString)

Thanks!

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<div class="post-metadata">

### Author: ![jprante](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/jprante/32/44941_2.png) [@jprante](https://discuss.elastic.co/u/jprante)
#### Post date: [May 25, 2013, 8:09am UTC](https://discuss.elastic.co/t/java-api-indexrequest-with-refresh/12114/2 "2013-05-25T08:09:36Z")

</div>

The "refresh" attribute in the index request controls the optional  
execution of a (heavy) refresh operation after the document creation.  
This is synchronous per shard but asynchronous per replica.

If you want to receive the API response after all replica shards have  
completed the operation you must increase the write consistency to  
WriteConsistencyLevel.ALL. This will wait for operation completion for  
all nodes being involved until the timeout in the request given is exceeded.

Jörg

Am 24.05.13 17:12, schrieb Andrei Tolnai:

> Hello.  
> Does \*Elasticsearch \*ensure that after one makes an index request and  
> sets _refresh_ to _true_, the refresh is being completed by the time  
> we get the response back or the refresh is done asynchronously and it  
> is not guaranteedthat refresh is completed by the time the response is  
> sent back?  
> Sample code:  
> valrequest=newIndexRequest(indexName,typeName)  
> .refresh(true)  
> .id(someId)  
> .source(someJson.toString)

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<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 6, 2017, 2:34am UTC](https://discuss.elastic.co/t/java-api-indexrequest-with-refresh/12114/3 "2017-07-06T02:34:49Z")

</div>


