Hello,
I am working on a very small sample for CURD operations in elasticsearch. I am using Nest library in my 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.