Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
Nest Elastic 5 Scan - Scroll example
var n = 100;
ElasticClient client = new ElasticClient(new Uri("http://localhost:9200"));
var result = client.Search<IndexType>(x =>
.Index("index")
.Type("type")
.From(0)
.Size(n)
.Scroll("12s"));
if (!response1.IsValid || string.IsNullOrEmpty(response1.ScrollId))
{
throw new Exception(response1.ServerError.Error.Reason);
}
else
{
var fromElement = 0;
var looping = true;
var scrollid = response1.ScrollId;
var Results = new List<IndexType>();
if (response1.Documents.Any())
{
Results.AddRange(response1.Documents);
}
while (looping)
{
var results3 = client.Scroll<IndexType>("60s", scrollid);
if (results3.IsValid)
{
Results.AddRange(results3.Documents);
scrollid = results3.ScrollId;
}
if (results3.Documents.Count() < n)
looping = false;
fromElement += n;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment