Skip to content

Instantly share code, notes, and snippets.

@Mifrill
Last active February 11, 2021 16:57
Show Gist options
  • Save Mifrill/de75ecc68b6c50e013f34884a84f2140 to your computer and use it in GitHub Desktop.
Save Mifrill/de75ecc68b6c50e013f34884a84f2140 to your computer and use it in GitHub Desktop.
elasticsearch
# Rspec settings
#
#
# Cluster
# Gemfile
# ElasticSearch test cluster
gem 'elasticsearch-extensions', git: 'git://github.com/elasticsearch/elasticsearch-ruby.git'
# .ENV
#
# TEST_CLUSTER_NAME=testing-cluster
# TEST_CLUSTER_COMMAND=~/elasticsearch-6.5.2/bin/elasticsearch
# TEST_CLUSTER_PORT=9350
# TEST_CLUSTER_NODES=1
require 'elasticsearch/extensions/test/cluster'
# Start an in-memory cluster for Elasticsearch as needed
config.before :all do
unless Elasticsearch::Extensions::Test::Cluster.running?(on: ENV['TEST_CLUSTER_PORT'])
Elasticsearch::Extensions::Test::Cluster.start
end
end
# Stop elasticsearch cluster after test run
config.after :suite do
if Elasticsearch::Extensions::Test::Cluster.running?(on: ENV['TEST_CLUSTER_PORT'])
Elasticsearch::Extensions::Test::Cluster.stop
end
end
config.before :each do
ActiveRecord::Base.descendants.each do |model|
next unless model.respond_to?(:__elasticsearch__)
begin
model.__elasticsearch__.create_index!
model.__elasticsearch__.refresh_index!
rescue StandardError => e
STDERR.puts "#{model.name}: #{e.inspect}"
end
end
end
# Delete indexes for all elastic searchable models to ensure clean state between tests
config.after :each do
ActiveRecord::Base.descendants.each do |model|
next unless model.respond_to?(:__elasticsearch__)
begin
model.__elasticsearch__.delete_index!
rescue StandardError => e
STDERR.puts "#{model.name}: #{e.inspect}"
end
end
end
@Mifrill
Copy link
Author

Mifrill commented Feb 11, 2021

curl -XPUT -H "Content-Type: application/json" http://localhost:9200/_cluster/settings -d '{ "transient": { "cluster.routing.allocation.disk.threshold_enabled": false } }'
curl -XPUT -H "Content-Type: application/json" http://localhost:9200/_all/_settings -d '{"index.blocks.read_only_allow_delete": null}'

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment