Hello Everyone,
Currently, I am using ScrollAll Method Of NEST Client to retrieve millions of records from elastic search. Below I have mentioned Code for this:
var numberOfShards=3;
objElasticClient.ScrollAll<PubmedIndexFields>("1m", numberOfShards, s => s
.MaxDegreeOfParallelism(numberOfShards / 2)
.Search(search => search
.Query(
q => q.QueryString(c => c
.Boost(1.1)
.Query(query.ToString())
.Analyzer(ElasticIndexConfiguration.CustomAnalyzerName)
.AllowLeadingWildcard()
)).Size(PageSize)
)
).Wait(TimeSpan.FromMinutes(5), r =>
{
var lstrecords = r.SearchResponse.Documents.ToList<PubmedIndexFields>();
TaskPool.AddRange(lstrecords.Select((t, i) =>
Task<List<IndexEntityFields>>.Factory.StartNew((obj) =>
{
tokenSource.Token.ThrowIfCancellationRequested();
var loc = (int)obj;
var lstobject = lstrecords.ElementAt(loc);
var indexEntityFieldses = new List<IndexEntityFields>();
var op = new IndexEntityOperation();
op.Parse_ElasticSearch(lstobject);
indexEntityFieldses.Add(op.Fields);
return indexEntityFieldses;
}, i, tokenSource.Token)));
Interlocked.Add(ref seenDocuments, r.SearchResponse.Hits.Count);
}
But Sometimes I did not get the proper result set.