From d89224405c255758078f636e335174f0fc9b647e Mon Sep 17 00:00:00 2001 From: scienceasdf Date: Wed, 9 Dec 2020 10:41:45 +0800 Subject: [PATCH] feat: set analyzer for elasticsearch (#2793) * Feature: Custom configuration for elasticsearch For better search results especially in Chinese, which the standard token analyzer may not work well. * Set default analyzer in settings when building index * Remove dangling comma --- server/modules/search/elasticsearch/definition.yml | 10 ++++++++-- server/modules/search/elasticsearch/engine.js | 11 ++++++++++- 2 files changed, 18 insertions(+), 3 deletions(-) diff --git a/server/modules/search/elasticsearch/definition.yml b/server/modules/search/elasticsearch/definition.yml index 834f3935..856f651b 100644 --- a/server/modules/search/elasticsearch/definition.yml +++ b/server/modules/search/elasticsearch/definition.yml @@ -26,16 +26,22 @@ props: hint: The index name to use during creation default: wiki order: 3 + analyzer: + type: String + title: Analyzer + hint: 'The token analyzer in elasticsearch' + default: simple + order: 4 sniffOnStart: type: Boolean title: Sniff on start hint: 'Should Wiki.js attempt to detect the rest of the cluster on first connect? (Default: off)' default: false - order: 4 + order: 5 sniffInterval: type: Number title: Sniff Interval hint: '0 = disabled, Interval in seconds to check for updated list of nodes in cluster. (Default: 0)' default: 0 - order: 5 + order: 6 diff --git a/server/modules/search/elasticsearch/engine.js b/server/modules/search/elasticsearch/engine.js index 7129c0f6..4a41df88 100644 --- a/server/modules/search/elasticsearch/engine.js +++ b/server/modules/search/elasticsearch/engine.js @@ -70,7 +70,16 @@ module.exports = { body: { mappings: (this.config.apiVersion === '6.x') ? { _doc: idxBody - } : idxBody + } : idxBody, + settings: { + analysis: { + analyzer: { + default: { + type: this.config.analyzer + } + } + } + } } }) } catch (err) {