# The new item is not fetching with search result immediately after add

**URL:** <https://discuss.elastic.co/t/the-new-item-is-not-fetching-with-search-result-immediately-after-add/110039>\
**Category:** Elasticsearch\
**Created:** [December 3, 2017, 9:47am UTC](https://discuss.elastic.co/t/the-new-item-is-not-fetching-with-search-result-immediately-after-add/110039 "2017-12-03T09:47:50Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![nmathur](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/nmathur/32/21451_2.png) [@nmathur](https://discuss.elastic.co/u/nmathur)\
**Post date:** [December 3, 2017, 9:47am UTC](https://discuss.elastic.co/t/the-new-item-is-not-fetching-with-search-result-immediately-after-add/110039/1 "2017-12-03T09:47:50Z")

</div>

Hello,

I am working on a very small sample for CURD operations in elasticsearch. I am using Nest library in my [ASP.NET](http://ASP.NET) MVC web application. The problem I am setting is that when I add any item and then redirect to list (search result) the the newly added item never exist in result. When I refresh the page (query again) then only I am able to get the newly added item.

Here I am sharing the methods:  
Get:

> ```
> public IEnumerable<Department> GetDepartments()
> {
> var searchResponse = ESClient().Search<Department>(s => s
> .From(0)
> .Size(200)
> .Index("myindex").Type("department"));
> return searchResponse.Documents;
> }
> 
> ```

Add:

> public string CreateDepartment(Department dept)  
> {  
> var response = ESClient().Index(dept, i =\> i.Index("myindex").Type("department").Id(dept.DepartmentId));  
> return response.IsValid == false ? response.OriginalException.Message : string.Empty;  
> }

When my controller post the form and call `CreateDepartment`, code successfully runs and I return to the action which calls `GetDepartments`, but this result never include my new item.

Hope my issue is clear. Please help and guide ..why elasticsearch showing this behavior .. how to get the new item in search.

---

<div class="post-metadata">

**Author:** ![warkolm](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/warkolm/32/39224_2.png) [@warkolm](https://discuss.elastic.co/u/warkolm)\
**Post date:** [December 3, 2017, 9:50am UTC](https://discuss.elastic.co/t/the-new-item-is-not-fetching-with-search-result-immediately-after-add/110039/2 "2017-12-03T09:50:28Z")

</div>

Have a read of [https://www.elastic.co/guide/en/elasticsearch/guide/2.x/near-real-time.html#near-real-time](https://www.elastic.co/guide/en/elasticsearch/guide/2.x/near-real-time.html#near-real-time), it's still valid for 5 and 6.

---

<div class="post-metadata">

**Author:** ![nmathur](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/nmathur/32/21451_2.png) [@nmathur](https://discuss.elastic.co/u/nmathur)\
**Post date:** [December 3, 2017, 9:52am UTC](https://discuss.elastic.co/t/the-new-item-is-not-fetching-with-search-result-immediately-after-add/110039/3 "2017-12-03T09:52:49Z")

</div>

Thanks for quick response.

So, should I refresh after add/update operations?

---

<div class="post-metadata">

**Author:** ![warkolm](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/warkolm/32/39224_2.png) [@warkolm](https://discuss.elastic.co/u/warkolm)\
**Post date:** [December 3, 2017, 9:53am UTC](https://discuss.elastic.co/t/the-new-item-is-not-fetching-with-search-result-immediately-after-add/110039/4 "2017-12-03T09:53:24Z")

</div>

That is correct.

---

<div class="post-metadata">

**Author:** ![nmathur](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/nmathur/32/21451_2.png) [@nmathur](https://discuss.elastic.co/u/nmathur)\
**Post date:** [December 3, 2017, 10:20am UTC](https://discuss.elastic.co/t/the-new-item-is-not-fetching-with-search-result-immediately-after-add/110039/6 "2017-12-03T10:20:55Z")

</div>

The post is suggesting not to refresh, what should I do than .. as a user I will accept that the added item should appear in the list .. any suggestions.

---

<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:** [December 3, 2017, 10:31am UTC](https://discuss.elastic.co/t/the-new-item-is-not-fetching-with-search-result-immediately-after-add/110039/7 "2017-12-03T10:31:57Z")

</div>

```
refresh=wait_for
```

---

<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:** [December 31, 2017, 10:43am UTC](https://discuss.elastic.co/t/the-new-item-is-not-fetching-with-search-result-immediately-after-add/110039/8 "2017-12-31T10:43:49Z")

</div>

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