# Does index operation (refresh:true) return before or after refresh?

**URL:** https://discuss.elastic.co/t/does-index-operation-refresh-true-return-before-or-after-refresh/72315
**Category:** Elasticsearch
**Created:** [January 20, 2017, 5:53pm UTC](https://discuss.elastic.co/t/does-index-operation-refresh-true-return-before-or-after-refresh/72315 "2017-01-20T17:53:53Z")
**Posts on this page:** 6
**Page:** 1

<div class="post-metadata">

### Author: ![Serg\_Pilipenko](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/serg_pilipenko/32/13833_2.png) [@Serg\_Pilipenko](https://discuss.elastic.co/u/Serg_Pilipenko)
#### Post date: [January 20, 2017, 5:53pm UTC](https://discuss.elastic.co/t/does-index-operation-refresh-true-return-before-or-after-refresh/72315/1 "2017-01-20T17:53:53Z")

</div>

Assuming version 2.4: does index operation with refresh set to true return after or before the refresh is done?  
Doc is not clear about this

---

<div class="post-metadata">

### Author: ![dakrone](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dakrone/32/23351_2.png) [@dakrone](https://discuss.elastic.co/u/dakrone)
#### Post date: [January 23, 2017, 6:01pm UTC](https://discuss.elastic.co/t/does-index-operation-refresh-true-return-before-or-after-refresh/72315/2 "2017-01-23T18:01:34Z")

</div>

It returns after forcing a refresh, so the refresh completes before the operation returns.

---

<div class="post-metadata">

### Author: ![dakrone](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dakrone/32/23351_2.png) [@dakrone](https://discuss.elastic.co/u/dakrone)
#### Post date: [January 23, 2017, 6:10pm UTC](https://discuss.elastic.co/t/does-index-operation-refresh-true-return-before-or-after-refresh/72315/3 "2017-01-23T18:10:25Z")

</div>

Also, it's worth mentioning that adding `?refresh=true` to each indexing operation is a very bad idea, as it will cause segments to be written out with a single document all the time and slow down indexing substantially.

---

<div class="post-metadata">

### Author: ![Serg\_Pilipenko](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/serg_pilipenko/32/13833_2.png) [@Serg\_Pilipenko](https://discuss.elastic.co/u/Serg_Pilipenko)
#### Post date: [January 23, 2017, 6:30pm UTC](https://discuss.elastic.co/t/does-index-operation-refresh-true-return-before-or-after-refresh/72315/4 "2017-01-23T18:30:05Z")

</div>

Thank you for your reply.

The application I use Elasticsearch in has periodic refresh set to 1s.  
According to Marvel there are 3 indexing operations a second in average with peaks at 20/s.  
I assume index with refresh=true will refresh just the shard doc is routed to.  
There are 16 shards in total + 1x replica. So I assume not much should change in terms of refresh rate and in turn, performance should not degradate.  
Application requires consistency of data and uses ES for listings. Having data available for search immediately after index will cover one of consistency gaps.

---

<div class="post-metadata">

### Author: ![dakrone](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dakrone/32/23351_2.png) [@dakrone](https://discuss.elastic.co/u/dakrone)
#### Post date: [January 23, 2017, 8:15pm UTC](https://discuss.elastic.co/t/does-index-operation-refresh-true-return-before-or-after-refresh/72315/5 "2017-01-23T20:15:36Z")

</div>

If you're able, something that would benefit you would be to upgrade to Elasticsearch 5.x, in which case you can use `?refresh=wait_for` which will wait for a natural refresh without triggering one explicitly.

---

<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: [February 20, 2017, 8:16pm UTC](https://discuss.elastic.co/t/does-index-operation-refresh-true-return-before-or-after-refresh/72315/6 "2017-02-20T20:16:12Z")

</div>

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