Lines 96-103
Arrayref of C<MARC::Record>s.
Link Here
|
96 |
sub update_index { |
96 |
sub update_index { |
97 |
my ($self, $biblionums, $records) = @_; |
97 |
my ($self, $biblionums, $records) = @_; |
98 |
|
98 |
|
99 |
my $conf = $self->get_elasticsearch_params(); |
|
|
100 |
my $elasticsearch = $self->get_elasticsearch(); |
101 |
my $documents = $self->marc_records_to_documents($records); |
99 |
my $documents = $self->marc_records_to_documents($records); |
102 |
my @body; |
100 |
my @body; |
103 |
|
101 |
|
Lines 113-120
sub update_index {
Link Here
|
113 |
} |
111 |
} |
114 |
my $response; |
112 |
my $response; |
115 |
if (@body) { |
113 |
if (@body) { |
|
|
114 |
my $elasticsearch = $self->get_elasticsearch(); |
116 |
$response = $elasticsearch->bulk( |
115 |
$response = $elasticsearch->bulk( |
117 |
index => $conf->{index_name}, |
116 |
index => $self->index_name, |
118 |
type => 'data', # is just hard coded in Indexer.pm? |
117 |
type => 'data', # is just hard coded in Indexer.pm? |
119 |
body => \@body |
118 |
body => \@body |
120 |
); |
119 |
); |
Lines 236-249
failes.
Link Here
|
236 |
|
235 |
|
237 |
sub update_mappings { |
236 |
sub update_mappings { |
238 |
my ($self) = @_; |
237 |
my ($self) = @_; |
239 |
my $conf = $self->get_elasticsearch_params(); |
|
|
240 |
my $elasticsearch = $self->get_elasticsearch(); |
238 |
my $elasticsearch = $self->get_elasticsearch(); |
241 |
my $mappings = $self->get_elasticsearch_mappings(); |
239 |
my $mappings = $self->get_elasticsearch_mappings(); |
242 |
|
240 |
|
243 |
foreach my $type (keys %{$mappings}) { |
241 |
foreach my $type (keys %{$mappings}) { |
244 |
try { |
242 |
try { |
245 |
my $response = $elasticsearch->indices->put_mapping( |
243 |
my $response = $elasticsearch->indices->put_mapping( |
246 |
index => $conf->{index_name}, |
244 |
index => $self->index_name, |
247 |
type => $type, |
245 |
type => $type, |
248 |
body => { |
246 |
body => { |
249 |
$type => $mappings->{$type} |
247 |
$type => $mappings->{$type} |
Lines 252-259
sub update_mappings {
Link Here
|
252 |
} catch { |
250 |
} catch { |
253 |
$self->set_index_status_recreate_required(); |
251 |
$self->set_index_status_recreate_required(); |
254 |
my $reason = $_[0]->{vars}->{body}->{error}->{reason}; |
252 |
my $reason = $_[0]->{vars}->{body}->{error}->{reason}; |
|
|
253 |
my $index_name = $self->index_name; |
255 |
Koha::Exceptions::Exception->throw( |
254 |
Koha::Exceptions::Exception->throw( |
256 |
error => "Unable to update mappings for index \"$conf->{index_name}\". Reason was: \"$reason\". Index needs to be recreated and reindexed", |
255 |
error => "Unable to update mappings for index \"$index_name\". Reason was: \"$reason\". Index needs to be recreated and reindexed", |
257 |
); |
256 |
); |
258 |
}; |
257 |
}; |
259 |
} |
258 |
} |
Lines 288-298
sub delete_index {
Link Here
|
288 |
my ($self, $biblionums) = @_; |
287 |
my ($self, $biblionums) = @_; |
289 |
|
288 |
|
290 |
my $elasticsearch = $self->get_elasticsearch(); |
289 |
my $elasticsearch = $self->get_elasticsearch(); |
291 |
my $conf = $self->get_elasticsearch_params(); |
|
|
292 |
|
293 |
my @body = map { { delete => { _id => $_ } } } @{$biblionums}; |
290 |
my @body = map { { delete => { _id => $_ } } } @{$biblionums}; |
294 |
my $result = $elasticsearch->bulk( |
291 |
my $result = $elasticsearch->bulk( |
295 |
index => $conf->{index_name}, |
292 |
index => $self->index_name, |
296 |
type => 'data', |
293 |
type => 'data', |
297 |
body => \@body, |
294 |
body => \@body, |
298 |
); |
295 |
); |
Lines 322-330
Drops the index from the Elasticsearch server.
Link Here
|
322 |
sub drop_index { |
319 |
sub drop_index { |
323 |
my ($self) = @_; |
320 |
my ($self) = @_; |
324 |
if ($self->index_exists) { |
321 |
if ($self->index_exists) { |
325 |
my $conf = $self->get_elasticsearch_params(); |
|
|
326 |
my $elasticsearch = $self->get_elasticsearch(); |
322 |
my $elasticsearch = $self->get_elasticsearch(); |
327 |
$elasticsearch->indices->delete(index => $conf->{index_name}); |
323 |
$elasticsearch->indices->delete(index => $self->index_name); |
328 |
$self->set_index_status_recreate_required(); |
324 |
$self->set_index_status_recreate_required(); |
329 |
} |
325 |
} |
330 |
} |
326 |
} |
Lines 337-347
Creates the index (including mappings) on the Elasticsearch server.
Link Here
|
337 |
|
333 |
|
338 |
sub create_index { |
334 |
sub create_index { |
339 |
my ($self) = @_; |
335 |
my ($self) = @_; |
340 |
my $conf = $self->get_elasticsearch_params(); |
|
|
341 |
my $settings = $self->get_elasticsearch_settings(); |
336 |
my $settings = $self->get_elasticsearch_settings(); |
342 |
my $elasticsearch = $self->get_elasticsearch(); |
337 |
my $elasticsearch = $self->get_elasticsearch(); |
343 |
$elasticsearch->indices->create( |
338 |
$elasticsearch->indices->create( |
344 |
index => $conf->{index_name}, |
339 |
index => $self->index_name, |
345 |
body => { |
340 |
body => { |
346 |
settings => $settings |
341 |
settings => $settings |
347 |
} |
342 |
} |
Lines 358-367
empty string to indicate whether index exists or not.
Link Here
|
358 |
|
353 |
|
359 |
sub index_exists { |
354 |
sub index_exists { |
360 |
my ($self) = @_; |
355 |
my ($self) = @_; |
361 |
my $conf = $self->get_elasticsearch_params(); |
|
|
362 |
my $elasticsearch = $self->get_elasticsearch(); |
356 |
my $elasticsearch = $self->get_elasticsearch(); |
363 |
return $elasticsearch->indices->exists( |
357 |
return $elasticsearch->indices->exists( |
364 |
index => $conf->{index_name}, |
358 |
index => $self->index_name, |
365 |
); |
359 |
); |
366 |
} |
360 |
} |
367 |
|
361 |
|