aws-v3-sdk 1.0.22 → 1.0.24
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/es-handler/sendGetRequest.js +58 -24
- package/package.json +1 -1
|
@@ -34,17 +34,27 @@ const getClient = async () => {
|
|
|
34
34
|
exports.sendGetRequest = async (index, query, from, size, sort, _source) => {
|
|
35
35
|
const client = await getClient()
|
|
36
36
|
return new Promise((resolve, reject) => {
|
|
37
|
-
|
|
37
|
+
const body = {}
|
|
38
|
+
if (query) {
|
|
39
|
+
body.query = query
|
|
40
|
+
}
|
|
38
41
|
if (sort) {
|
|
39
|
-
body =
|
|
42
|
+
body.sort = sort
|
|
40
43
|
}
|
|
41
|
-
|
|
44
|
+
const options = {
|
|
42
45
|
index,
|
|
43
|
-
from,
|
|
44
|
-
size,
|
|
45
|
-
_source,
|
|
46
46
|
body
|
|
47
|
-
}
|
|
47
|
+
}
|
|
48
|
+
if (from) {
|
|
49
|
+
options.from = from
|
|
50
|
+
}
|
|
51
|
+
if (size) {
|
|
52
|
+
options.size = size
|
|
53
|
+
}
|
|
54
|
+
if (_source) {
|
|
55
|
+
options._source = size
|
|
56
|
+
}
|
|
57
|
+
client.search(options).then(response => {
|
|
48
58
|
logger.debug(response, { response })
|
|
49
59
|
const data = response.body.hits.hits
|
|
50
60
|
const totalCount = response.body.hits.total
|
|
@@ -53,8 +63,12 @@ exports.sendGetRequest = async (index, query, from, size, sort, _source) => {
|
|
|
53
63
|
})
|
|
54
64
|
resolve({ items: mappedData, data: mappedData, totalCount })
|
|
55
65
|
}).catch(err => {
|
|
56
|
-
|
|
57
|
-
|
|
66
|
+
if (err) {
|
|
67
|
+
logger.error('ES sendGetRequest Error', { err })
|
|
68
|
+
reject(err)
|
|
69
|
+
} else {
|
|
70
|
+
resolve({ items: [], data: [], totalCount: 0 })
|
|
71
|
+
}
|
|
58
72
|
})
|
|
59
73
|
})
|
|
60
74
|
}
|
|
@@ -62,25 +76,37 @@ exports.sendGetRequest = async (index, query, from, size, sort, _source) => {
|
|
|
62
76
|
exports.sendGetRequestCallback = async (index, query, from, size, sort, callback) => {
|
|
63
77
|
const client = await getClient()
|
|
64
78
|
return new Promise((resolve, reject) => {
|
|
65
|
-
|
|
79
|
+
const body = {}
|
|
80
|
+
if (query) {
|
|
81
|
+
body.query = query
|
|
82
|
+
}
|
|
66
83
|
if (sort) {
|
|
67
|
-
body =
|
|
84
|
+
body.sort = sort
|
|
68
85
|
}
|
|
69
|
-
|
|
86
|
+
const options = {
|
|
70
87
|
index,
|
|
71
|
-
from,
|
|
72
|
-
size,
|
|
73
88
|
body
|
|
74
|
-
}
|
|
89
|
+
}
|
|
90
|
+
if (from) {
|
|
91
|
+
options.from = from
|
|
92
|
+
}
|
|
93
|
+
if (size) {
|
|
94
|
+
options.size = size
|
|
95
|
+
}
|
|
96
|
+
client.search(options).then(response => {
|
|
75
97
|
const data = response.body.hits.hits
|
|
76
98
|
const totalCount = response.body.hits.total
|
|
77
99
|
const mappedData = data.map(item => {
|
|
78
100
|
return item._source
|
|
79
101
|
})
|
|
80
102
|
callback(null, { items: mappedData, data: mappedData, totalCount })
|
|
81
|
-
}).catch(
|
|
82
|
-
|
|
83
|
-
|
|
103
|
+
}).catch(err => {
|
|
104
|
+
if (err) {
|
|
105
|
+
logger.error('ES Error', { err })
|
|
106
|
+
reject(err)
|
|
107
|
+
} else {
|
|
108
|
+
resolve({ items: [], data: [], totalCount: 0 })
|
|
109
|
+
}
|
|
84
110
|
})
|
|
85
111
|
})
|
|
86
112
|
}
|
|
@@ -94,9 +120,13 @@ exports.getCount = async (index, query) => {
|
|
|
94
120
|
}).then(response => {
|
|
95
121
|
const data = response.body
|
|
96
122
|
resolve({ data })
|
|
97
|
-
}).catch(
|
|
98
|
-
|
|
99
|
-
|
|
123
|
+
}).catch(err => {
|
|
124
|
+
if (err) {
|
|
125
|
+
logger.error('ES Error', { err })
|
|
126
|
+
reject(err)
|
|
127
|
+
} else {
|
|
128
|
+
resolve({ items: [], data: [], totalCount: 0 })
|
|
129
|
+
}
|
|
100
130
|
})
|
|
101
131
|
})
|
|
102
132
|
}
|
|
@@ -109,9 +139,13 @@ exports.multiSearch = async (query) => {
|
|
|
109
139
|
body
|
|
110
140
|
}).then(response => {
|
|
111
141
|
resolve(response)
|
|
112
|
-
}).catch(
|
|
113
|
-
|
|
114
|
-
|
|
142
|
+
}).catch(err => {
|
|
143
|
+
if (err) {
|
|
144
|
+
logger.error('ES Error', { err })
|
|
145
|
+
reject(err)
|
|
146
|
+
} else {
|
|
147
|
+
resolve({ items: [], data: [], totalCount: 0 })
|
|
148
|
+
}
|
|
115
149
|
})
|
|
116
150
|
})
|
|
117
151
|
}
|