From 7aa114f11e4d194d3db5dcf765974a56a3d5c84b Mon Sep 17 00:00:00 2001 From: Nick Clemens Date: Thu, 19 Mar 2020 16:30:29 +0000 Subject: [PATCH] Bug 23137: Add reset option to rebuild_elasticsearch.pl Setup: 1 - Be using Elasticsearch 2 - Reload mappings from the db Admin->Search configuration Reset Mappings 3 - Reindex ES and confirm searching is working To test: 1 - Apply patch 2 - Alter your mappings file for elastic (just change a description for a field) 3 - perl misc/search_tools/rebuild_elasticsearch.pl -r -v Verbose not necessary, but good for letting you know things are progressing 4 - Confirm the mapping change shows in the interface 5 - Confirm reindex worked and searching is working Signed-off-by: Andrew Fuerste-Henry Signed-off-by: Jonathan Druart Signed-off-by: Martin Renvoize Signed-off-by: Joy Nelson --- misc/search_tools/rebuild_elasticsearch.pl | 25 +++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) diff --git a/misc/search_tools/rebuild_elasticsearch.pl b/misc/search_tools/rebuild_elasticsearch.pl index 9bfa6e27aa..71a5c01f59 100755 --- a/misc/search_tools/rebuild_elasticsearch.pl +++ b/misc/search_tools/rebuild_elasticsearch.pl @@ -27,6 +27,13 @@ rebuild_elasticsearch.pl - inserts records from a Koha database into Elasticsear B [B<-c|--commit>=C] +[B<-d|--delete>] +[B<-r|--reset>] +[B<-a|--authorities>] +[B<-b|--biblios>] +[B<-bn|--bnumber>] +[B<-ai|--authid>] +[B<-p|--processes>] [B<-v|--verbose>] [B<-h|--help>] [B<--man>] @@ -48,6 +55,11 @@ Higher should be faster, but will cause more RAM usage. Default is 5000. Delete the index and recreate it before indexing. +=item B<-r|--reset> + +Reload mappings from files (specified in koha-conf.xml) before indexing. +Implies --delete. + =item B<-a|--authorities> Index the authorities only. Combining this with B<-b> is the same as @@ -98,7 +110,9 @@ use Koha::Script; use C4::Context; use Koha::MetadataRecord::Authority; use Koha::BiblioUtils; +use Koha::SearchEngine::Elasticsearch; use Koha::SearchEngine::Elasticsearch::Indexer; +use Koha::Caches; use MARC::Field; use MARC::Record; use Modern::Perl; @@ -106,7 +120,7 @@ use Pod::Usage; my $verbose = 0; my $commit = 5000; -my ($delete, $help, $man, $processes); +my ($delete, $reset, $help, $man, $processes); my ($index_biblios, $index_authorities); my (@biblionumbers,@authids); @@ -115,6 +129,7 @@ $|=1; # flushes output GetOptions( 'c|commit=i' => \$commit, 'd|delete' => \$delete, + 'r|reset' => \$reset, 'a|authorities' => \$index_authorities, 'b|biblios' => \$index_biblios, 'bn|bnumber=i' => \@biblionumbers, @@ -139,6 +154,14 @@ pod2usage( -exitstatus => 0, -verbose => 2 ) if $man; _sanity_check(); +if ($reset){ + Koha::SearchEngine::Elasticsearch->reset_elasticsearch_mappings; + my $cache = Koha::Caches->get_instance(); + $cache->clear_from_cache('elasticsearch_search_fields_staff_client'); + $cache->clear_from_cache('elasticsearch_search_fields_opac'); + $delete = 1; +} + _verify_index_state($Koha::SearchEngine::Elasticsearch::BIBLIOS_INDEX, $delete) if ($index_biblios); _verify_index_state($Koha::SearchEngine::Elasticsearch::AUTHORITIES_INDEX, $delete) if ($index_authorities); -- 2.39.5