Skip to content

Instantly share code, notes, and snippets.

@Cicciokr
Created October 31, 2017 13:12
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Cicciokr/5300ae6e0d3690e87af02474d4890617 to your computer and use it in GitHub Desktop.
Save Cicciokr/5300ae6e0d3690e87af02474d4890617 to your computer and use it in GitHub Desktop.
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