【问题标题】:Ruby on Rails - ElasticSearch Result window is too largeRuby on Rails - ElasticSearch 结果窗口太大
【发布时间】:2017-12-18 17:15:29
【问题描述】:

我正在使用 elasticsearch-rails gem。

当用户在我的分页中单击更高页码的链接时,我收到以下错误。这是错误:

Elasticsearch::Transport::Transport::Errors::InternalServerError ([500] {"error":{"root_cause":[{"type":"query_phase_execution_exception","reason":"Result window is too large, from + size must be less than or equal to: [10000] but was [48700]. See the scroll api for a more efficient way to request large data sets. This limit can be set by changing the [index.max_result_window] index level setting."}],"type":"search_phase_execution_exception","reason":"all shards failed","phase":"query","grouped":true,"failed_shards":[{"shard":0,"index":"products","node":"fNcaDjwzRRGu2fq0KjTWUQ","reason":{"type":"query_phase_execution_exception","reason":"Result window is too large, from + size must be less than or equal to: [10000] but was [48700]. See the scroll api for a more efficient way to request large data sets. This limit can be set by changing the [index.max_result_window] index level setting."}}]},"status":500}):

我在哪里设置 index.max_result_window 或者这甚至是解决此问题的正确方法?

【问题讨论】:

标签: ruby-on-rails elasticsearch elasticsearch-rails


【解决方案1】:

您真的需要让用户对 48000 个条目进行深度分页吗?这里的问题在于 elasticsearch 内部是如何工作的。如果您查询第 N 个结果,elasticsearch 必须同时获取前 N-1 个结果才能丢弃它们。这就是为什么随着用户分页越深,此类查询的开销就越大。

滚动 API 可能是一个很好的选择,如果您只有很少的用户并且他们都表现良好(因为他们不会同时打开无数滚动上下文并使它们永远保持活动状态)但可能不是。

如果可以选择,请将您的分页限制为这 10k 个结果(甚至更少),并鼓励您的用户在他们的查询中更加具体。如果没有,请准备好扩展集群中的硬件(内存!)并进行长时间运行的查询。

【讨论】:

  • 决定限制分页。将分页限制为 400 页,每页 25 条记录。似乎工作得很好。谢谢!
猜你喜欢
  • 2016-02-24
  • 2020-02-16
  • 2011-12-08
  • 2016-02-01
  • 1970-01-01
  • 2013-12-23
  • 2015-08-13
  • 1970-01-01
  • 2020-10-28
相关资源
最近更新 更多