# Losing data if I don't flush

**URL:** <https://discuss.elastic.co/t/losing-data-if-i-dont-flush/6920>\
**Category:** Elasticsearch\
**Created:** [March 6, 2012, 8:01pm UTC](https://discuss.elastic.co/t/losing-data-if-i-dont-flush/6920 "2012-03-06T20:01:22Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Eric\_Jain](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/eric_jain/32/834_2.png) [@Eric\_Jain](https://discuss.elastic.co/u/Eric_Jain)\
**Post date:** [March 6, 2012, 8:01pm UTC](https://discuss.elastic.co/t/losing-data-if-i-dont-flush/6920/1 "2012-03-06T20:01:22Z")

</div>

During development I frequently restart the application that I have  
elasticsearch embedded in. I noticed that the last update to an index  
is often lost--unless the indexes are flushed. Shouldn't close() be  
enough?

public void init() {  
Settings settings = ImmutableSettings.settingsBuilder()  
.put("index.mapper.dynamic", false)  
.put("index.cache.filter.type", "none")  
.put("action.auto\_create\_index", false).build();  
node = NodeBuilder.nodeBuilder().settings(settings).node();  
client = node.client();  
recover();  
}

public void close() {

client.admin().indices().prepareFlush("\_all").execute().actionGet();  
client.close();  
node.close();  
}

---

<div class="post-metadata">

**Author:** ![Eric\_Jain](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/eric_jain/32/834_2.png) [@Eric\_Jain](https://discuss.elastic.co/u/Eric_Jain)\
**Post date:** [March 6, 2012, 8:39pm UTC](https://discuss.elastic.co/t/losing-data-if-i-dont-flush/6920/2 "2012-03-06T20:39:38Z")

</div>

On Mar 6, 12:01 pm, Eric Jain [eric.j...@gmail.com](mailto:eric.j...@gmail.com) wrote:

> During development I frequently restart the application that I have  
> elasticsearch embedded in. I noticed that the last update to an index  
> is often lost--unless the indexes are flushed. Shouldn't close() be  
> enough?

Looking at the translog dir, here's what I see:

translog-1331003921694 (0KB)  
(update index)  
translog-1331003921694 (3KB)  
(unchanged after a minute; restart)  
translog-1331003921695 (0KB)  
translog-1331003921694.recovering (3KB)  
(unchanged after a minute; restart)  
translog-1331003921695 (0KB)  
translog-1331003921695.recovering (0KB)  
(unchanged after a minute; restart)  
translog-1331003921695 (0KB)  
translog-1331003921695.recovering (0KB)  
(update index)  
translog-1331003921695 (7KB)  
translog-1331003921695.recovering (0KB)  
(unchanged after a minute; restart)  
translog-1331003921695 (0KB)  
translog-1331003921695.recovering (0KB)  
...

---

<div class="post-metadata">

**Author:** ![kimchy](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/kimchy/32/44952_2.png) [@kimchy](https://discuss.elastic.co/u/kimchy)\
**Post date:** [March 7, 2012, 11:16am UTC](https://discuss.elastic.co/t/losing-data-if-i-dont-flush/6920/3 "2012-03-07T11:16:12Z")

</div>

It shouldn't happen, can you create a simple test case that shows it? Also, which version are you using?

On Tuesday, March 6, 2012 at 10:39 PM, Eric Jain wrote:

> On Mar 6, 12:01 pm, Eric Jain \<[eric.j...@gmail.com](mailto:eric.j...@gmail.com) ([http://gmail.com](http://gmail.com))\> wrote:
> 
> > During development I frequently restart the application that I have  
> > elasticsearch embedded in. I noticed that the last update to an index  
> > is often lost--unless the indexes are flushed. Shouldn't close() be  
> > enough?
> 
> Looking at the translog dir, here's what I see:
> 
> translog-1331003921694 (0KB)  
> (update index)  
> translog-1331003921694 (3KB)  
> (unchanged after a minute; restart)  
> translog-1331003921695 (0KB)  
> translog-1331003921694.recovering (3KB)  
> (unchanged after a minute; restart)  
> translog-1331003921695 (0KB)  
> translog-1331003921695.recovering (0KB)  
> (unchanged after a minute; restart)  
> translog-1331003921695 (0KB)  
> translog-1331003921695.recovering (0KB)  
> (update index)  
> translog-1331003921695 (7KB)  
> translog-1331003921695.recovering (0KB)  
> (unchanged after a minute; restart)  
> translog-1331003921695 (0KB)  
> translog-1331003921695.recovering (0KB)  
> ...

---

<div class="post-metadata">

**Author:** ![Eric\_Jain](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/eric_jain/32/834_2.png) [@Eric\_Jain](https://discuss.elastic.co/u/Eric_Jain)\
**Post date:** [March 7, 2012, 6:58pm UTC](https://discuss.elastic.co/t/losing-data-if-i-dont-flush/6920/4 "2012-03-07T18:58:37Z")

</div>

On Wed, Mar 7, 2012 at 03:16, Shay Banon [kimchy@gmail.com](mailto:kimchy@gmail.com) wrote:

> It shouldn't happen, can you create a simple test case that shows it? Also,  
> which version are you using?

0.19.0

I haven't been able to reproduce the issue with a simple test case  
yet. The index only gets into the "updates are lost unless flushed"  
after a while...

While writing a test case, I encountered another oddity that I haven't  
seen otherwise: If the number\_of\_replicas for an index is set to more  
than 0, the cluster state doesn't ever seem to get past YELLOW:

[gist:1995058 · GitHub](https://gist.github.com/1995058)

What's wrong with this code?

---

<div class="post-metadata">

**Author:** ![kimchy](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/kimchy/32/44952_2.png) [@kimchy](https://discuss.elastic.co/u/kimchy)\
**Post date:** [March 7, 2012, 8:48pm UTC](https://discuss.elastic.co/t/losing-data-if-i-dont-flush/6920/5 "2012-03-07T20:48:10Z")

</div>

If you have a single node, and create an index with index.number\_of\_replicas \> 0, the health will be yellow (since not all replicas are allocated). It has always been like that.

On Wednesday, March 7, 2012 at 8:58 PM, Eric Jain wrote:

> On Wed, Mar 7, 2012 at 03:16, Shay Banon \<[kimchy@gmail.com](mailto:kimchy@gmail.com) ([mailto:kimchy@gmail.com](mailto:kimchy@gmail.com))\> wrote:
> 
> > It shouldn't happen, can you create a simple test case that shows it? Also,  
> > which version are you using?
> 
> 0.19.0
> 
> I haven't been able to reproduce the issue with a simple test case  
> yet. The index only gets into the "updates are lost unless flushed"  
> after a while...
> 
> While writing a test case, I encountered another oddity that I haven't  
> seen otherwise: If the number\_of\_replicas for an index is set to more  
> than 0, the cluster state doesn't ever seem to get past YELLOW:
> 
> [gist:1995058 · GitHub](https://gist.github.com/1995058)
> 
> What's wrong with this code?

---

<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, 3:36am UTC](https://discuss.elastic.co/t/losing-data-if-i-dont-flush/6920/6 "2017-07-06T03:36:48Z")

</div>


