使用 Nest v. 2.1 在 ElasticSearch 中查询所有内容

Query all in ElasticSearch using Nest v. 2.1

var settings = new ConnectionSettings(Constants.ElasticSearch.Node);
var client = new ElasticClient(settings);

var response = client.Search<DtoTypes.Customer.SearchResult>(s =>
    s.From(0)
    .Size(100000)
    .Query(q => q.MatchAll()));

它在文件较小时有效,但我想检索包含超过 100k 文档的索引中的所有文档。必须是我缺少的配置设置才能绕过限制。我也试过 Take() 而不是 Size()

返回的调试信息是

"Invalid NEST response built from a unsuccesful low level call on POST: /_search\r\n# Audit trail of this API call:\r\n - BadResponse: Node: http://127.0.0.1:9200/ Took: 00:00:00.2964038\r\n# ServerError: ServerError: 500Type: search_phase_execution_exception Reason: \"all shards failed\"\r\n# OriginalException: System.Net.WebException: The remote server returned an error: (500) Internal Server Error.\r\n at System.Net.HttpWebRequest.GetResponse()\r\n at Elasticsearch.Net.HttpConnection.Request[TReturn](RequestData requestData) in C:\users\russ\source\elasticsearch-net\src\Elasticsearch.Net\Connection\HttpConnection.cs:line 138\r\n# Request:\r\n\r\n# Response:\r\n\r\n"

Elasticsearch 对其允许的结果数量有软限制 return。如果你想要一次性获得超过 10.000 个结果,你应该使用扫描和滚动功能 :)

来自 Elasticsearch 文档:

"Note that from + size can not be more than the index.max_result_window index setting which defaults to 10,000. See the Scroll API for more efficient ways to do deep scrolling."

参考:

https://www.elastic.co/guide/en/elasticsearch/reference/current/search-request-from-size.html https://www.elastic.co/guide/en/elasticsearch/reference/current/search-request-scroll.html https://nest.azurewebsites.net/nest/search/scroll.html