Ruby on Rails - ElasticSearch 结果 window 太大
Ruby on Rails - ElasticSearch Result window is too large
我正在使用 elasticsearch-rails gem。
当用户在我的分页中单击更高的页码 link 时,我收到以下错误。这是错误:
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 或者这是否是解决此问题的正确方法?
你真的需要让用户分页 48000 个条目吗?这里的问题在于 elasticsearch 内部是如何工作的。如果您查询第 N 个结果,elasticsearch 必须获取前 N-1 个结果并丢弃它们。这就是为什么用户分页越深,此类查询的成本就越高。
Scroll API 可能是一个不错的选择,如果你只有很少的用户并且他们都表现良好(因为他们不会同时打开无数的滚动上下文并让他们永远活着)但可能不会。
如果可行,请将您的分页限制为这 10k 个结果(或更少),并鼓励您的用户在他们的查询中更加具体。如果没有,请准备好扩展集群中的硬件(内存!)并进行长时间的 运行 查询。
我正在使用 elasticsearch-rails gem。
当用户在我的分页中单击更高的页码 link 时,我收到以下错误。这是错误:
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 或者这是否是解决此问题的正确方法?
你真的需要让用户分页 48000 个条目吗?这里的问题在于 elasticsearch 内部是如何工作的。如果您查询第 N 个结果,elasticsearch 必须获取前 N-1 个结果并丢弃它们。这就是为什么用户分页越深,此类查询的成本就越高。
Scroll API 可能是一个不错的选择,如果你只有很少的用户并且他们都表现良好(因为他们不会同时打开无数的滚动上下文并让他们永远活着)但可能不会。
如果可行,请将您的分页限制为这 10k 个结果(或更少),并鼓励您的用户在他们的查询中更加具体。如果没有,请准备好扩展集群中的硬件(内存!)并进行长时间的 运行 查询。