require 'elasticsearch' class ElasticSearchHelper attr_accessor :server_uri, :index def initialize(server_uri, index) @server_uri = server_uri @index = index end # will build an array of 50 pastes to ship to es def build_json_array(pb, keys) json_for_es = keys.map do |k| pb.encode_json(pb.raw_paste_data(k), pb.raw_paste_metadata(k)) end end def puts_to_es(payload, increment_num) header = { 'Content-type': 'application/json' } response = RestClient::Request.execute( method: :put, url: "#{server_uri}/#{index}/#{index}s/#{increment_num}", headers: header, payload: payload) end def data_mappings # metadata mappings # send a PUT { "mappings": { "_doc": { "properties": { "type": { "type": "keyword" }, "paste_metadata": { "type": "nested" }, "properties": { "scrape_url": { "type": "string" }, "full_url": { "type": "string" }, "date": { "type": "string" }, "size": { "type": "string" }, "expire": { "type": "string" }, "title": { "type": "string" }, "syntax": { "type": "string" }, "user": { "type": "string" }, "hits": { "type": "string" } } "paste_text": { "type": "string" } } } } } end end