【问题标题】:How to use the NEST ".net client" for Elasticsearch to paginate through all the records?如何使用 Elasticsearch 的 NEST“.net 客户端”对所有记录进行分页?
【发布时间】:2021-07-15 23:54:16
【问题描述】:

我正在尝试使用C# .net client for Elasticsearch NEST 对所有可用记录进行分页。

我想一次从服务器 5000 获取所有 id 的列表。所以我得到的第一个请求是 0-5000,下一个请求是 5001-10000,然后是 10001-15000....

看来我应该使用search_after API 来获取记录,但不知道如何检索数据。

这是我尝试做的事情,但我觉得我不明白我在做什么以及如何提出多个请求..

var products = await elasticClient.SearchAsync<Product>(x =>  
    x.Source(s => s.Includes(se => se.Field(sef => sef.Id))) // all I need back is the "id" field
     .Sort(srt => srt.Ascending(p => p.Id)) // we can sort the ids
     .SearchAfter(5000, "get list of ids??"); // I have no idea what parameters to provide this method!
);

如何使用 .net 库一次循环遍历所有可用的 ID“5000”个 ID?

【问题讨论】:

    标签: c# .net elasticsearch nest elasticsearch-7


    【解决方案1】:

    用 pageNumber 参数试试这个:

    var products = await elasticClient.SearchAsync<Product>(x =>  
        x.Source(s => s.Includes(se => se.Field(sef => sef.Id)))
        .From(5000*(pageNumber-1))
        .Size(5000)
        .Sort(srt => srt.Ascending(p => p.Id))
    );
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2017-11-19
      • 2017-12-22
      • 2015-02-19
      • 2012-09-23
      • 1970-01-01
      • 2013-04-26
      • 2013-12-14
      • 1970-01-01
      相关资源
      最近更新 更多