2019-04-25 07:46:39 +09:00
|
|
|
import * as elasticsearch from '@elastic/elasticsearch';
|
2018-04-02 13:15:53 +09:00
|
|
|
import config from '../config';
|
2016-12-29 07:49:51 +09:00
|
|
|
|
2018-07-04 20:36:06 +09:00
|
|
|
const index = {
|
|
|
|
settings: {
|
|
|
|
analysis: {
|
|
|
|
analyzer: {
|
2019-04-25 07:46:39 +09:00
|
|
|
ngram: {
|
|
|
|
tokenizer: 'ngram'
|
2018-07-04 20:36:06 +09:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
mappings: {
|
2019-04-25 07:46:39 +09:00
|
|
|
properties: {
|
|
|
|
text: {
|
|
|
|
type: 'text',
|
|
|
|
index: true,
|
|
|
|
analyzer: 'ngram',
|
|
|
|
},
|
|
|
|
userId: {
|
|
|
|
type: 'keyword',
|
|
|
|
index: true,
|
|
|
|
},
|
|
|
|
userHost: {
|
|
|
|
type: 'keyword',
|
|
|
|
index: true,
|
2018-07-04 20:36:06 +09:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2016-12-29 07:49:51 +09:00
|
|
|
// Init ElasticSearch connection
|
2019-02-07 21:02:33 +09:00
|
|
|
const client = config.elasticsearch ? new elasticsearch.Client({
|
2019-04-25 07:46:39 +09:00
|
|
|
node: `http://${config.elasticsearch.host}:${config.elasticsearch.port}`,
|
|
|
|
pingTimeout: 30000
|
2019-02-07 21:02:33 +09:00
|
|
|
}) : null;
|
2016-12-29 07:49:51 +09:00
|
|
|
|
2018-07-04 20:13:05 +09:00
|
|
|
if (client) {
|
2018-07-04 20:36:06 +09:00
|
|
|
client.indices.exists({
|
2019-08-09 13:04:35 +09:00
|
|
|
index: config.elasticsearch.index || 'misskey_note',
|
2018-07-04 20:36:06 +09:00
|
|
|
}).then(exist => {
|
2019-04-25 07:46:39 +09:00
|
|
|
if (!exist.body) {
|
|
|
|
client.indices.create({
|
2019-08-09 13:04:35 +09:00
|
|
|
index: config.elasticsearch.index || 'misskey_note',
|
2019-04-25 07:46:39 +09:00
|
|
|
body: index
|
|
|
|
});
|
|
|
|
}
|
2018-07-04 20:13:05 +09:00
|
|
|
});
|
|
|
|
}
|
2016-12-29 07:49:51 +09:00
|
|
|
|
|
|
|
export default client;
|