Lines 162-167
if ($index_authorities) {
Link Here
|
162 |
do_reindex($next, $Koha::SearchEngine::Elasticsearch::AUTHORITIES_INDEX); |
162 |
do_reindex($next, $Koha::SearchEngine::Elasticsearch::AUTHORITIES_INDEX); |
163 |
} |
163 |
} |
164 |
|
164 |
|
|
|
165 |
=head1 INTERNAL METHODS |
166 |
|
167 |
=head2 do_reindex |
168 |
|
169 |
For each index we iterate through the records, committing at specified count |
170 |
|
171 |
=cut |
172 |
|
165 |
sub do_reindex { |
173 |
sub do_reindex { |
166 |
my ( $next, $index_name ) = @_; |
174 |
my ( $next, $index_name ) = @_; |
167 |
|
175 |
|
Lines 198-204
sub do_reindex {
Link Here
|
198 |
push @commit_buffer, $record; |
206 |
push @commit_buffer, $record; |
199 |
if ( !( --$commit_count ) ) { |
207 |
if ( !( --$commit_count ) ) { |
200 |
_log( 1, "Committing $commit records..." ); |
208 |
_log( 1, "Committing $commit records..." ); |
201 |
$indexer->update_index( \@id_buffer, \@commit_buffer ); |
209 |
my $response = $indexer->update_index( \@id_buffer, \@commit_buffer ); |
|
|
210 |
_handle_response($response); |
202 |
$commit_count = $commit; |
211 |
$commit_count = $commit; |
203 |
@id_buffer = (); |
212 |
@id_buffer = (); |
204 |
@commit_buffer = (); |
213 |
@commit_buffer = (); |
Lines 208-230
sub do_reindex {
Link Here
|
208 |
|
217 |
|
209 |
# There are probably uncommitted records |
218 |
# There are probably uncommitted records |
210 |
_log( 1, "Committing final records...\n" ); |
219 |
_log( 1, "Committing final records...\n" ); |
211 |
$indexer->update_index( \@id_buffer, \@commit_buffer ); |
220 |
my $response = $indexer->update_index( \@id_buffer, \@commit_buffer ); |
|
|
221 |
_handle_response($response); |
212 |
_log( 1, "Total $count records indexed\n" ); |
222 |
_log( 1, "Total $count records indexed\n" ); |
213 |
} |
223 |
} |
214 |
|
224 |
|
215 |
# Checks some basic stuff to ensure that it's sane before we start. |
225 |
=head2 sanity_check |
|
|
226 |
|
227 |
Checks some basic stuff to ensure that it's sane before we start. |
228 |
|
229 |
=cut |
230 |
|
216 |
sub sanity_check { |
231 |
sub sanity_check { |
217 |
# Do we have an elasticsearch block defined? |
232 |
# Do we have an elasticsearch block defined? |
218 |
my $conf = C4::Context->config('elasticsearch'); |
233 |
my $conf = C4::Context->config('elasticsearch'); |
219 |
die "No 'elasticsearch' block is defined in koha-conf.xml.\n" if ( !$conf ); |
234 |
die "No 'elasticsearch' block is defined in koha-conf.xml.\n" if ( !$conf ); |
220 |
} |
235 |
} |
221 |
|
236 |
|
222 |
# Output progress information. |
237 |
=head2 _handle_response |
223 |
# |
238 |
|
224 |
# _log($level, $msg); |
239 |
Parse the return from update_index and display errors depending on verbosity of the script |
225 |
# |
240 |
|
226 |
# Will output $msg if the verbosity setting is set to $level or more. Will |
241 |
=cut |
227 |
# not include a trailing newline. |
242 |
|
|
|
243 |
sub _handle_response { |
244 |
my ($response) = @_; |
245 |
my $errors; |
246 |
if( $response->{errors} eq 'true' ){ |
247 |
_log( 1, "There were errors during indexing\n" ); |
248 |
if ( $verbose > 1 ){ |
249 |
foreach my $item (@{$response->{items}}){ |
250 |
next unless defined $item->{index}->{error}; |
251 |
print "Record #" . $item->{index}->{_id} . " " . |
252 |
$item->{index}->{error}->{reason} . " (" . $item->{index}->{error}->{type} . ") : " . |
253 |
$item->{index}->{error}->{caused_by}->{type} . " (" . $item->{index}->{error}->{caused_by}->{reason} . ")\n"; |
254 |
} |
255 |
} |
256 |
} |
257 |
} |
258 |
|
259 |
=head2 _log |
260 |
|
261 |
Output progress information. |
262 |
|
263 |
_log($level, $msg); |
264 |
|
265 |
Will output $msg if the verbosity setting is set to $level or more. Will |
266 |
not include a trailing newline. |
267 |
|
268 |
=cut |
269 |
|
228 |
sub _log { |
270 |
sub _log { |
229 |
my ($level, $msg) = @_; |
271 |
my ($level, $msg) = @_; |
230 |
|
272 |
|
231 |
- |
|
|