Skip to content

Commit 7cfb327

Browse files
committed
[DOCS] Adds docs for Scroll Helper
1 parent 7b623f9 commit 7cfb327

File tree

3 files changed

+43
-1
lines changed

3 files changed

+43
-1
lines changed

Diff for: docs/helpers.asciidoc

+38-1
Original file line numberDiff line numberDiff line change
@@ -59,4 +59,41 @@ helper.ingest(documents) { |_, docs| puts "Ingested #{docs.count} documents" }
5959

6060
=== Scroll Helper
6161

62-
=== Point in Time Helper
62+
This helper provides an easy way to get results from a Scroll.
63+
64+
To use the ScrollHelper, you need to require it in your code:
65+
66+
[source,ruby]
67+
----
68+
require 'elasticsearch/helpers/scroll_helper'
69+
----
70+
71+
You need to instantiate a ScrollHelper with a client, an index, and a body (with the scroll API parameters) which will be used in every following scroll request:
72+
73+
[source,ruby]
74+
----
75+
client = Elasticsearch::Client.new
76+
scroll_helper = Elasticsearch::Helpers::ScrollHelper.new(client, index, body)
77+
----
78+
79+
There are two ways to get the results from a scroll using the helper.
80+
81+
You can iterate over a scroll using the methods in `Enumerable` such as `each` and `map`:
82+
83+
[source,ruby]
84+
----
85+
scroll_helper.each do |item|
86+
puts item
87+
end
88+
----
89+
90+
You can fetch results by page, with the `results` function:
91+
92+
[source,ruby]
93+
----
94+
my_documents = []
95+
while !(documents = scroll_helper.results).empty?
96+
my_documents << documents
97+
end
98+
scroll_helper.clear
99+
----

Diff for: elasticsearch/lib/elasticsearch/helpers/bulk_helper.rb

+1
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ module Helpers
2020
# Elasticsearch Client Helper for the Bulk API
2121
#
2222
# @see https://www.elastic.co/guide/en/elasticsearch/reference/master/docs-bulk.html
23+
#
2324
class BulkHelper
2425
attr_accessor :index
2526

Diff for: elasticsearch/lib/elasticsearch/helpers/scroll_helper.rb

+4
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,10 @@
1717

1818
module Elasticsearch
1919
module Helpers
20+
# Elasticsearch Client Helper for the Scroll API
21+
#
22+
# @see https://www.elastic.co/guide/en/elasticsearch/reference/current/scroll-api.html
23+
#
2024
class ScrollHelper
2125
include Enumerable
2226

0 commit comments

Comments
 (0)