# Need help with the flush operation and lucene files

**URL:** <https://discuss.elastic.co/t/need-help-with-the-flush-operation-and-lucene-files/77271>\
**Category:** Elasticsearch\
**Created:** [March 3, 2017, 6:25am UTC](https://discuss.elastic.co/t/need-help-with-the-flush-operation-and-lucene-files/77271 "2017-03-03T06:25:43Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Godin](https://avatars.discourse-cdn.com/v4/letter/g/439d5e/32.png) [@Godin](https://discuss.elastic.co/u/Godin)\
**Post date:** [March 3, 2017, 6:25am UTC](https://discuss.elastic.co/t/need-help-with-the-flush-operation-and-lucene-files/77271/1 "2017-03-03T06:25:43Z")

</div>

I insert into 200000 docs into a index(called "test\_index",1 primary shard and 0 replica shard) using bulk function, each bulk request has 20000 docs. Then I flush all data into the disk( lucene file) with FlushRequest and close the index.

> ```
> FlushRequest flushRequest = new FlushRequest("test_index");
> flushRequest.force(true);
> transportClient.admin().indices().flush(flushRequest).get();
> 
> ```

Then I use IndexWriter to check the data immediately, I find the lucene directory's doc number sometimes is between 190000 and 200000 after a lot of experiments.

> ```
> > Directory directory = FSDirectory.open(Paths.get(shardDataPath));
> > IndexWriterConfig config = new IndexWriterConfig(new StandardAnalyzer());
> > IndexWriter indexWriter = new IndexWriter(directory,config);
> > int docsNumber = indexWriter.numDocs();
> > indexWriter.close();
> 
> ```

Why?I guess it's because the flush operation have not finished before returning the flush response? Thus, I got the incomplete data? Thanks a lot.

---

<div class="post-metadata">

**Author:** ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)\
**Post date:** [March 3, 2017, 7:23am UTC](https://discuss.elastic.co/t/need-help-with-the-flush-operation-and-lucene-files/77271/2 "2017-03-03T07:23:13Z")

</div>

I think you want to refresh not flush.

But why are you doing low level Lucene code?

---

<div class="post-metadata">

**Author:** ![Godin](https://avatars.discourse-cdn.com/v4/letter/g/439d5e/32.png) [@Godin](https://discuss.elastic.co/u/Godin)\
**Post date:** [March 3, 2017, 8:11am UTC](https://discuss.elastic.co/t/need-help-with-the-flush-operation-and-lucene-files/77271/4 "2017-03-03T08:11:12Z")

</div>

Hi,I need to copy the lucene file to hdfs for another program. I think it is flush operation, because I wanna make sure all the data are written into the lucene file after the flush.The refresh operation just makes the doc available for search,it does not make sure the doc are written to disk(lucene file).Right?Thanks a lot.

---

<div class="post-metadata">

**Author:** ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)\
**Post date:** [March 3, 2017, 10:55am UTC](https://discuss.elastic.co/t/need-help-with-the-flush-operation-and-lucene-files/77271/5 "2017-03-03T10:55:45Z")

</div>

Did you try the refresh I mentioned?

---

<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:** [March 31, 2017, 10:55am UTC](https://discuss.elastic.co/t/need-help-with-the-flush-operation-and-lucene-files/77271/6 "2017-03-31T10:55:52Z")

</div>

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