update cluster settings to prevent auto index creation, update destroy to remove ALL indexes (#6042)
This commit is contained in:
parent
df7b62e2b0
commit
acfdd11b50
3 changed files with 27 additions and 1 deletions
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -16,6 +16,6 @@ namespace :search do
|
|||
exit
|
||||
end
|
||||
|
||||
Search::Cluster.destroy_indexes
|
||||
SearchClient.indices.delete(index: "*")
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue