diff options
-rwxr-xr-x | ag | 16 | ||||
-rw-r--r-- | lib/storage.rb | 6 |
2 files changed, 22 insertions, 0 deletions
@@ -73,6 +73,13 @@ op = OptionParser.new do |opts| $options.need_argument = false end + opts.on('--flush-index', 'Flush index to disk. Needs --list') do + abort 'Can only select one action' unless $options.action.nil? + + $options.action = :do_flush_index + $options.need_argument = false + end + opts.on('--rethread', 'Rethread messages. Needs --list') do abort 'Can only select one action' unless $options.action.nil? @@ -277,6 +284,15 @@ rescue Elasticsearch::Transport::Transport::Errors::BadRequest => e end end +def do_flush_index(ignore_exists: false, _raise: false) + Ag::Storage.flush_index($options.name) +rescue Elasticsearch::Transport::Transport::Errors::BadRequest => e + unless ignore_exists && e.message =~ /IndexAlreadyExistsException/ + raise e if _raise + $stderr.puts "Cannot flush index #{e}" + end +end + def do_reindex # http://babinho.net/2014/07/refresh-your-elasticsearch-index-with-zero-downtime/ abort 'Come back later.' diff --git a/lib/storage.rb b/lib/storage.rb index daa1d1b..304c6e2 100644 --- a/lib/storage.rb +++ b/lib/storage.rb @@ -286,6 +286,12 @@ module Ag::Storage _hide_unhide(list, id, false, comment) end + def flush_index(list) + $es.indices.flush( + :index: index_name(list), + ) + end + def update(list, id, doc_changes) raise "Invalid update for #{list}/#{id} #{doc_changes}" unless doc_changes.is_a?(Hash) $es.update( |