1 | "use strict";
|
2 | var mongoosastic = require("mongoosastic");
|
3 | var elasticsearch = require("elasticsearch");
|
4 | const config_1 = require("../config");
|
5 |
|
6 |
|
7 |
|
8 | class ElastticSearchUtils {
|
9 | constructor() {
|
10 | if (config_1.Config.ApplyElasticSearch) {
|
11 | this.esClient = new elasticsearch.Client({ host: config_1.Config.ElasticSearchConnection });
|
12 | }
|
13 | }
|
14 | insertMongoosasticToSchema(schema) {
|
15 | if (config_1.Config.ApplyElasticSearch) {
|
16 | schema.plugin(mongoosastic, {
|
17 | esClient: this.esClient
|
18 | });
|
19 | }
|
20 | }
|
21 | registerToMongoosastic(mongooseModel) {
|
22 |
|
23 | if (config_1.Config.ApplyElasticSearch && mongooseModel.createMapping) {
|
24 | mongooseModel.createMapping((err, mapping) => {
|
25 | if (err) {
|
26 | console.error(err);
|
27 | }
|
28 | else {
|
29 | console.log(mapping);
|
30 | }
|
31 | });
|
32 | }
|
33 | }
|
34 | }
|
35 | exports.searchUtils = new ElastticSearchUtils();
|
36 |
|
37 |
|