Lines 21-26
use Carp qw( carp croak );
Link Here
|
21 |
use Modern::Perl; |
21 |
use Modern::Perl; |
22 |
use Try::Tiny qw( catch try ); |
22 |
use Try::Tiny qw( catch try ); |
23 |
use List::Util qw( any ); |
23 |
use List::Util qw( any ); |
|
|
24 |
use version; |
24 |
use base qw(Koha::SearchEngine::Elasticsearch); |
25 |
use base qw(Koha::SearchEngine::Elasticsearch); |
25 |
|
26 |
|
26 |
use Koha::Exceptions; |
27 |
use Koha::Exceptions; |
Lines 115-125
sub update_index {
Link Here
|
115 |
if (@body) { |
116 |
if (@body) { |
116 |
try{ |
117 |
try{ |
117 |
my $elasticsearch = $self->get_elasticsearch(); |
118 |
my $elasticsearch = $self->get_elasticsearch(); |
118 |
$response = $elasticsearch->bulk( |
119 |
my %es_bulk = ( |
119 |
index => $self->index_name, |
120 |
index => $self->index_name, |
120 |
type => 'data', # is just hard coded in Indexer.pm? |
|
|
121 |
body => \@body |
121 |
body => \@body |
122 |
); |
122 |
); |
|
|
123 |
if (version->parse($self->{es_version}) < version->parse('7.0.0')) { |
124 |
$es_bulk{'type'} = 'data'; |
125 |
} |
126 |
$response = $elasticsearch->bulk(%es_bulk); |
123 |
if ($response->{errors}) { |
127 |
if ($response->{errors}) { |
124 |
carp "One or more ElasticSearch errors occurred when indexing documents"; |
128 |
carp "One or more ElasticSearch errors occurred when indexing documents"; |
125 |
} |
129 |
} |
Lines 250-273
sub update_mappings {
Link Here
|
250 |
my $elasticsearch = $self->get_elasticsearch(); |
254 |
my $elasticsearch = $self->get_elasticsearch(); |
251 |
my $mappings = $self->get_elasticsearch_mappings(); |
255 |
my $mappings = $self->get_elasticsearch_mappings(); |
252 |
|
256 |
|
253 |
foreach my $type (keys %{$mappings}) { |
257 |
try { |
254 |
try { |
258 |
my %es_mapping = ( |
255 |
my $response = $elasticsearch->indices->put_mapping( |
259 |
index => $self->index_name, |
256 |
index => $self->index_name, |
260 |
body => $mappings |
257 |
type => $type, |
261 |
); |
258 |
body => { |
262 |
if (version->parse($self->{es_version}) < version->parse('7.0.0')) { |
259 |
$type => $mappings->{$type} |
263 |
if (version->parse($self->{es_version}) >= version->parse('6.8.0') && version->parse($elasticsearch->VERSION) >= version->parse('6.8.0')) { |
260 |
} |
264 |
$es_mapping{'include_type_name'} = \1; |
261 |
); |
265 |
} |
262 |
} catch { |
266 |
$es_mapping{'type'} = 'data'; |
263 |
$self->set_index_status_recreate_required(); |
267 |
$es_mapping{'body'} = {'data' => $mappings}; |
264 |
my $reason = $_[0]->{vars}->{body}->{error}->{reason}; |
268 |
} |
265 |
my $index_name = $self->index_name; |
269 |
my $response = $elasticsearch->indices->put_mapping(%es_mapping); |
266 |
Koha::Exceptions::Exception->throw( |
270 |
} catch { |
267 |
error => "Unable to update mappings for index \"$index_name\". Reason was: \"$reason\". Index needs to be recreated and reindexed", |
271 |
$self->set_index_status_recreate_required(); |
268 |
); |
272 |
my $reason = $_[0]->{vars}->{body}->{error}->{reason}; |
269 |
}; |
273 |
my $index_name = $self->index_name; |
270 |
} |
274 |
Koha::Exceptions::Exception->throw( |
|
|
275 |
error => "Unable to update mappings for index \"$index_name\". Reason was: \"$reason\". Index needs to be recreated and reindexed", |
276 |
); |
277 |
}; |
271 |
$self->set_index_status_ok(); |
278 |
$self->set_index_status_ok(); |
272 |
} |
279 |
} |
273 |
|
280 |
|
Lines 346-356
sub delete_index {
Link Here
|
346 |
|
353 |
|
347 |
my $elasticsearch = $self->get_elasticsearch(); |
354 |
my $elasticsearch = $self->get_elasticsearch(); |
348 |
my @body = map { { delete => { _id => "$_" } } } @{$biblionums}; |
355 |
my @body = map { { delete => { _id => "$_" } } } @{$biblionums}; |
349 |
my $result = $elasticsearch->bulk( |
356 |
my %es_bulk = ( |
350 |
index => $self->index_name, |
357 |
index => $self->index_name, |
351 |
type => 'data', |
|
|
352 |
body => \@body, |
358 |
body => \@body, |
353 |
); |
359 |
); |
|
|
360 |
if (version->parse($self->{es_version}) < version->parse('7.0.0')) { |
361 |
$es_bulk{'type'} = 'data'; |
362 |
} |
363 |
my $result = $elasticsearch->bulk(%es_bulk); |
354 |
if ($result->{errors}) { |
364 |
if ($result->{errors}) { |
355 |
croak "An Elasticsearch error occurred during bulk delete"; |
365 |
croak "An Elasticsearch error occurred during bulk delete"; |
356 |
} |
366 |
} |