# Elasticsearch UpdateByQuery index refresh issue

**URL:** <https://discuss.elastic.co/t/elasticsearch-updatebyquery-index-refresh-issue/130893>\
**Category:** Elasticsearch\
**Created:** [May 7, 2018, 6:35pm UTC](https://discuss.elastic.co/t/elasticsearch-updatebyquery-index-refresh-issue/130893 "2018-05-07T18:35:53Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Adriano](https://avatars.discourse-cdn.com/v4/letter/a/c37758/32.png) [@Adriano](https://discuss.elastic.co/u/Adriano)\
**Post date:** [May 7, 2018, 6:35pm UTC](https://discuss.elastic.co/t/elasticsearch-updatebyquery-index-refresh-issue/130893/1 "2018-05-07T18:35:54Z")

</div>

I am working with Elasticsearch(ES) 5 and NEST 5 on C#

I have a workflow implemented using ES. Simplifiying the workflow has 2 steps.

Step 1: I generate the recipients for a message using an UpdateByQuery statement base on some criteria.

Step 2: I query all recipients generated on step 1 to actualy deliver the message.

The problem I am facing is that some times the first step run so fast that when the second step runs the index is not refresh yet, so no recipient is found.

I tried setting "WaitForCompletion(true)" (default on Nest) but I get the same result. Also I notice that UpdateByQuery does not support refresh=wait\_for so not sure how to do this.

My update by query looks like this:

```
query
.Index(allIndexesStr)

// Exclude all contact in this list
.Query(q =>
    ...
)
.WaitForCompletion(true)
// Update script
.Script(script => script
    .Inline(scriptStr)
    .Params(p =>
        ...
    )
)
.Routing(customerSiteId.ToString());

```

My search look like this:

```
search
.Index(allIndexesStr)
.Size(size)
.Scroll(timeout)
.Query(q =>
    ...
)
.Sort(sort => sort
    .Ascending("contactGuid.keyword")
)
.Routing(customerSiteId.ToString());

```

So I am wondering how is the propper way to solve this issue using ES...

Any help will be appreciate

---

<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:** [June 4, 2018, 6:35pm UTC](https://discuss.elastic.co/t/elasticsearch-updatebyquery-index-refresh-issue/130893/2 "2018-06-04T18:35:57Z")

</div>

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