Ruby on Rails - ElasticSearch Result窗口太大

时间:2017-12-18 17:15:30

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

我正在使用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,或者这是解决此问题的正确方法?

1 个答案:

答案 0 :(得分:2)

您真的需要让用户对48000个条目进行深度分页吗?这里的问题在于elasticsearch如何在内部工作。如果查询第N个结果,elasticsearch必须获取第一个N-1结果,以便丢弃它们。这就是为什么这些查询会让更深层次的用户分页更加昂贵。

Scroll API可能非常合适,如果你只有很少的用户并且他们都表现得很好(因为他们没有同时打开多个滚动上下文并让它们永远保持活着),但可能没有。

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