【问题标题】:Query all in ElasticSearch using Nest v. 2.1使用 Nest v. 2.1 在 ElasticSearch 中查询所有内容
【发布时间】:2016-03-30 14:09:57
【问题描述】:
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()

返回的调试信息是

“由不成功的低级别调用构建的无效 NEST 响应 POST: /_search\r\n# 此 API 调用的审核跟踪:\r\n - BadResponse: 节点:http://127.0.0.1:9200/ 接受:00:00:00.2964038\r\n# ServerError: 服务器错误:500 类型:search_phase_execution_exception 原因:\"all 分片失败\"\r\n# OriginalException: System.Net.WebException: The 远程服务器返回错误: (500) 内部服务器错误。\r\n at System.Net.HttpWebRequest.GetResponse()\r\n 在 Elasticsearch.Net.HttpConnection.Request[TReturn](RequestData 请求数据)在 C:\users\russ\source\elasticsearch-net\src\Elasticsearch.Net\Connection\HttpConnection.cs:line 138\r\n# 请求:\r\n\r\n# 响应:\r\n\r\n"

【问题讨论】:

  • 调试信息使查询期间在 elasticsearch 中似乎发生了一些事情,而不是在嵌套中。您是否尝试通过普通搜索 API 运行它?您应该能够从嵌套响应以及response.RequestInformation 中获取查询
  • 也许this 的回答会对你有所帮助。
  • 如果您在ConnectionSettings 上使用.DisableDirectStreaming(),您也可以在DebugInformation 中看到请求和响应(您可能只想使用.DisableDirectStreaming() 而在开发中而不是在生产中)

标签: elasticsearch nest


【解决方案1】:

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

来自 Elasticsearch 文档:

"注意from+size不能大于 index.max_result_window 索引设置,默认为 10,000。看 Scroll API 以更有效地进行深度滚动。”

参考:

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

【讨论】:

  • 我会试试的。在我使用 Nest 的旧测试中,我设置了 Take(100000) 并且它起作用了,所以我必须设置该设置以增加值 从上面的链接中,我还看到“滚动不是用于实时用户请求,而是用于处理大量数据”。我可能最终会在内存中缓存我的全部数据以将其全部提取,然后只需使用弹性进行实际搜索
  • 您的旧测试是否针对旧版本的 Elasticsearch 运行?如果我没记错的话,他们在 2.x 的某个地方引入了限制。我不确定您的用例是什么,但您需要一次返回 100.000 个结果吗??
  • 我以为是 2.x。我可能将配置文件中的 index.max_result_window_index 设置为荒谬的。是的......公司老板想要什么,公司老板就得到了:)我已经提出了反对它的理由。
  • 客户.. ;) 祝你的项目好运!
猜你喜欢
  • 1970-01-01
  • 2015-06-05
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2023-03-31
相关资源
最近更新 更多