# BulkProcessor using BulkRequest with wait\_for

**URL:** <https://discuss.elastic.co/t/bulkprocessor-using-bulkrequest-with-wait-for/268308>\
**Category:** Elasticsearch\
**Created:** [March 25, 2021, 9:13am UTC](https://discuss.elastic.co/t/bulkprocessor-using-bulkrequest-with-wait-for/268308 "2021-03-25T09:13:16Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![jbalaguero](https://avatars.discourse-cdn.com/v4/letter/j/c68b51/32.png) [@jbalaguero](https://discuss.elastic.co/u/jbalaguero)\
**Post date:** [March 25, 2021, 9:13am UTC](https://discuss.elastic.co/t/bulkprocessor-using-bulkrequest-with-wait-for/268308/1 "2021-03-25T09:13:16Z")

</div>

Hello,

We are trying to set a "wait\_for" refresh policy for every bulk request we are performing. It seems the only way is setting this policy on the 'beforeBulk' method on the bulk listener in this way:

```auto
public void beforeBulk(long executionId, BulkRequest request) {`
  request.setRefreshPolicy(WriteRequest.RefreshPolicy.WAIT_UNTIL);`
}

```

The idea behind this is: we are performing searches on this index, but we want to hold a search if there are documents involved in it that were indexed by a previous bulk request but they have not been refreshed yet. Once these documents are refreshed, then the search will be executed.

Since the ES docs say:

- Never start multiple `refresh=wait_for` requests in a row. Instead batch them into a single bulk request with `refresh=wait_for` and Elasticsearch will start them all in parallel and return only when they have all finished.

We understand the above code is the right way to achieve this. Are we right?

Thanks,

Joan.

---

<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 25, 2021, 9:19am UTC](https://discuss.elastic.co/t/bulkprocessor-using-bulkrequest-with-wait-for/268308/2 "2021-03-25T09:19:29Z")

</div>

This looks correct to me.

---

<div class="post-metadata">

**Author:** ![jbalaguero](https://avatars.discourse-cdn.com/v4/letter/j/c68b51/32.png) [@jbalaguero](https://discuss.elastic.co/u/jbalaguero)\
**Post date:** [March 25, 2021, 9:49am UTC](https://discuss.elastic.co/t/bulkprocessor-using-bulkrequest-with-wait-for/268308/3 "2021-03-25T09:49:24Z")

</div>

Thanks David.

---

<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:** [April 22, 2021, 9:50am UTC](https://discuss.elastic.co/t/bulkprocessor-using-bulkrequest-with-wait-for/268308/4 "2021-04-22T09:50:04Z")

</div>

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