[英]How to use the NEST “.net client” for Elasticsearch to paginate through all the records?
I am trying to use the C# .net client for Elasticsearch NEST to paginate through all the available records.我正在尝试使用Elasticsearch NEST的C# .net 客户端对所有可用记录进行分页。
I want to get a list of all ids from the server 5000 at a time.我想一次从服务器 5000 获取所有 ID 的列表。 So the very first request I get 0-5000, next request 5001-10000, then 10001-15000....所以我得到的第一个请求是 0-5000,下一个请求是 5001-10000,然后是 10001-15000....
It seems that I should be using the search_after API to get the records but puzzled on how to retrieve the data.似乎我应该使用search_after API 来获取记录,但对如何检索数据感到困惑。
Here is what I tried to do, but I feel that I am not understanding what I am doing and how can I make multiple requests..这是我尝试做的事情,但我觉得我不明白我在做什么以及如何提出多个请求。
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!
);
How can I use the .net library to loop over all available ids "5000" ids at a time?如何使用 .net 库一次遍历所有可用的 ID“5000”ID?
Try this with pageNumber param:用 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))
);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.