Line 0
Link Here
|
0 |
- |
1 |
#! /usr/bin/perl |
|
|
2 |
# |
3 |
# This compares record counts from a Koha database to elastic search |
4 |
|
5 |
# Copyright 2019 ByWater Solutions |
6 |
# |
7 |
# This file is part of Koha. |
8 |
# |
9 |
# Koha is free software; you can redistribute it and/or modify it under the |
10 |
# terms of the GNU General Public License as published by the Free Software |
11 |
# Foundation; either version 3 of the License, or (at your option) any later |
12 |
# version. |
13 |
# |
14 |
# Koha is distributed in the hope that it will be useful, but WITHOUT ANY |
15 |
# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR |
16 |
# A PARTICULAR PURPOSE. See the GNU General Public License for more details. |
17 |
# |
18 |
# You should have received a copy of the GNU General Public License along |
19 |
# with Koha; if not, write to the Free Software Foundation, Inc., |
20 |
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. |
21 |
|
22 |
=head1 NAME |
23 |
|
24 |
compare_es_to_db.pl - compares record counts from a Koha database to Elasticsearch |
25 |
|
26 |
=head1 SYNOPSIS |
27 |
|
28 |
B<compare_es_to_db.pl> |
29 |
|
30 |
=cut |
31 |
|
32 |
use Modern::Perl; |
33 |
use Koha::Items; |
34 |
use Koha::SearchEngine::Elasticsearch; |
35 |
use Array::Utils qw( array_diff ); |
36 |
|
37 |
use Koha::Biblios; |
38 |
use Koha::Authorities; |
39 |
|
40 |
my @biblionumbers = Koha::Biblios->search()->get_column('biblionumber'); |
41 |
my @authids = Koha::Authorities->search()->get_column('authid'); |
42 |
|
43 |
foreach my $index ( ('biblios','authorities') ){ |
44 |
print "=================\n"; |
45 |
print "Checking $index\n"; |
46 |
my @db_records = $index eq 'biblios' ? Koha::Biblios->search()->get_column('biblionumber') : Koha::Authorities->search()->get_column('authid'); |
47 |
|
48 |
my $searcher = Koha::SearchEngine::Elasticsearch->new({ index => $index }); |
49 |
my $es = $searcher->get_elasticsearch(); |
50 |
my $count = $es->indices->stats( index => $searcher->get_elasticsearch_params->{index_name} ) |
51 |
->{_all}{primaries}{docs}{count}; |
52 |
print "Count in db for $index is " . scalar @db_records . ", count in Elasticsearch is $count\n"; |
53 |
# All done if they match |
54 |
next if @db_records == $count; |
55 |
|
56 |
# Otherwise, lets find all the ES ids |
57 |
my $scroll = $es->scroll_helper( |
58 |
index => $searcher->get_elasticsearch_params->{index_name}, |
59 |
size => 5000, |
60 |
body => { |
61 |
query => { |
62 |
match_all => {} |
63 |
} |
64 |
}, |
65 |
scroll_in_qs => 1, |
66 |
); |
67 |
|
68 |
my @es_ids; |
69 |
|
70 |
while (my $doc = $scroll->next ){ |
71 |
push @es_ids, $doc->{_id}; |
72 |
} |
73 |
|
74 |
# And compare the arrays |
75 |
my @diff = array_diff(@biblionumbers, @es_ids ); |
76 |
foreach my $problem (@diff){ |
77 |
print "Record #$problem is not in both sources\n"; |
78 |
} |
79 |
} |