diff options
author | Robin H. Johnson <robbat2@gentoo.org> | 2017-05-23 11:18:01 -0700 |
---|---|---|
committer | Robin H. Johnson <robbat2@gentoo.org> | 2017-05-23 11:18:01 -0700 |
commit | 0568b5cc657975d460ac4eaea73736eb13ff4696 (patch) | |
tree | c27c40e5d3bec2e3794316f979b29b5bfde51e63 | |
parent | More function name mismatch (diff) | |
download | backend-0568b5cc657975d460ac4eaea73736eb13ff4696.tar.gz backend-0568b5cc657975d460ac4eaea73736eb13ff4696.tar.bz2 backend-0568b5cc657975d460ac4eaea73736eb13ff4696.zip |
ag: allow manual flush of index.
Signed-off-by: Robin H. Johnson <robbat2@gentoo.org>
-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( |