简体   繁体   English

如何使用耐嚼的宝石使用Elasticsearch滚动API?

[英]How to use elasticsearch scroll api using chewy gem?

I am using 'chewy' gem for elasticsearch in my ROR application. 我在我的ROR应用程序中使用'耐嚼'宝石进行弹性搜索。 But I didn't find any documentation for elasticsearch scroll api. 但我没有找到elasticsearch scroll api的任何文档。 I'm getting below error when I jump to last page of the records. 当我跳到记录的最后一页时,我遇到了错误。

[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 [19450]. 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 parameter."}],"type":"search_phase_execution_exception","reason":"all shards failed",
"phase":"query","grouped":true,"failed_shards":[{"shard":0,"index":"recordings","node":"tgLqH_wwRUG6NmY0PCB0nA",
"reason":{"type":"query_phase_execution_exception","reason":"Result window is too large, from + size must
 be less than or equal to: [10000] but was [19450]. 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
 parameter."}}]},"status":500}

Is there any way to implement elasticsearch scroll api in chewy gem or is their any other option? 有什么方法可以在耐嚼的gem中实现elasticsearch滚动api还是它们有其​​他选择?

Just make the query size smaller and you can use scroll in batches: 只需缩小查询大小,您就可以批量使用滚动:

  # @example Call the `scroll` API until all the documents are returned
  #
  #     # Index 1,000 documents
  #     client.indices.delete index: 'test'
  #     1_000.times do |i| client.index index: 'test', type: 'test', id: i+1, body: {title: "Test #{i}"} end
  #     client.indices.refresh index: 'test'
  #
  #     # Open the "view" of the index by passing the `scroll` parameter
  #     # Sorting by `_doc` makes the operations faster
  #     r = client.search index: 'test', scroll: '1m', 
              body: {size: 100, sort: ['_doc']}
  #
  #     # Display the initial results
  #     puts "--- BATCH 0 -------------------------------------------------"
  #     puts r['hits']['hits'].map { |d| d['_source']['title'] }.inspect
  #
  #     # Call the `scroll` API until empty results are returned
  #     while r = client.scroll(scroll_id: r['_scroll_id'], scroll: '5m') and not r['hits']['hits'].empty? do
  #       puts "--- BATCH #{defined?($i) ? $i += 1 : $i = 1} -------------------------------------------------"
  #       puts r['hits']['hits'].map { |d| d['_source']['title'] }.inspect
  #       puts
  #     end

Example taken from here using the Elasticsearch DSL Gem 使用Elasticsearch DSL Gem此处获取的示例

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM