首页 > 解决方案 > 无需滚动即可获取文档属性值 - 下一个弹性搜索

问题描述

我已经用这种简化的结构索引了文档:

public class Document
{
    public string Id { get; set; }
    public string x { get; set; }

}

我正在像这样搜索它们:

var initialResponse = client.Search<Document>(s => s.From(0)
    .Size(100).Scroll(scrollTimeout)
    .Query(q => q
        .MatchPhrase(c => c
            .Field(p => p.Attachment.Content)
            .Analyzer("standard")
            .Boost(1.1)
            .Query(searchTerm)
        ))); 

然后遍历文档(更多代码在这里)。这显然需要时间,我想知道是否可以在一个有效负载中获得匹配文档的所有 ID 甚至更好的 x 值?

谢谢!

标签: c#elasticsearchnest

解决方案


Elasticsearch 有index.max_result_window一个默认值为 10,000 的设置。

这是您可以在单个请求中检索的最大文档数。如果你想获得更多——你需要使用scrollAPI search_after,就像你已经做的那样。


推荐阅读