lib/ej/core.rb in ej-0.0.8 vs lib/ej/core.rb in ej-0.0.9

- old
+ new

@@ -13,27 +13,28 @@ @logger = debug ? Logger.new($stderr) : nil @index = index @client = Elasticsearch::Client.new hosts: host, logger: @logger, index: @index end - def search(type, query, size, from, source_only, routing = nil) + def search(type, query, size, from, source_only, routing = nil, fields = nil) body = { from: from } body[:size] = size unless size.nil? body[:query] = { query_string: { query: query } } unless query.nil? search_option = { index: @index, type: type, body: body } search_option[:routing] = routing unless routing.nil? + search_option[:_source] = fields.nil? ? nil : fields.join(',') results = Hashie::Mash.new(@client.search(search_option)) source_only ? get_sources(results) : results end def distinct(term, type, query) body = { size: 0, "aggs"=>{ term + "_count"=>{"cardinality"=>{"field"=>term}}}} body[:query] = { query_string: { query: query } } unless query.nil? @client.search index: @index, type: type, body: body end - def move(source, dest, query) + def copy(source, dest, query) per = DEFAULT_PER num = 0 logger = Logger.new($stdout) source_client = Elasticsearch::Client.new hosts: source, index: @index dest_client = Elasticsearch::Client.new hosts: dest @@ -51,11 +52,11 @@ doc.delete('_score') bulk_message << { index: doc.to_h } bulk_message << source end dest_client.bulk body: bulk_message unless bulk_message.empty? - logger.info("move complete #{from + docs.size}/#{total}") + logger.info("copy complete #{from + docs.size}/#{total}") num += 1 end end def dump(query) @@ -202,9 +203,17 @@ @client.indices.get_warmer index: @index end def refresh @client.indices.refresh index: @index + end + + def nodes_info + @client.nodes.info + end + + def nodes_stats + @client.nodes.stats end def bulk(timestamp_key, type, add_timestamp, id_keys, index) data = parse_json(STDIN.read) template = id_keys.map { |key| '%s' }.join('_') unless id_keys.nil?