protected ConcurrentDictionary <string, T> GetDicObjectScroll <T>(string _default_index, QueryContainer query, SourceFilter so) where T : class { try { var numberOfShards = 5; var seenSlices = new ConcurrentBag <int>(); ConcurrentDictionary <string, T> bag = new ConcurrentDictionary <string, T>(); ScrollAllRequest req = new ScrollAllRequest("1m", numberOfShards); SearchRequest sReq = new SearchRequest(_default_index); sReq.Query = query; if (so != null) { sReq.Source = so; } req.Search = sReq; req.MaxDegreeOfParallelism = numberOfShards / 2; var scrollObserver = client.ScrollAll <T>(req).Wait(TimeSpan.FromMinutes(5), r => { seenSlices.Add(r.Slice); foreach (var item in r.SearchResponse.Hits) { bag.TryAdd(item.Id, item.Source); } }); return(bag); } catch { } return(null); }
protected ConcurrentBag <T> GetObjectScroll <T>(string _default_index, QueryContainer query, SourceFilter so, List <ISort> lSort = null, string routing = "") where T : class { try { var numberOfShards = 5; var seenSlices = new ConcurrentBag <int>(); ConcurrentBag <T> bag = new ConcurrentBag <T>(); ScrollAllRequest req = new ScrollAllRequest("5m", numberOfShards); SearchRequest sReq = new SearchRequest(_default_index); if (!string.IsNullOrEmpty(routing)) { sReq.Routing = routing; } sReq.Query = query; if (lSort != null) { sReq.Sort = lSort; } if (so != null) { sReq.Source = so; } req.Search = sReq; req.MaxDegreeOfParallelism = numberOfShards;// / 2; sReq.Size = 10000; var scrollObserver = client.ScrollAll <T>(req).Wait(TimeSpan.FromMinutes(20), r => { seenSlices.Add(r.Slice); if (lSort == null) { System.Threading.Tasks.Parallel.ForEach(r.SearchResponse.Documents, new System.Threading.Tasks.ParallelOptions { MaxDegreeOfParallelism = 10 }, item => { bag.Add(item); }); } else { foreach (var item in r.SearchResponse.Documents) { bag.Add(item); } } }); return(bag); } catch { } return(null); }