Elasticsearch 2.1: Result window is too large (index.max_result_window)

后端 未结 7 1930
余生分开走
余生分开走 2020-11-28 05:18

We retrieve information from Elasticsearch 2.1 and allow the user to page thru the results. When the user requests a high page number we get the following error message:

相关标签:
7条回答
  • 2020-11-28 05:54

    Use the Scroll API to get more than 10000 results.

    Scroll example in ElasticSearch NEST API

    I have used it like this:

    private static Customer[] GetCustomers(IElasticClient elasticClient)
    {
        var customers = new List<Customer>();
        var searchResult = elasticClient.Search<Customer>(s => s.Index(IndexAlias.ForCustomers())
                              .Size(10000).SearchType(SearchType.Scan).Scroll("1m"));
    
        do
        {
            var result = searchResult;
            searchResult = elasticClient.Scroll<Customer>("1m", result.ScrollId);
            customers.AddRange(searchResult.Documents);
        } while (searchResult.IsValid && searchResult.Documents.Any());
    
        return customers.ToArray();
    }
    
    0 讨论(0)
提交回复
热议问题