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