update cluster settings to prevent auto index creation, update destroy to remove ALL indexes (#6042)

This commit is contained in:
Molly Struve 2020-02-12 15:21:38 -05:00 committed by GitHub
parent df7b62e2b0
commit acfdd11b50
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 27 additions and 1 deletions

View file

@ -9,11 +9,16 @@ module Search
end
def setup_indexes
update_settings
create_indexes
add_aliases
update_mappings
end
def update_settings
SearchClient.cluster.put_settings(body: default_settings)
end
def create_indexes
SEARCH_CLASSES.each do |search_class|
next if SearchClient.indices.exists(index: search_class::INDEX_NAME)
@ -39,6 +44,18 @@ module Search
search_class.delete_index
end
end
private
def default_settings
{
persistent: {
action: {
auto_create_index: false
}
}
}
end
end
end
end

View file

@ -16,6 +16,6 @@ namespace :search do
exit
end
Search::Cluster.destroy_indexes
SearchClient.indices.delete(index: "*")
end
end

View file

@ -66,4 +66,13 @@ RSpec.describe Search::Cluster, type: :service do
expect(described_class::SEARCH_CLASSES).to all(have_received(:update_mappings))
end
end
describe "::update_settings" do
it "updates cluster settings" do
described_class.update_settings
cluster_settings = SearchClient.cluster.get_settings
auto_create_setting = cluster_settings.dig("persistent", "action", "auto_create_index")
expect(auto_create_setting).to eq("false")
end
end
end