Created
October 31, 2017 13:12
-
-
Save Cicciokr/5300ae6e0d3690e87af02474d4890617 to your computer and use it in GitHub Desktop.
Nest Elastic 5 Scan - Scroll example
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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