UNPKG

1.19 kBJavaScriptView Raw
1"use strict";
2var mongoosastic = require("mongoosastic");
3var elasticsearch = require("elasticsearch");
4const config_1 = require("../config");
5/**
6 * ElastticSearchUtils
7 */
8class 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 // This will be called only in the case if the mongoosastic plugin was attached to the mongoose model.
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}
35exports.searchUtils = new ElastticSearchUtils();
36
37//# sourceMappingURL=elasticSearchUtils.js.map