return $result;
}
+# Partial document update
+sub update_document {
+ my ($self, $id, $body) = @_;
+
+ my $result;
+
+ eval {
+ $result = $self->es->update(
+ index => $self->index_name,
+ type => 'record',
+ id => $id,
+ body => $body
+ );
+ };
+
+ if ($@) {
+ $logger->error("ES update_document failed with $@");
+ return undef;
+ }
+
+ if ($result->{failed}) {
+ $logger->error("ES update document $id failed " . Dumper($result));
+ return undef;
+ }
+
+ $logger->debug("ES update => $id succeeded");
+ return $result;
+}
+
sub search {
my ($self, $query) = @_;
return ("english");
}
+sub skip_marc {
+ my $self = shift;
+ return $self->{skip_marc};
+}
+
+sub skip_holdings {
+ my $self = shift;
+ return $self->{skip_holdings};
+}
+
sub xsl_file {
my ($self) = @_;
$bib_ids = [@active_ids];
- my $holdings = $self->load_holdings($bib_ids);
- my $marc = $self->load_marc($bib_ids);
+ my $holdings = $self->load_holdings($bib_ids) unless $self->skip_holdings;
+ my $marc = $self->load_marc($bib_ids) unless $self->skip_marc;
+
my $bib_fields = new_editor()->retrieve_all_elastic_bib_field;
for my $bib_id (@$bib_ids) {
my $body = {
bib_source => $rec->{bib_source},
- metarecord => $rec->{metarecord},
- marc => $marc->{$bib_id} || [],
- holdings => $holdings->{$bib_id} || []
+ metarecord => $rec->{metarecord}
};
+ $body->{marc} = $marc->{$bib_id} || [] unless $self->skip_marc;
+ $body->{holdings} = $holdings->{$bib_id} || [] unless $self->skip_holdings;
+
# ES likes the "T" separator for ISO dates
($body->{create_date} = $rec->{create_date}) =~ s/ /T/g;
($body->{edit_date} = $rec->{edit_date}) =~ s/ /T/g;
}
}
- return 0 unless $self->index_document($bib_id, $body);
+ if ($self->skip_marc || $self->skip_holdings) {
+ # TODO: In skip mode, assume we are updating documents instead
+ # of creating new ones. This may need to be more flexible.
+ return 0 unless $self->update_document($bib_id, $body);
+ } else {
+ return 0 unless $self->index_document($bib_id, $body);
+ }
$state->{start_record} = $bib_id + 1;
$index_count++;
my $modified_since;
my $max_duration;
my $batch_size = 500;
+my $skip_marc;
+my $skip_holdings;
# Database settings read from ENV by default.
my $db_host = $ENV{PGHOST} || 'localhost';
'max-duration=s' => \$max_duration,
'batch-size=s' => \$batch_size,
'bib-transform=s' => \$bib_transform,
+ 'skip-marc' => \$skip_marc,
+ 'skip-holdings' => \$skip_holdings,
'db-name=s' => \$db_name,
'db-host=s' => \$db_host,
'db-port=s' => \$db_port,
at regular intervals to keep the ES-indexed data in sync
with the EG data.
+ --skip-marc
+ --skip-holdings
+ Bypass indexing the MARC and/or holdings data. This is
+ useful when reindexing for configuration changes, where
+ the underlying bib data has not changed.
+
--max-duration <duration>
Stop indexing once the process has been running for this
amount of time.
$es = OpenILS::Elastic::BibSearch->new(
cluster => $cluster,
index_name => $index_name,
+ write_mode => 1,
xsl_file => $bib_transform,
- write_mode => 1
+ skip_marc => $skip_marc,
+ skip_holdings => $skip_holdings
);
}