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

(-)a/Koha/SearchEngine/Elasticsearch/Indexer.pm (-3 / +3 lines)
Lines 128-142 sub update_index { Link Here
128
        };
128
        };
129
        push @body, $document;
129
        push @body, $document;
130
    }
130
    }
131
    my $response;
131
    if (@body) {
132
    if (@body) {
132
        my $response = $elasticsearch->bulk(
133
        $response = $elasticsearch->bulk(
133
            index => $conf->{index_name},
134
            index => $conf->{index_name},
134
            type => 'data', # is just hard coded in Indexer.pm?
135
            type => 'data', # is just hard coded in Indexer.pm?
135
            body => \@body
136
            body => \@body
136
        );
137
        );
137
    }
138
    }
138
    # TODO: handle response
139
    return $response;
139
    return 1;
140
}
140
}
141
141
142
=head2 set_index_status_ok
142
=head2 set_index_status_ok
(-)a/misc/search_tools/rebuild_elastic_search.pl (-10 / +50 lines)
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
    if( $response->{errors} eq 'true' ){
246
        _log( 1, "There were errors during indexing\n" );
247
        if ( $verbose > 1 ){
248
            foreach my $item (@{$response->{items}}){
249
                next unless defined $item->{index}->{error};
250
                print "Record #" . $item->{index}->{_id} . " " .
251
                      $item->{index}->{error}->{reason} . " (" . $item->{index}->{error}->{type} . ") : " .
252
                      $item->{index}->{error}->{caused_by}->{type} . " (" . $item->{index}->{error}->{caused_by}->{reason} . ")\n";
253
            }
254
        }
255
    }
256
}
257
258
=head2 _log
259
260
Output progress information.
261
262
    _log($level, $msg);
263
264
Will output $msg if the verbosity setting is set to $level or more. Will
265
not include a trailing newline.
266
267
=cut
268
228
sub _log {
269
sub _log {
229
    my ($level, $msg) = @_;
270
    my ($level, $msg) = @_;
230
271
231
- 

Return to bug 22828