Lines 37-43
__PACKAGE__->mk_ro_accessors(qw( index ));
Link Here
|
37 |
__PACKAGE__->mk_accessors(qw( sort_fields )); |
37 |
__PACKAGE__->mk_accessors(qw( sort_fields )); |
38 |
|
38 |
|
39 |
# Constants to refer to the standard index names |
39 |
# Constants to refer to the standard index names |
40 |
Readonly our $BIBLIOS_INDEX => 'biblios'; |
40 |
Readonly our $BIBLIOS_INDEX => 'biblios'; #These are going to be the suffixes for our aliases - most access to indexes will be via alias |
41 |
Readonly our $AUTHORITIES_INDEX => 'authorities'; |
41 |
Readonly our $AUTHORITIES_INDEX => 'authorities'; |
42 |
|
42 |
|
43 |
=head1 NAME |
43 |
=head1 NAME |
Lines 236-241
sub get_elasticsearch_mappings {
Link Here
|
236 |
return $mappings; |
236 |
return $mappings; |
237 |
} |
237 |
} |
238 |
|
238 |
|
|
|
239 |
=head2 get_alias_index |
240 |
|
241 |
Get the ES specific index names that an alias points to |
242 |
|
243 |
Returns an index name or undef |
244 |
|
245 |
=cut |
246 |
|
247 |
sub get_alias_index { |
248 |
my ($self) = @_; |
249 |
my $alias = $self->get_elasticsearch_params()->{index_name}; #FIXME this should probably be an object property/method |
250 |
if ( !$self->store ) { |
251 |
my $params = $self->get_elasticsearch_params(); |
252 |
$self->store( |
253 |
Catmandu::Store::ElasticSearch->new( |
254 |
%$params, |
255 |
index_settings => $self->get_elasticsearch_settings(), |
256 |
index_mappings => $self->get_elasticsearch_mappings(), |
257 |
) |
258 |
); |
259 |
} |
260 |
if ( $self->store->es->indices->exists_alias( name => $alias ) ) { #use the embedded es object to access ES methods directly and check if alias points to anything |
261 |
my $current_index_info = $self->store->es->indices->get_alias( name => $alias ); #we get a hashref of info |
262 |
my @current_indices = keys %$current_index_info; #the keys contain the names of indexes pointed to be the alias |
263 |
return $current_indices[0]; #For now we are maintaining a 1:1 ratio, pointing to several is possible |
264 |
} else { |
265 |
return undef; |
266 |
} |
267 |
} |
268 |
|
269 |
=head2 update_alias_indices |
270 |
|
271 |
Takes our ES alias name and two index names and swaps the old for the new |
272 |
return |
273 |
|
274 |
=cut |
275 |
|
276 |
sub update_alias { |
277 |
my $self = shift; |
278 |
my ( $params ) = @_; |
279 |
my $alias = $self->get_elasticsearch_params()->{index_name}; #FIXME this should probably be an object property/method |
280 |
die "Must supply old_index and new_index parameters" unless ( $params->{old_index} && $params->{new_index} ); |
281 |
return $self->store->es->indices->update_aliases( #this is atomic so we won't delete unless this works |
282 |
body => { |
283 |
actions => [ |
284 |
{ add => { alias => $alias, index => $params->{new_index} } }, |
285 |
{ remove => { alias => $alias, index => $params->{old_index} } } |
286 |
] |
287 |
} |
288 |
); |
289 |
} |
290 |
|
239 |
=head2 _elasticsearch_mapping_for_* |
291 |
=head2 _elasticsearch_mapping_for_* |
240 |
|
292 |
|
241 |
Get the ES mappings for the given data type or a special mapping case |
293 |
Get the ES mappings for the given data type or a special mapping case |
Lines 418-427
These are of a form suited to Catmandu's MARC fixers.
Link Here
|
418 |
sub _foreach_mapping { |
470 |
sub _foreach_mapping { |
419 |
my ( $self, $sub ) = @_; |
471 |
my ( $self, $sub ) = @_; |
420 |
|
472 |
|
|
|
473 |
my $index_type; |
474 |
|
475 |
$self->index =~ /biblio/ ? $index_type = 'biblios' : |
476 |
$self->index =~ /authorities/ ? $index_type = 'authorities' : return; |
477 |
|
421 |
# TODO use a caching framework here |
478 |
# TODO use a caching framework here |
422 |
my $search_fields = Koha::Database->schema->resultset('SearchField')->search( |
479 |
my $search_fields = Koha::Database->schema->resultset('SearchField')->search( |
423 |
{ |
480 |
{ |
424 |
'search_marc_map.index_name' => $self->index, |
481 |
'search_marc_map.index_name' => $index_type, |
425 |
}, |
482 |
}, |
426 |
{ join => { search_marc_to_fields => 'search_marc_map' }, |
483 |
{ join => { search_marc_to_fields => 'search_marc_map' }, |
427 |
'+select' => [ |
484 |
'+select' => [ |