Class: Embulk::Input::Elasticsearch

Inherits:
InputPlugin
  • Object
show all
Defined in:
lib/embulk/input/elasticsearch.rb,
lib/embulk/input/elasticsearch/error.rb,
lib/embulk/input/elasticsearch/converter.rb,
lib/embulk/input/elasticsearch/connection.rb,
lib/embulk/input/elasticsearch/input_thread.rb

Defined Under Namespace

Modules: Traceable Classes: ConfigError, Connection, ConnectionError, Converter, DataError, InputThread, TypecastError

Constant Summary collapse

ADD_QUERY_TO_RECORD_KEY =
'query'

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.resume(task, columns, count, &control) ⇒ Object



46
47
48
49
50
51
# File 'lib/embulk/input/elasticsearch.rb', line 46

def self.resume(task, columns, count, &control)
  task_reports = yield(task, columns, count)

  next_config_diff = {}
  return next_config_diff
end

.transaction(config, &control) ⇒ Object



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/embulk/input/elasticsearch.rb', line 13

def self.transaction(config, &control)
  task = {
    "nodes" => config.param("nodes", :array),
    "request_timeout" => config.param("request_timeout", :integer, default: 60),
    "index" => config.param("index", :string),
    "reload_connections" => config.param("reload_connections", :bool, default: true),
    "reload_on_failure" => config.param("reload_on_failure", :bool, default: false),
    "ignore_not_found" => config.param("ignore_not_found", :bool, default: true),
    "index_type" => config.param("index_type", :string, default: nil),
    "retry_on_failure" => config.param("retry_on_failure", :integer, default: 5),
    "per_size" => config.param("per_size", :integer, default: 1000),
    "limit_size" => config.param("limit_size", :integer, default: nil),
    "fields" => config.param("fields", :array, default: nil),
    "queries" => config.param("queries", :array),
    "sort" => config.param("sort", :hash, default: nil),
    "add_query_to_record" => config.param("add_query_to_record", :bool, default: false),
    "scroll" => config.param("scroll", :string, default: '1m')
  }
  # TODO: want max_threads
  define_num_threads = config.param("num_threads", :integer, default: 1)
  task['slice_queries'] = InputThread.get_slice_from_num_threads(task['queries'], define_num_threads)

  columns = []
  task['fields'].each_with_index{ |field, i|
    columns << Column.new(i, field['name'], field['type'].to_sym)
  }
  if task['add_query_to_record']
    columns << Column.new(task['fields'].size, ADD_QUERY_TO_RECORD_KEY, :string)
  end

  resume(task, columns, task['slice_queries'].size, &control)
end

Instance Method Details

#initObject



53
54
55
56
57
58
# File 'lib/embulk/input/elasticsearch.rb', line 53

def init
  @queries = task['slice_queries'][@index]
  Embulk.logger.info("this thread queries => #{@queries}")
  @add_query_to_record = task['add_query_to_record']
  @connection = Connection.new(task)
end

#runObject



60
61
62
63
64
65
66
67
68
69
70
71
72
73
# File 'lib/embulk/input/elasticsearch.rb', line 60

def run
  @queries.each do |query|
    @connection.search_with_query(query) { |result|
      if @add_query_to_record
        result << query
      end
      page_builder.add(result)
    }
  end
  page_builder.finish

  task_report = {}
  return task_report
end