Просмотр исходного кода

- revert hunk of init() method in elasticsearch.ts
- adjust condition for this.isElasticsearchReindexOnBoot() position
- add comments for rebuildIndex(), in the end normalizeIndices() will be called after rebuildIndex() process.

LuqmanHakim-Grune 4 лет назад
Родитель
Сommit
aa583740ac

+ 4 - 0
packages/app/src/server/service/search-delegator/elasticsearch.ts

@@ -143,6 +143,10 @@ class ElasticsearchDelegator implements SearchDelegator<Data> {
     };
   }
 
+  async init() {
+    return this.normalizeIndices();
+  }
+
   /**
    * return Nodes Info
    * `cluster:monitor/nodes/info` privilege is required on ES

+ 10 - 9
packages/app/src/server/service/search.ts

@@ -78,17 +78,18 @@ class SearchService implements SearchQueryParser, SearchResolver {
     this.isElasticsearchReindexOnBoot = this.configManager.getConfig('crowi', 'app:elasticsearchReindexOnBoot');
 
     if (this.isConfigured) {
-      if (!this.isElasticsearchReindexOnBoot) {
-        logger.info('ELASTICSEARCH_REINDEX_ON_BOOT value is false, no reindex on boot');
-        this.normalizeIndices();
-      }
-      else {
-        logger.info('Reindex elasticsearch is running');
-        this.rebuildIndex();
-      }
-
+      this.fullTextSearchDelegator.init();
       this.registerUpdateEvent();
     }
+
+    if (!this.isElasticsearchReindexOnBoot) {
+      logger.info('ELASTICSEARCH_REINDEX_ON_BOOT value is false, no reindex on boot');
+      this.normalizeIndices();
+    }
+    else {
+      logger.info('Reindex elasticsearch is running');
+      this.rebuildIndex(); // rebuildIndex() will call normalizeIndices() in the end of rebuildIndex() process
+    }
   }
 
   get isConfigured() {