Module: Elasticsearch::API::Actions
- Defined in:
- lib/elasticsearch/api/actions/stream.rb
Instance Method Summary collapse
-
#stream(*args, &block) ⇒ Object
search.stream index: ‘scrollindex’, scroll: ‘5m’, body: { query: { title: ‘test’ } }.
Instance Method Details
#stream(*args, &block) ⇒ Object
search.stream index: ‘scrollindex’, scroll: ‘5m’, body: { query: { title: ‘test’ } }
counter = 0 search.stream counter, index: ‘scrollindex’, scroll: ‘5m’, body: { query: { title: ‘test’ } }
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/elasticsearch/api/actions/stream.rb', line 9 def stream(*args, &block) raise ArgumentError.new "wrong number of arguments (#{args.count} for 1..2)" if args.count > 2 raise ArgumentError.new 'no block given' unless block_given? opts, memo = *args.reverse opts[:scroll] = opts[:scroll] || opts['scroll'] || '5m' scroll_opts = { :scroll => opts[:scroll] } catch :stop_stream do results = search opts scroll_opts[:scroll_id] = results['_scroll_id'] results = scroll scroll_opts if opts[:search_type] =~ /scan/ until results['hits']['hits'].empty? do scroll_opts[:scroll_id] = results['_scroll_id'] results['hits']['hits'].each do |doc| memo = yield doc, memo end results = scroll scroll_opts end end memo end |