1
- /**
2
- * name : elasticSearch.js
3
- * author : Aman Jung Karki
4
- * created-date : 11-Jun-2020
5
- * Description : elastic search common functionality
6
- */
7
-
8
- /**
9
- * Get user data
10
- * @function
11
- * @name get
12
- * @param {String } id - a unique document id
13
- * @param {String } index - elastic search index
14
- * @param {String } type - elastic search type
15
- * @returns {Object } Get user data.
16
- */
17
-
18
- var get = function (
19
- id = "" ,
20
- index = "" ,
21
- type = ""
22
- ) {
23
-
24
- return new Promise ( async function ( resolve , reject ) {
25
- try {
26
-
27
- if ( id == "" ) {
28
- throw new Error ( "ID is required" ) ;
29
- }
30
-
31
- if ( index == "" ) {
32
- throw new Error ( "Index is required" ) ;
33
- }
34
-
35
- const result = await elasticsearch . client . get ( {
36
- id : id ,
37
- index : index
38
- } , {
39
- ignore : [ httpStatusCode [ "not_found" ] . status ] ,
40
- maxRetries : 3
41
- } ) ;
42
-
43
- return resolve ( result ) ;
44
-
45
- } catch ( error ) {
46
- return reject ( error ) ;
47
- }
48
- } )
49
- } ;
50
-
51
- /* *
52
- * Create or update based on user data.
53
- * @function
54
- * @name createOrUpdate
55
- * @param {String } id - a unique document id
56
- * @param {String } index - elastic search index
57
- * @param {String } data - requested data
58
- * @returns {Object } created or updated user data.
59
- */
60
-
61
- var createOrUpdate = function (
62
- id = "" ,
63
- index = "" ,
64
- data = ""
65
- ) {
66
-
67
- return new Promise ( async function ( resolve , reject ) {
68
- try {
69
-
70
- if ( id == "" ) {
71
- throw new Error ( "ID is required" ) ;
72
- }
73
-
74
- if ( index == "" ) {
75
- throw new Error ( "Index is required" ) ;
76
- }
77
-
78
- if ( Object . keys ( data ) . length == 0 ) {
79
- throw new Error ( "Data is required" ) ;
80
- }
81
-
82
- let result =
83
- await elasticsearch . client . update ( {
84
- id : id ,
85
- index : index ,
86
- body : {
87
- doc : data ,
88
- doc_as_upsert : true
89
- }
90
- } ) ;
91
-
92
- return resolve ( result ) ;
93
-
94
- } catch ( error ) {
95
- return reject ( error ) ;
96
- }
97
- } )
98
- } ;
99
-
100
- module . exports = {
101
- get : get ,
102
- createOrUpdate : createOrUpdate
103
- } ;
1
+ // / **
2
+ // * name : elasticSearch.js
3
+ // * author : Aman Jung Karki
4
+ // * created-date : 11-Jun-2020
5
+ // * Description : elastic search common functionality
6
+ // */
7
+
8
+ // / **
9
+ // * Get user data
10
+ // * @function
11
+ // * @name get
12
+ // * @param {String } id - a unique document id
13
+ // * @param {String } index - elastic search index
14
+ // * @param {String } type - elastic search type
15
+ // * @returns {Object } Get user data.
16
+ // */
17
+
18
+ // var get = function (
19
+ // id = "",
20
+ // index = "",
21
+ // type = ""
22
+ // ) {
23
+
24
+ // return new Promise(async function (resolve, reject) {
25
+ // try {
26
+
27
+ // if (id == "") {
28
+ // throw new Error("ID is required");
29
+ // }
30
+
31
+ // if (index == "") {
32
+ // throw new Error("Index is required");
33
+ // }
34
+
35
+ // const result = await elasticsearch.client.get({
36
+ // id: id,
37
+ // index: index
38
+ // }, {
39
+ // ignore: [httpStatusCode["not_found"].status],
40
+ // maxRetries: 3
41
+ // });
42
+
43
+ // return resolve(result);
44
+
45
+ // } catch (error) {
46
+ // return reject(error);
47
+ // }
48
+ // })
49
+ // };
50
+
51
+ // *
52
+ // * Create or update based on user data.
53
+ // * @function
54
+ // * @name createOrUpdate
55
+ // * @param {String } id - a unique document id
56
+ // * @param {String } index - elastic search index
57
+ // * @param {String } data - requested data
58
+ // * @returns {Object } created or updated user data.
59
+
60
+
61
+ // var createOrUpdate = function (
62
+ // id = "",
63
+ // index = "",
64
+ // data = ""
65
+ // ) {
66
+
67
+ // return new Promise(async function (resolve, reject) {
68
+ // try {
69
+
70
+ // if (id == "") {
71
+ // throw new Error("ID is required");
72
+ // }
73
+
74
+ // if (index == "") {
75
+ // throw new Error("Index is required");
76
+ // }
77
+
78
+ // if (Object.keys(data).length == 0) {
79
+ // throw new Error("Data is required");
80
+ // }
81
+
82
+ // let result =
83
+ // await elasticsearch.client.update({
84
+ // id : id,
85
+ // index : index,
86
+ // body : {
87
+ // doc : data ,
88
+ // doc_as_upsert : true
89
+ // }
90
+ // });
91
+
92
+ // return resolve(result);
93
+
94
+ // } catch (error) {
95
+ // return reject(error);
96
+ // }
97
+ // })
98
+ // };
99
+
100
+ // module.exports = {
101
+ // get : get,
102
+ // createOrUpdate : createOrUpdate
103
+ // };
0 commit comments