Skip to content

Instantly share code, notes, and snippets.

@leandro
Last active August 29, 2015 14:21
Show Gist options
  • Select an option

  • Save leandro/2cdcacb1c51bdbf022ea to your computer and use it in GitHub Desktop.

Select an option

Save leandro/2cdcacb1c51bdbf022ea to your computer and use it in GitHub Desktop.
Self sustainable standalone ruby script
source "https://rubygems.org"
# Declare your gem's dependencies in breakout_elasticsearch.gemspec.
# Bundler will treat runtime dependencies like base dependencies, and
# development dependencies will be added by default to the :development group.
gemspec
# jquery-rails is used by the dummy application
gem "jquery-rails"
group :es_scripts do
gem 'elasticsearch-transport', git: 'git://github.com/elasticsearch/elasticsearch-ruby.git'
end
require 'rubygems'
require 'bundler'
gemfile_dir = File.expand_path(File.join(File.dirname(__FILE__), '..'))
gemfile = File.join(gemfile_dir, 'Gemfile')
Dir.chdir(gemfile_dir)
system "bundle install --gemfile #{gemfile} --deployment --without development test default production"
Bundler.setup(:es_scripts)
require 'elasticsearch/transport'
client = Elasticsearch::Client.new host: '127.0.0.1:9201'
response = client.perform_request 'GET', '_cluster/health'
p response
leandroico:~ leandro$ ruby migrate.rb
Fetching gem metadata from https://rubygems.org/.........
Fetching git://github.com/elasticsearch/elasticsearch-ruby.git
Installing multipart-post 2.0.0
Installing faraday 0.9.1
Installing multi_json 1.11.0
Using elasticsearch-transport 1.0.7 from git://github.com/elasticsearch/elasticsearch-ruby.git (at master)
Using bundler 1.7.6
Your bundle is complete!
Gems in the groups development, test, default and production were not installed.
It was installed into ./vendor/bundle
#<Elasticsearch::Transport::Transport::Response:0x007f949b164720 @headers={"content-type"=>"application/json; charset=UTF-8", "content-length"=>"239"}, @body={"cluster_name"=>"elasticsearch_leandro", "status"=>"yellow", "timed_out"=>false, "number_of_nodes"=>1, "number_of_data_nodes"=>1, "active_primary_shards"=>125, "active_shards"=>125, "relocating_shards"=>0, "initializing_shards"=>0, "unassigned_shards"=>125}, @status=200>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment