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

(-)a/Koha/SearchEngine/Elasticsearch.pm (-8 / +6 lines)
Lines 189-197 sub get_elasticsearch_mappings { Link Here
189
    if (!defined $all_mappings{$self->index}) {
189
    if (!defined $all_mappings{$self->index}) {
190
        $sort_fields{$self->index} = {};
190
        $sort_fields{$self->index} = {};
191
        # Clone the general mapping to break ties with the original hash
191
        # Clone the general mapping to break ties with the original hash
192
        my $mappings = {
192
        my $mappings = clone(_get_elasticsearch_field_config('general', ''));
193
            data => clone(_get_elasticsearch_field_config('general', ''))
194
        };
195
        my $marcflavour = lc C4::Context->preference('marcflavour');
193
        my $marcflavour = lc C4::Context->preference('marcflavour');
196
        $self->_foreach_mapping(
194
        $self->_foreach_mapping(
197
            sub {
195
            sub {
Lines 214-238 sub get_elasticsearch_mappings { Link Here
214
                }
212
                }
215
213
216
                if ($search) {
214
                if ($search) {
217
                    $mappings->{data}{properties}{$name} = _get_elasticsearch_field_config('search', $es_type);
215
                    $mappings->{properties}{$name} = _get_elasticsearch_field_config('search', $es_type);
218
                }
216
                }
219
217
220
                if ($facet) {
218
                if ($facet) {
221
                    $mappings->{data}{properties}{ $name . '__facet' } = _get_elasticsearch_field_config('facet', $es_type);
219
                    $mappings->{properties}{ $name . '__facet' } = _get_elasticsearch_field_config('facet', $es_type);
222
                }
220
                }
223
                if ($suggestible) {
221
                if ($suggestible) {
224
                    $mappings->{data}{properties}{ $name . '__suggestion' } = _get_elasticsearch_field_config('suggestible', $es_type);
222
                    $mappings->{properties}{ $name . '__suggestion' } = _get_elasticsearch_field_config('suggestible', $es_type);
225
                }
223
                }
226
                # Sort is a bit special as it can be true, false, undef.
224
                # Sort is a bit special as it can be true, false, undef.
227
                # We care about "true" or "undef",
225
                # We care about "true" or "undef",
228
                # "undef" means to do the default thing, which is make it sortable.
226
                # "undef" means to do the default thing, which is make it sortable.
229
                if (!defined $sort || $sort) {
227
                if (!defined $sort || $sort) {
230
                    $mappings->{data}{properties}{ $name . '__sort' } = _get_elasticsearch_field_config('sort', $es_type);
228
                    $mappings->{properties}{ $name . '__sort' } = _get_elasticsearch_field_config('sort', $es_type);
231
                    $sort_fields{$self->index}{$name} = 1;
229
                    $sort_fields{$self->index}{$name} = 1;
232
                }
230
                }
233
            }
231
            }
234
        );
232
        );
235
        $mappings->{data}{properties}{ 'match-heading' } = _get_elasticsearch_field_config('search', 'text') if $self->index eq 'authorities';
233
        $mappings->{properties}{ 'match-heading' } = _get_elasticsearch_field_config('search', 'text') if $self->index eq 'authorities';
236
        $all_mappings{$self->index} = $mappings;
234
        $all_mappings{$self->index} = $mappings;
237
    }
235
    }
238
    $self->sort_fields(\%{$sort_fields{$self->index}});
236
    $self->sort_fields(\%{$sort_fields{$self->index}});
(-)a/Koha/SearchEngine/Elasticsearch/Indexer.pm (-18 / +18 lines)
Lines 250-273 sub update_mappings { Link Here
250
    my $elasticsearch = $self->get_elasticsearch();
250
    my $elasticsearch = $self->get_elasticsearch();
251
    my $mappings = $self->get_elasticsearch_mappings();
251
    my $mappings = $self->get_elasticsearch_mappings();
252
252
253
    foreach my $type (keys %{$mappings}) {
253
    try {
254
        try {
254
        my $response = $elasticsearch->indices->put_mapping(
255
            my $response = $elasticsearch->indices->put_mapping(
255
            index => $self->index_name,
256
                index => $self->index_name,
256
            type => 'data',
257
                type => $type,
257
            include_type_name => JSON::true(),
258
                body => {
258
            body => {
259
                    $type => $mappings->{$type}
259
                data => $mappings
260
                }
260
            }
261
            );
261
        );
262
        } catch {
262
    } catch {
263
            $self->set_index_status_recreate_required();
263
        $self->set_index_status_recreate_required();
264
            my $reason = $_[0]->{vars}->{body}->{error}->{reason};
264
        my $reason = $_[0]->{vars}->{body}->{error}->{reason};
265
            my $index_name = $self->index_name;
265
        my $index_name = $self->index_name;
266
            Koha::Exceptions::Exception->throw(
266
        Koha::Exceptions::Exception->throw(
267
                error => "Unable to update mappings for index \"$index_name\". Reason was: \"$reason\". Index needs to be recreated and reindexed",
267
            error => "Unable to update mappings for index \"$index_name\". Reason was: \"$reason\". Index needs to be recreated and reindexed",
268
            );
268
        );
269
        };
269
    };
270
    }
271
    $self->set_index_status_ok();
270
    $self->set_index_status_ok();
272
}
271
}
273
272
Lines 349-354 sub delete_index { Link Here
349
    my $result = $elasticsearch->bulk(
348
    my $result = $elasticsearch->bulk(
350
        index => $self->index_name,
349
        index => $self->index_name,
351
        type => 'data',
350
        type => 'data',
351
        include_type_name => JSON::true(),
352
        body => \@body,
352
        body => \@body,
353
    );
353
    );
354
    if ($result->{errors}) {
354
    if ($result->{errors}) {
(-)a/Koha/SearchEngine/Elasticsearch/QueryBuilder.pm (-3 / +2 lines)
Lines 583-589 sub build_authorities_query_compat { Link Here
583
583
584
        $m = exists $koha_to_index_name->{$m} ? $koha_to_index_name->{$m} : $m;
584
        $m = exists $koha_to_index_name->{$m} ? $koha_to_index_name->{$m} : $m;
585
        push @indexes, $m;
585
        push @indexes, $m;
586
        warn "Unknown search field $m in marclist" unless (defined $mappings->{data}->{properties}->{$m} || $m eq '' || $m eq 'match-heading');
586
        warn "Unknown search field $m in marclist" unless (defined $mappings->{properties}->{$m} || $m eq '' || $m eq 'match-heading');
587
    }
587
    }
588
    for ( my $i = 0 ; $i < @$value ; $i++ ) {
588
    for ( my $i = 0 ; $i < @$value ; $i++ ) {
589
        next unless $value->[$i]; #clean empty form values, ES doesn't like undefined searches
589
        next unless $value->[$i]; #clean empty form values, ES doesn't like undefined searches
Lines 1132-1138 sub _sort_field { Link Here
1132
    my ($self, $f) = @_;
1132
    my ($self, $f) = @_;
1133
1133
1134
    my $mappings = $self->get_elasticsearch_mappings();
1134
    my $mappings = $self->get_elasticsearch_mappings();
1135
    my $textField = defined $mappings->{data}{properties}{$f}{type} && $mappings->{data}{properties}{$f}{type} eq 'text';
1135
    my $textField = defined $mappings->{properties}{$f}{type} && $mappings->{properties}{$f}{type} eq 'text';
1136
    if (!defined $self->sort_fields()->{$f} || $self->sort_fields()->{$f}) {
1136
    if (!defined $self->sort_fields()->{$f} || $self->sort_fields()->{$f}) {
1137
        $f .= '__sort';
1137
        $f .= '__sort';
1138
    } else {
1138
    } else {
1139
- 

Return to bug 25669