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($elasticsearch->info->{version}->{number}) < 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 252-264
sub update_mappings {
Link Here
|
252 |
|
256 |
|
253 |
foreach my $type (keys %{$mappings}) { |
257 |
foreach my $type (keys %{$mappings}) { |
254 |
try { |
258 |
try { |
255 |
my $response = $elasticsearch->indices->put_mapping( |
259 |
my %es_mapping = ( |
256 |
index => $self->index_name, |
260 |
index => $self->index_name, |
257 |
type => $type, |
261 |
body => $mappings->{$type} |
258 |
body => { |
|
|
259 |
$type => $mappings->{$type} |
260 |
} |
261 |
); |
262 |
); |
|
|
263 |
if (version->parse($elasticsearch->info->{version}->{number}) < version->parse('7.0.0')) { |
264 |
if (version->parse($elasticsearch->info->{version}->{number}) >= version->parse('6.8.0') && version->parse($elasticsearch->VERSION) >= version->parse('6.8.0')) { |
265 |
$es_mapping{'include_type_name'} = \1; |
266 |
} |
267 |
$es_mapping{'type'} = 'data'; |
268 |
$es_mapping{'body'} = {'data' => $mappings->{$type}}; |
269 |
} |
270 |
my $response = $elasticsearch->indices->put_mapping(%es_mapping); |
262 |
} catch { |
271 |
} catch { |
263 |
$self->set_index_status_recreate_required(); |
272 |
$self->set_index_status_recreate_required(); |
264 |
my $reason = $_[0]->{vars}->{body}->{error}->{reason}; |
273 |
my $reason = $_[0]->{vars}->{body}->{error}->{reason}; |
Lines 346-356
sub delete_index {
Link Here
|
346 |
|
355 |
|
347 |
my $elasticsearch = $self->get_elasticsearch(); |
356 |
my $elasticsearch = $self->get_elasticsearch(); |
348 |
my @body = map { { delete => { _id => "$_" } } } @{$biblionums}; |
357 |
my @body = map { { delete => { _id => "$_" } } } @{$biblionums}; |
349 |
my $result = $elasticsearch->bulk( |
358 |
my %es_bulk = ( |
350 |
index => $self->index_name, |
359 |
index => $self->index_name, |
351 |
type => 'data', |
|
|
352 |
body => \@body, |
360 |
body => \@body, |
353 |
); |
361 |
); |
|
|
362 |
if (version->parse($elasticsearch->info->{version}->{number}) < version->parse('7.0.0')) { |
363 |
$es_bulk{'type'} = 'data'; |
364 |
} |
365 |
my $result = $elasticsearch->bulk(%es_bulk); |
354 |
if ($result->{errors}) { |
366 |
if ($result->{errors}) { |
355 |
croak "An Elasticsearch error occurred during bulk delete"; |
367 |
croak "An Elasticsearch error occurred during bulk delete"; |
356 |
} |
368 |
} |
357 |
- |
|
|