View | Details | Raw Unified | Return to bug 22828
Collapse All | Expand All

(-)a/Koha/SearchEngine/Elasticsearch/Indexer.pm (-3 / +3 lines)
Lines 117-131 sub update_index { Link Here
117
        };
117
        };
118
        push @body, $document;
118
        push @body, $document;
119
    }
119
    }
120
    my $response;
120
    if (@body) {
121
    if (@body) {
121
        my $response = $elasticsearch->bulk(
122
        $response = $elasticsearch->bulk(
122
            index => $conf->{index_name},
123
            index => $conf->{index_name},
123
            type => 'data', # is just hard coded in Indexer.pm?
124
            type => 'data', # is just hard coded in Indexer.pm?
124
            body => \@body
125
            body => \@body
125
        );
126
        );
126
    }
127
    }
127
    # TODO: handle response
128
    return $response;
128
    return 1;
129
}
129
}
130
130
131
=head2 set_index_status_ok
131
=head2 set_index_status_ok
(-)a/misc/search_tools/rebuild_elasticsearch.pl (-3 / +28 lines)
Lines 206-211 if ($slice_index == 0) { Link Here
206
    }
206
    }
207
}
207
}
208
208
209
=head1 INTERNAL METHODS
210
209
=head2 _verify_index_state
211
=head2 _verify_index_state
210
212
211
    _verify_index_state($Koha::SearchEngine::Elasticsearch::BIBLIOS_INDEX, 1);
213
    _verify_index_state($Koha::SearchEngine::Elasticsearch::BIBLIOS_INDEX, 1);
Lines 241-246 sub _verify_index_state { Link Here
241
    _do_reindex($callback, $Koha::SearchEngine::Elasticsearch::BIBLIOS_INDEX);
243
    _do_reindex($callback, $Koha::SearchEngine::Elasticsearch::BIBLIOS_INDEX);
242
244
243
Does the actual reindexing. $callback is a function that always returns the next record.
245
Does the actual reindexing. $callback is a function that always returns the next record.
246
For each index we iterate through the records, committing at specified count
244
247
245
=cut
248
=cut
246
249
Lines 266-272 sub _do_reindex { Link Here
266
        push @commit_buffer, $record;
269
        push @commit_buffer, $record;
267
        if ( !( --$commit_count ) ) {
270
        if ( !( --$commit_count ) ) {
268
            _log( 1, "Committing $commit records...\n" );
271
            _log( 1, "Committing $commit records...\n" );
269
            $indexer->update_index( \@id_buffer, \@commit_buffer );
272
            my $response = $indexer->update_index( \@id_buffer, \@commit_buffer );
273
            _handle_response($response);
270
            $commit_count  = $commit;
274
            $commit_count  = $commit;
271
            @id_buffer     = ();
275
            @id_buffer     = ();
272
            @commit_buffer = ();
276
            @commit_buffer = ();
Lines 276-282 sub _do_reindex { Link Here
276
280
277
    # There are probably uncommitted records
281
    # There are probably uncommitted records
278
    _log( 1, "Committing final records...\n" );
282
    _log( 1, "Committing final records...\n" );
279
    $indexer->update_index( \@id_buffer, \@commit_buffer );
283
    my $response = $indexer->update_index( \@id_buffer, \@commit_buffer );
284
    _handle_response($response);
280
    _log( 1, "Total $count records indexed\n" );
285
    _log( 1, "Total $count records indexed\n" );
281
}
286
}
282
287
Lines 294-299 sub _sanity_check { Link Here
294
    die "No 'elasticsearch' block is defined in koha-conf.xml.\n" if ( !$conf );
299
    die "No 'elasticsearch' block is defined in koha-conf.xml.\n" if ( !$conf );
295
}
300
}
296
301
302
=head2 _handle_response
303
304
Parse the return from update_index and display errors depending on verbosity of the script
305
306
=cut
307
308
sub _handle_response {
309
    my ($response) = @_;
310
    if( $response->{errors} eq 'true' ){
311
        _log( 1, "There were errors during indexing\n" );
312
        if ( $verbose > 1 ){
313
            foreach my $item (@{$response->{items}}){
314
                next unless defined $item->{index}->{error};
315
                print "Record #" . $item->{index}->{_id} . " " .
316
                      $item->{index}->{error}->{reason} . " (" . $item->{index}->{error}->{type} . ") : " .
317
                      $item->{index}->{error}->{caused_by}->{type} . " (" . $item->{index}->{error}->{caused_by}->{reason} . ")\n";
318
            }
319
        }
320
    }
321
}
322
297
=head2 _log
323
=head2 _log
298
324
299
    _log($level, "Message\n");
325
    _log($level, "Message\n");
300
- 

Return to bug 22828