summaryrefslogtreecommitdiff
path: root/src/db
diff options
context:
space:
mode:
authorsyuilo <syuilotan@yahoo.co.jp>2019-04-25 07:46:39 +0900
committersyuilo <syuilotan@yahoo.co.jp>2019-04-25 07:46:39 +0900
commit0db54386cdef3f444f1afb4f3b8bfcaeab7ac68d (patch)
tree38d3d6b2112326bb1a03a8732cd8969e24d693de /src/db
parentFix #4793 (diff)
downloadsharkey-0db54386cdef3f444f1afb4f3b8bfcaeab7ac68d.tar.gz
sharkey-0db54386cdef3f444f1afb4f3b8bfcaeab7ac68d.tar.bz2
sharkey-0db54386cdef3f444f1afb4f3b8bfcaeab7ac68d.zip
Resolve #3119
Diffstat (limited to 'src/db')
-rw-r--r--src/db/elasticsearch.ts72
1 files changed, 25 insertions, 47 deletions
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
+ });
+ }
});
}