Similar questions were asked before and a furnished the primitive code below based on similar answers. My requirement is to 'loop'/scroll over all currently indexed documents in elastic search to obtain a list of their unique ids. The code below works fine for the first 1000 documents but then gets stuck in the do while loop without retrieving new ids. It may not scroll further? Could someone please be so kind and point out the error/issue? Thanks!
var searchResult = client.Search<Document>(
s => s
.AllTypes()
.From(0)
.Size(1000)
.MatchAll()
.Scroll("10s")
);
IBulkResponse indexResult = null;
do
{
var result = searchResult;
searchResult = client.Scroll<Document>("10s", result.ScrollId);
if (searchResult.Documents.Any())
{
foreach (var doc in searchResult.Documents)
{
var id = doc.some_id.Trim();
if (id_list.Contains(id) == false)
{
id_list.Add(id);
Console.WriteLine(id_list.Count);
}
}
}
page++;
} while (searchResult.IsValid && indexResult != null && indexResult.IsValid && searchResult.Documents.Any());