我想按索引获取我的所有文档。我尝试了以下方法:
var response = client.Search(s => s.Index(“ test”)。MatchAll());
该响应返回“成功操作”,但是尽管该索引下有许多文档,但它没有找到任何文档。
答案 0 :(得分:0)
要获取索引中的所有 个文档,您需要使用Scroll API。请注意,根据我们讨论的文档数量,您可能会通过多个HTTP请求/响应分批接收它们。
NEST中有一个帮助程序,可以简化此操作,ScrollAll()
Time processTimePerScroll = "20s";
int numberOfSlices = Environment.ProcessorCount;
var scrollAllObservable = client.ScrollAll<Person>(processTimePerScroll, numberOfSlices, sc => sc
.MaxDegreeOfParallelism(numberOfSlices)
.Search(s => s
.Query(q => q
.MatchAll()
)
)
)
var waitHandle = new ManualResetEvent(false);
Exception exception = null;
var scrollAllObserver = new ScrollAllObserver<Person>(
onNext: response =>
{
// do something with the documents
var documents = response.SearchResponse.Documents;
},
onError: e =>
{
exception = e;
waitHandle.Set();
},
onCompleted: () => waitHandle.Set()
);
scrollAllObservable.Subscribe(scrollAllObserver);
waitHandle.WaitOne();
if (exception != null)
{
throw exception;
}