Module: ES

Defined in:
lib/es/client.rb,
lib/es.rb,
lib/es/utils.rb,
lib/es/version.rb,
lib/es/connection.rb,
lib/es/raw_client.rb

Overview

TODO find a better way to wrap serialization to client

Defined Under Namespace

Classes: Client, Connection, RawClient

Constant Summary collapse

VERSION =
'0.0.8'

Class Method Summary collapse

Class Method Details

.copy_index(from_index, to_index, opts = {}) ⇒ Object



2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/es/utils.rb', line 2

def self.copy_index(from_index, to_index, opts = {})
  scroll_timeout = opts.fetch(:scroll_timeout, '5m')
  scroll_size = opts.fetch(:scroll_size, 100)

  from = new(host: opts[:from_host])
  to = new(host: opts[:to_host])

  results = from.search(from_index, {query: {match_all: {}}}, {scroll: scroll_timeout, size: scroll_size})

  while results['hits']['hits'].any?
    requests = results['hits']['hits'].each_with_object([]) do |hit, requests|
      requests << {index: {_type: hit['_type'], _id: hit['id']}}
      requests << hit['_source']
    end

    to.bulk(requests, to_index)

    scroll_id = results['_scroll_id']
    results = from.scroll(scroll: scroll_timeout, scroll_id: scroll_id)
  end
end

.new(*args) ⇒ Object

faux constructor



2
3
4
# File 'lib/es.rb', line 2

def self.new(*args) # faux constructor
  Client.new(*args)
end