This commit is contained in:
syuilo
2019-04-25 07:46:39 +09:00
parent 772258b0b8
commit 0db54386cd
14 changed files with 147 additions and 90 deletions

View File

@ -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
});
}
});
}