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 267-290 sub update_mappings { Link Here
267
    my $elasticsearch = $self->get_elasticsearch();
267
    my $elasticsearch = $self->get_elasticsearch();
268
    my $mappings = $self->get_elasticsearch_mappings();
268
    my $mappings = $self->get_elasticsearch_mappings();
269
269
270
    foreach my $type (keys %{$mappings}) {
270
    try {
271
        try {
271
        my $response = $elasticsearch->indices->put_mapping(
272
            my $response = $elasticsearch->indices->put_mapping(
272
            index => $self->index_name,
273
                index => $self->index_name,
273
            type => 'data',
274
                type => $type,
274
            include_type_name => JSON::true(),
275
                body => {
275
            body => {
276
                    $type => $mappings->{$type}
276
                data => $mappings
277
                }
277
            }
278
            );
278
        );
279
        } catch {
279
    } catch {
280
            $self->set_index_status_recreate_required();
280
        $self->set_index_status_recreate_required();
281
            my $reason = $_[0]->{vars}->{body}->{error}->{reason};
281
        my $reason = $_[0]->{vars}->{body}->{error}->{reason};
282
            my $index_name = $self->index_name;
282
        my $index_name = $self->index_name;
283
            Koha::Exception->throw(
283
        Koha::Exception->throw(
284
                error => "Unable to update mappings for index \"$index_name\". Reason was: \"$reason\". Index needs to be recreated and reindexed",
284
            error => "Unable to update mappings for index \"$index_name\". Reason was: \"$reason\". Index needs to be recreated and reindexed",
285
            );
285
        );
286
        };
286
    };
287
    }
288
    $self->set_index_status_ok();
287
    $self->set_index_status_ok();
289
}
288
}
290
289
Lines 356-361 sub delete_index { Link Here
356
    my $result = $elasticsearch->bulk(
355
    my $result = $elasticsearch->bulk(
357
        index => $self->index_name,
356
        index => $self->index_name,
358
        type => 'data',
357
        type => 'data',
358
        include_type_name => JSON::true(),
359
        body => \@body,
359
        body => \@body,
360
    );
360
    );
361
    if ($result->{errors}) {
361
    if ($result->{errors}) {
(-)a/Koha/SearchEngine/Elasticsearch/QueryBuilder.pm (-3 / +2 lines)
Lines 577-583 sub build_authorities_query_compat { Link Here
577
577
578
        $m = exists $koha_to_index_name->{$m} ? $koha_to_index_name->{$m} : $m;
578
        $m = exists $koha_to_index_name->{$m} ? $koha_to_index_name->{$m} : $m;
579
        push @indexes, $m;
579
        push @indexes, $m;
580
        warn "Unknown search field $m in marclist" unless (defined $mappings->{data}->{properties}->{$m} || $m eq '' || $m eq 'match-heading');
580
        warn "Unknown search field $m in marclist" unless (defined $mappings->{properties}->{$m} || $m eq '' || $m eq 'match-heading');
581
    }
581
    }
582
    for ( my $i = 0 ; $i < @$value ; $i++ ) {
582
    for ( my $i = 0 ; $i < @$value ; $i++ ) {
583
        next unless $value->[$i]; #clean empty form values, ES doesn't like undefined searches
583
        next unless $value->[$i]; #clean empty form values, ES doesn't like undefined searches
Lines 1125-1131 sub _sort_field { Link Here
1125
    my ($self, $f) = @_;
1125
    my ($self, $f) = @_;
1126
1126
1127
    my $mappings = $self->get_elasticsearch_mappings();
1127
    my $mappings = $self->get_elasticsearch_mappings();
1128
    my $textField = defined $mappings->{data}{properties}{$f}{type} && $mappings->{data}{properties}{$f}{type} eq 'text';
1128
    my $textField = defined $mappings->{properties}{$f}{type} && $mappings->{properties}{$f}{type} eq 'text';
1129
    if (!defined $self->sort_fields()->{$f} || $self->sort_fields()->{$f}) {
1129
    if (!defined $self->sort_fields()->{$f} || $self->sort_fields()->{$f}) {
1130
        $f .= '__sort';
1130
        $f .= '__sort';
1131
    } else {
1131
    } else {
1132
- 

Return to bug 25669