support es proxied path; indexes one at a time
authorBill Erickson <berickxx@gmail.com>
Thu, 18 Jul 2019 19:20:13 +0000 (15:20 -0400)
committerBill Erickson <berickxx@gmail.com>
Fri, 17 Jan 2020 19:36:02 +0000 (14:36 -0500)
Signed-off-by: Bill Erickson <berickxx@gmail.com>
Open-ILS/examples/fm_IDL.xml
Open-ILS/src/perlmods/lib/OpenILS/Elastic.pm
Open-ILS/src/perlmods/lib/OpenILS/Elastic/BibSearch.pm
Open-ILS/src/sql/Pg/upgrade/XXXX.schema.elastic-search.sql

index 3534cee..209e129 100644 (file)
@@ -12956,6 +12956,7 @@ SELECT  usr,
                        <field reporter:label="Host" name="host" reporter:datatype="text"/>
                        <field reporter:label="Protocol" name="proto" reporter:datatype="text"/>
                        <field reporter:label="Port" name="port" reporter:datatype="int"/>
+                       <field reporter:label="Path" name="path" reporter:datatype="text"/>
                        <field reporter:label="Active" name="active" reporter:datatype="bool"/>
                </fields>
                <links>
index 424b121..8f6c4ae 100644 (file)
@@ -126,8 +126,8 @@ sub connect {
 
     my @nodes;
     for my $server (@{$self->nodes}) {
-        push(@nodes, sprintf("%s://%s:%d", 
-            $server->proto, $server->host, $server->port));
+        push(@nodes, sprintf("%s://%s:%d%s", 
+            $server->proto, $server->host, $server->port, $server->path));
     }
 
     $logger->debug("ES connecting to nodes @nodes");
index 8f8cabe..f891a55 100644 (file)
@@ -133,7 +133,7 @@ sub create_index {
         # Apply field boost.
         $def->{boost} = $field->weight if ($field->weight || 1) > 1;
 
-        $logger->info("ES adding field $field_name: ". 
+        $logger->debug("ES adding field $field_name: ". 
             OpenSRF::Utils::JSON->perl2JSON($def));
 
         $mappings->{$field_name} = $def;
@@ -145,22 +145,47 @@ sub create_index {
 
     my $conf = {
         index => $INDEX_NAME,
-        body => {
-            settings => $settings,
-            mappings => {record => {properties => $mappings}}
-        }
+        body => {settings => $settings}
     };
 
-    # Send the index definition to Elastic
+
+    $logger->info("ES creating index '$INDEX_NAME'");
+
+    # Create the base index with settings
     eval { $self->es->indices->create($conf) };
 
     if ($@) {
         $logger->error("ES failed to create index cluster=".  
             $self->cluster. "index=$INDEX_NAME error=$@");
-        print "$@\n\n";
+        warn "$@\n\n";
         return 0;
     }
 
+    # Create each mapping one at a time instead of en masse so we 
+    # can more easily report when mapping creation fails.
+
+    for my $field (keys %$mappings) {
+        $logger->info("ES Creating index mapping for field $field");
+
+        eval { 
+            $self->es->indices->put_mapping({
+                index => $INDEX_NAME,
+                type  => 'record',
+                body  => {properties => {$field => $mappings->{$field}}}
+            });
+        };
+
+        if ($@) {
+            my $mapjson = OpenSRF::Utils::JSON->perl2JSON($mappings->{$field});
+
+            $logger->error("ES failed to create index mapping: " .
+                "index=$INDEX_NAME field=$field error=$@ mapping=$mapjson");
+
+            warn "$@\n\n";
+            return 0;
+        }
+    }
+
     return 1;
 }
 
index c26c487..7dbc25c 100644 (file)
@@ -16,6 +16,7 @@ CREATE TABLE elastic.node (
     host    TEXT    NOT NULL,
     proto   TEXT    NOT NULL,
     port    INTEGER NOT NULL,
+    path    TEXT    NOT NULL DEFAULT '/',
     active  BOOLEAN NOT NULL DEFAULT FALSE,
     cluster TEXT    NOT NULL 
             REFERENCES elastic.cluster (code) ON DELETE CASCADE,