|
Lines 115-125
sub update_index {
Link Here
|
| 115 |
if (@body) { |
115 |
if (@body) { |
| 116 |
try{ |
116 |
try{ |
| 117 |
my $elasticsearch = $self->get_elasticsearch(); |
117 |
my $elasticsearch = $self->get_elasticsearch(); |
| 118 |
$response = $elasticsearch->bulk( |
118 |
#TODO Remove check for no_type and use bulk without type when support for Elasticsearch 6 is dropped |
| 119 |
index => $self->index_name, |
119 |
if ($self->{no_type}) { |
| 120 |
type => 'data', # is just hard coded in Indexer.pm? |
120 |
$response = $elasticsearch->bulk( |
| 121 |
body => \@body |
121 |
index => $self->index_name, |
| 122 |
); |
122 |
body => \@body |
|
|
123 |
); |
| 124 |
} |
| 125 |
else { |
| 126 |
$response = $elasticsearch->bulk( |
| 127 |
index => $self->index_name, |
| 128 |
type => 'data', |
| 129 |
body => \@body |
| 130 |
); |
| 131 |
} |
| 123 |
if ($response->{errors}) { |
132 |
if ($response->{errors}) { |
| 124 |
carp "One or more ElasticSearch errors occurred when indexing documents"; |
133 |
carp "One or more ElasticSearch errors occurred when indexing documents"; |
| 125 |
} |
134 |
} |
|
Lines 250-273
sub update_mappings {
Link Here
|
| 250 |
my $elasticsearch = $self->get_elasticsearch(); |
259 |
my $elasticsearch = $self->get_elasticsearch(); |
| 251 |
my $mappings = $self->get_elasticsearch_mappings(); |
260 |
my $mappings = $self->get_elasticsearch_mappings(); |
| 252 |
|
261 |
|
| 253 |
foreach my $type (keys %{$mappings}) { |
262 |
try { |
| 254 |
try { |
263 |
#TODO Remove check for no_type and use put_mapping without type when support for Elasticsearch 6 is dropped |
|
|
264 |
if ($self->{no_type}) { |
| 265 |
my $response = $elasticsearch->indices->put_mapping( |
| 266 |
index => $self->index_name, |
| 267 |
body => $mappings |
| 268 |
); |
| 269 |
} |
| 270 |
else { |
| 255 |
my $response = $elasticsearch->indices->put_mapping( |
271 |
my $response = $elasticsearch->indices->put_mapping( |
| 256 |
index => $self->index_name, |
272 |
index => $self->index_name, |
| 257 |
type => $type, |
273 |
type => 'data', |
| 258 |
body => { |
274 |
body => { |
| 259 |
$type => $mappings->{$type} |
275 |
data => $mappings |
| 260 |
} |
276 |
} |
| 261 |
); |
277 |
); |
| 262 |
} catch { |
278 |
} |
| 263 |
$self->set_index_status_recreate_required(); |
279 |
} catch { |
| 264 |
my $reason = $_[0]->{vars}->{body}->{error}->{reason}; |
280 |
$self->set_index_status_recreate_required(); |
| 265 |
my $index_name = $self->index_name; |
281 |
my $reason = $_[0]->{vars}->{body}->{error}->{reason}; |
| 266 |
Koha::Exceptions::Exception->throw( |
282 |
my $index_name = $self->index_name; |
| 267 |
error => "Unable to update mappings for index \"$index_name\". Reason was: \"$reason\". Index needs to be recreated and reindexed", |
283 |
Koha::Exceptions::Exception->throw( |
| 268 |
); |
284 |
error => "Unable to update mappings for index \"$index_name\". Reason was: \"$reason\". Index needs to be recreated and reindexed", |
| 269 |
}; |
285 |
); |
| 270 |
} |
286 |
}; |
| 271 |
$self->set_index_status_ok(); |
287 |
$self->set_index_status_ok(); |
| 272 |
} |
288 |
} |
| 273 |
|
289 |
|
|
Lines 346-356
sub delete_index {
Link Here
|
| 346 |
|
362 |
|
| 347 |
my $elasticsearch = $self->get_elasticsearch(); |
363 |
my $elasticsearch = $self->get_elasticsearch(); |
| 348 |
my @body = map { { delete => { _id => "$_" } } } @{$biblionums}; |
364 |
my @body = map { { delete => { _id => "$_" } } } @{$biblionums}; |
| 349 |
my $result = $elasticsearch->bulk( |
365 |
#TODO Remove check for no_type and use bulk without type when support for Elasticsearch 6 is dropped |
| 350 |
index => $self->index_name, |
366 |
my $result = $self->{no_type} ? |
| 351 |
type => 'data', |
367 |
$elasticsearch->bulk( |
| 352 |
body => \@body, |
368 |
index => $self->index_name, |
| 353 |
); |
369 |
body => \@body, |
|
|
370 |
) |
| 371 |
: |
| 372 |
$elasticsearch->bulk( |
| 373 |
index => $self->index_name, |
| 374 |
type => 'data', |
| 375 |
body => \@body, |
| 376 |
); |
| 354 |
if ($result->{errors}) { |
377 |
if ($result->{errors}) { |
| 355 |
croak "An Elasticsearch error occurred during bulk delete"; |
378 |
croak "An Elasticsearch error occurred during bulk delete"; |
| 356 |
} |
379 |
} |