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 <andrew@bywatersolutions.com>
Signed-off-by: Jonathan Druart <jonathan.druart@bugs.koha-community.org>
Signed-off-by: Martin Renvoize <martin.renvoize@ptfs-europe.com>
This commit is contained in:
Nick Clemens 2020-03-19 16:30:29 +00:00 committed by Martin Renvoize
parent feab2cbeb2
commit 9fa6bb6401
No known key found for this signature in database
GPG Key ID: 422B469130441A0F
1 changed files with 24 additions and 1 deletions

View File

@ -27,6 +27,13 @@ rebuild_elasticsearch.pl - inserts records from a Koha database into Elasticsear
B<rebuild_elasticsearch.pl>
[B<-c|--commit>=C<count>]
[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);