0

我正在编写 NEST 代码以从弹性搜索中检索大量数据。现在我正在使用 Scroll 功能以同步方式从集群中获取所有记录。下面是代码片段。

var response = elasticClient.Search<IndexType>(s => s                                 
                                    .Source(sf => sf
                                    .Includes(i => i
                                               .Fields(                                                          
                                                          f => f.DateTime
                                                      )
                                             )
                                            )
                                            .Scroll("1m") 
                                            .From(0)
                                            .Size(9999)
                                    .Query(q => q

                                         .DateRange(r => r
                                             .Field(f => f.DateTime)
                                             .GreaterThanOrEquals(new DateTime(2017, 01, 01))
                                             .LessThan(new DateTime(2017, 04, 01))
                                         )
                                         )                                               
                                          .Sort(q => q.Ascending(u => u.DateTime))
                                         );


            List<IndexType> allData = new List<IndexType>();                                         
            while (response.Documents.Any())
            {
                foreach (var document in response.Documents)
                {
                    allData.Add(document);
                }                    

                response = elasticClient.Scroll<RACType>("1m", response.ScrollId);
            }

现在代替 while 循环(批量获取 10000 条记录,直到获取所有文档),是否有任何机制可以异步/并行执行此操作,这样我就不必等待所有迭代?

4

0 回答 0