# How to use "flush" for delete-by-query from Java API?

**URL:** <https://discuss.elastic.co/t/how-to-use-flush-for-delete-by-query-from-java-api/39515>\
**Category:** Elasticsearch\
**Created:** [January 19, 2016, 9:02am UTC](https://discuss.elastic.co/t/how-to-use-flush-for-delete-by-query-from-java-api/39515 "2016-01-19T09:02:31Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![drippel](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/drippel/32/44823_2.png) [@drippel](https://discuss.elastic.co/u/drippel)\
**Post date:** [January 19, 2016, 9:02am UTC](https://discuss.elastic.co/t/how-to-use-flush-for-delete-by-query-from-java-api/39515/1 "2016-01-19T09:02:32Z")

</div>

When using the new delete-by-query plugin functionality, even when the operation succeeds - it takes time till the result can actually be observed. This is an issue when running unit-tests.  
I thought that using the "flush" functionality may be beneficial for that (or maybe "force merge"?) but I could find only a [scripting API](https://www.elastic.co/guide/en/elasticsearch/reference/current/indices-flush.html) for this.  
What is the Java way to do it?

---

<div class="post-metadata">

**Author:** ![mikemccand](https://avatars.discourse-cdn.com/v4/letter/m/f04885/32.png) [@mikemccand](https://discuss.elastic.co/u/mikemccand)\
**Post date:** [January 19, 2016, 3:35pm UTC](https://discuss.elastic.co/t/how-to-use-flush-for-delete-by-query-from-java-api/39515/2 "2016-01-19T15:35:43Z")

</div>

Actually you want to use the `refresh` API, which makes all recent index changes visible to searching. `flush` is heavier, forcing an fsync of all written lucene files and clearing of Elasticsearch's transaction logs.

Don't do `forceMerge` 😉 That's very very heavy and very much overkill here.

---

<div class="post-metadata">

**Author:** ![drippel](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/drippel/32/44823_2.png) [@drippel](https://discuss.elastic.co/u/drippel)\
**Post date:** [January 20, 2016, 6:44am UTC](https://discuss.elastic.co/t/how-to-use-flush-for-delete-by-query-from-java-api/39515/3 "2016-01-20T06:44:27Z")

</div>

Thanks!

---

<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, 11:23pm UTC](https://discuss.elastic.co/t/how-to-use-flush-for-delete-by-query-from-java-api/39515/4 "2017-07-05T23:23:11Z")

</div>


