From 0db54386cdef3f444f1afb4f3b8bfcaeab7ac68d Mon Sep 17 00:00:00 2001 From: syuilo Date: Thu, 25 Apr 2019 07:46:39 +0900 Subject: Resolve #3119 --- src/db/elasticsearch.ts | 72 +++++++++++++++++-------------------------------- 1 file changed, 25 insertions(+), 47 deletions(-) (limited to 'src/db') diff --git a/src/db/elasticsearch.ts b/src/db/elasticsearch.ts index d54b01763b..02c9e88d9c 100644 --- a/src/db/elasticsearch.ts +++ b/src/db/elasticsearch.ts @@ -1,41 +1,30 @@ -import * as elasticsearch from 'elasticsearch'; +import * as elasticsearch from '@elastic/elasticsearch'; import config from '../config'; -import Logger from '../services/logger'; - -const esLogger = new Logger('es'); const index = { settings: { analysis: { - normalizer: { - lowercase_normalizer: { - type: 'custom', - filter: ['lowercase'] - } - }, analyzer: { - bigram: { - tokenizer: 'bigram_tokenizer' - } - }, - tokenizer: { - bigram_tokenizer: { - type: 'nGram', - min_gram: 2, - max_gram: 2 + ngram: { + tokenizer: 'ngram' } } } }, mappings: { - note: { - properties: { - text: { - type: 'text', - index: true, - analyzer: 'bigram', - normalizer: 'lowercase_normalizer' - } + properties: { + text: { + type: 'text', + index: true, + analyzer: 'ngram', + }, + userId: { + type: 'keyword', + index: true, + }, + userHost: { + type: 'keyword', + index: true, } } } @@ -43,31 +32,20 @@ const index = { // Init ElasticSearch connection const client = config.elasticsearch ? new elasticsearch.Client({ - host: `${config.elasticsearch.host}:${config.elasticsearch.port}` + node: `http://${config.elasticsearch.host}:${config.elasticsearch.port}`, + pingTimeout: 30000 }) : null; if (client) { - // Send a HEAD request - client.ping({ - // Ping usually has a 3000ms timeout - requestTimeout: 30000 - }, error => { - if (error) { - esLogger.error('elasticsearch is down!'); - } else { - esLogger.succ('elasticsearch is available!'); - } - }); - client.indices.exists({ - index: 'misskey' + index: 'misskey_note' }).then(exist => { - if (exist) return; - - client.indices.create({ - index: 'misskey', - body: index - }); + if (!exist.body) { + client.indices.create({ + index: 'misskey_note', + body: index + }); + } }); } -- cgit v1.2.3-freya