Lines 112-117
Full documentation.
Link Here
|
112 |
|
112 |
|
113 |
=back |
113 |
=back |
114 |
|
114 |
|
|
|
115 |
=head1 EXAMPLES |
116 |
|
117 |
C<rebuild_elasticsearch.pl> |
118 |
|
119 |
=head2 Index a single biblio or authority |
120 |
|
121 |
C<rebuild_elasticsearch.pl -v -bn 123> |
122 |
|
123 |
C<rebuild_elasticsearch.pl -v -ai 456> |
124 |
|
125 |
This is useful when playing with new mappings. |
126 |
|
127 |
=head2 Use C<--where> to select the records to index |
128 |
|
129 |
You can pass arbitrary SQL via C<--where> to select which records you |
130 |
want to index. C<--where> only works if you specify either C<-b> or |
131 |
C<-a> to index either biblios or authorities. |
132 |
|
133 |
When using C<-b> to index biblios, the SQL is applied to the table |
134 |
C<biblio>. When indexing authorities via C<-a>, the table |
135 |
C<auth_header> is used. |
136 |
|
137 |
Please note that you cannot do proper joins (because this would make |
138 |
the CLI very complicated). But you can use subselects. |
139 |
|
140 |
=head3 biblios created in the last 24h |
141 |
|
142 |
rebuild_elasticsearch.pl -v --biblios \ |
143 |
--where 'datecreated > date_sub(now(), interval 1 day)' |
144 |
|
145 |
=head3 authorities with authid between 500 and 600 |
146 |
|
147 |
rebuild_elasticsearch.pl -v --authorities \ |
148 |
--where 'authid between 500 and 599' |
149 |
|
150 |
=head3 biblios with an item that was modified in the last hour OR metadata was modified in the last hour |
151 |
|
152 |
rebuild_elasticsearch.pl -v --biblios \ |
153 |
--where " biblionumber in ( select biblionumber from biblio_metadata where timestamp >= date_sub(now(), interval 1 hour)) |
154 |
OR biblionumber in (select biblionumber from items where timestamp >= date_sub(now(), interval 1 hour)) " |
155 |
|
156 |
Or use a UNION: |
157 |
|
158 |
rebuild_elasticsearch.pl -v --biblios \ |
159 |
--where "biblionumber in ( |
160 |
select biblionumber from biblio_metadata where timestamp >= '2025-10-09' |
161 |
UNION select biblionumber from items where timestamp >= '2025-10-09') " |
162 |
|
163 |
=head3 biblios where 856u starts with 'http' |
164 |
|
165 |
rebuild_elasticsearch.pl -v --biblios \ |
166 |
--where 'biblionumber in ( |
167 |
select biblionumber from biblio_metadata where |
168 |
ExtractValue(metadata,'\''//datafield[@tag="856"]/subfield[@code="u"]'\'') like "http%")' |
169 |
|
170 |
In this case we have to be quite careful with the bash quoting. We use single quotes for C<--where> (so that the C<@> sign is not interpreted from bash) and the have to esacpe the single quotes we need in C<ExtractValue> with C<'\''>. |
171 |
|
172 |
=head3 Very complex queries |
173 |
|
174 |
For very complex queries it is easier to create a table in the database containing the biblionumbers and then use a subselect to select them. |
175 |
|
176 |
CREATE TABLE some_selection AS SELECT biblionumber FROM ... MONSTER SQL ...; |
177 |
|
178 |
rebuild_elasticsearch.pl -v --biblios --where ' biblionumber in (select biblionumber from some_selection ); |
179 |
|
180 |
DROP TABLE some_selection; |
181 |
|
115 |
=head1 IMPLEMENTATION |
182 |
=head1 IMPLEMENTATION |
116 |
|
183 |
|
117 |
=cut |
184 |
=cut |
Lines 160-166
unless ( $index_authorities || $index_biblios ) {
Link Here
|
160 |
} |
227 |
} |
161 |
|
228 |
|
162 |
if ( $processes && ( @biblionumbers || @authids ) ) { |
229 |
if ( $processes && ( @biblionumbers || @authids ) ) { |
163 |
die "Argument p|processes cannot be combined with bn|bnumber or ai|authid"; |
230 |
die "Argument p|processes cannot be combined with bn|bnumber or ai|authid\n"; |
164 |
} |
231 |
} |
165 |
|
232 |
|
166 |
pod2usage(1) if $help; |
233 |
pod2usage(1) if $help; |
Lines 207-212
if ($desc) {
Link Here
|
207 |
} |
274 |
} |
208 |
|
275 |
|
209 |
if ($where) { |
276 |
if ($where) { |
|
|
277 |
if ( $index_authorities && $index_biblios ) { |
278 |
die "Argument w|where must be combined with either b|biblios or a|authorities\n"; |
279 |
} |
210 |
$iterator_options{where} = $where; |
280 |
$iterator_options{where} = $where; |
211 |
} |
281 |
} |
212 |
|
282 |
|
Lines 362-368
Parse the return from update_index and display errors depending on verbosity of
Link Here
|
362 |
|
432 |
|
363 |
sub _handle_response { |
433 |
sub _handle_response { |
364 |
my ($response) = @_; |
434 |
my ($response) = @_; |
365 |
if ( $response->{errors} eq 'true' ) { |
435 |
if ( $response && $response->{errors} eq 'true' ) { |
366 |
_log( 1, "There were errors during indexing\n" ); |
436 |
_log( 1, "There were errors during indexing\n" ); |
367 |
if ( $verbose > 1 ) { |
437 |
if ( $verbose > 1 ) { |
368 |
foreach my $item ( @{ $response->{items} } ) { |
438 |
foreach my $item ( @{ $response->{items} } ) { |
369 |
- |
|
|