2019-04-24 16:46:39 -06:00
|
|
|
import * as elasticsearch from '@elastic/elasticsearch';
|
2021-08-19 06:55:45 -06:00
|
|
|
import config from '@/config/index';
|
2016-12-28 15:49:51 -07:00
|
|
|
|
2018-07-04 05:36:06 -06:00
|
|
|
const index = {
|
|
|
|
settings: {
|
|
|
|
analysis: {
|
|
|
|
analyzer: {
|
2019-04-24 16:46:39 -06:00
|
|
|
ngram: {
|
2021-12-09 07:58:30 -07:00
|
|
|
tokenizer: 'ngram',
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
2018-07-04 05:36:06 -06:00
|
|
|
},
|
|
|
|
mappings: {
|
2019-04-24 16:46:39 -06:00
|
|
|
properties: {
|
|
|
|
text: {
|
|
|
|
type: 'text',
|
|
|
|
index: true,
|
|
|
|
analyzer: 'ngram',
|
|
|
|
},
|
|
|
|
userId: {
|
|
|
|
type: 'keyword',
|
|
|
|
index: true,
|
|
|
|
},
|
|
|
|
userHost: {
|
|
|
|
type: 'keyword',
|
|
|
|
index: true,
|
2021-12-09 07:58:30 -07:00
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
2018-07-04 05:36:06 -06:00
|
|
|
};
|
|
|
|
|
2016-12-28 15:49:51 -07:00
|
|
|
// Init ElasticSearch connection
|
2019-02-07 05:02:33 -07:00
|
|
|
const client = config.elasticsearch ? new elasticsearch.Client({
|
2019-10-20 09:41:12 -06:00
|
|
|
node: `${config.elasticsearch.ssl ? 'https://' : 'http://'}${config.elasticsearch.host}:${config.elasticsearch.port}`,
|
2020-03-19 23:00:34 -06:00
|
|
|
auth: (config.elasticsearch.user && config.elasticsearch.pass) ? {
|
|
|
|
username: config.elasticsearch.user,
|
2021-12-09 07:58:30 -07:00
|
|
|
password: config.elasticsearch.pass,
|
2020-03-19 23:00:34 -06:00
|
|
|
} : undefined,
|
2021-12-09 07:58:30 -07:00
|
|
|
pingTimeout: 30000,
|
2019-02-07 05:02:33 -07:00
|
|
|
}) : null;
|
2016-12-28 15:49:51 -07:00
|
|
|
|
2018-07-04 05:13:05 -06:00
|
|
|
if (client) {
|
2018-07-04 05:36:06 -06:00
|
|
|
client.indices.exists({
|
2019-08-08 22:04:35 -06:00
|
|
|
index: config.elasticsearch.index || 'misskey_note',
|
2018-07-04 05:36:06 -06:00
|
|
|
}).then(exist => {
|
2019-04-24 16:46:39 -06:00
|
|
|
if (!exist.body) {
|
|
|
|
client.indices.create({
|
2019-08-08 22:04:35 -06:00
|
|
|
index: config.elasticsearch.index || 'misskey_note',
|
2021-12-09 07:58:30 -07:00
|
|
|
body: index,
|
2019-04-24 16:46:39 -06:00
|
|
|
});
|
|
|
|
}
|
2018-07-04 05:13:05 -06:00
|
|
|
});
|
|
|
|
}
|
2016-12-28 15:49:51 -07:00
|
|
|
|
|
|
|
export default client;
|