@lowdefy/connection-elasticsearch 4.0.0-alpha.1

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.
Files changed (23) hide show
  1. package/LICENSE +201 -0
  2. package/dist/connections/Elasticsearch/Elasticsearch.js +33 -0
  3. package/dist/connections/Elasticsearch/ElasticsearchDelete/ElasticsearchDelete.js +27 -0
  4. package/dist/connections/Elasticsearch/ElasticsearchDelete/ElasticsearchDelete.json +87 -0
  5. package/dist/connections/Elasticsearch/ElasticsearchDelete/index.js +24 -0
  6. package/dist/connections/Elasticsearch/ElasticsearchDeleteByQuery/ElasticsearchDeleteByQuery.js +26 -0
  7. package/dist/connections/Elasticsearch/ElasticsearchDeleteByQuery/ElasticsearchDeleteByQuery.json +231 -0
  8. package/dist/connections/Elasticsearch/ElasticsearchDeleteByQuery/index.js +24 -0
  9. package/dist/connections/Elasticsearch/ElasticsearchIndex/ElasticsearchIndex.js +28 -0
  10. package/dist/connections/Elasticsearch/ElasticsearchIndex/ElasticsearchIndex.json +100 -0
  11. package/dist/connections/Elasticsearch/ElasticsearchIndex/index.js +24 -0
  12. package/dist/connections/Elasticsearch/ElasticsearchSchema.json +457 -0
  13. package/dist/connections/Elasticsearch/ElasticsearchSearch/ElasticsearchSearch.js +54 -0
  14. package/dist/connections/Elasticsearch/ElasticsearchSearch/ElasticsearchSearch.json +380 -0
  15. package/dist/connections/Elasticsearch/ElasticsearchSearch/index.js +24 -0
  16. package/dist/connections/Elasticsearch/ElasticsearchUpdate/ElasticsearchUpdate.js +27 -0
  17. package/dist/connections/Elasticsearch/ElasticsearchUpdate/ElasticsearchUpdate.json +187 -0
  18. package/dist/connections/Elasticsearch/ElasticsearchUpdate/index.js +24 -0
  19. package/dist/connections/Elasticsearch/ElasticsearchUpdateByQuery/ElasticsearchUpdateByQuery.js +26 -0
  20. package/dist/connections/Elasticsearch/ElasticsearchUpdateByQuery/ElasticsearchUpdateByQuery.json +240 -0
  21. package/dist/connections/Elasticsearch/ElasticsearchUpdateByQuery/index.js +24 -0
  22. package/dist/index.js +7 -0
  23. package/package.json +58 -0
@@ -0,0 +1,28 @@
1
+ /*
2
+ Copyright 2020-2021 Lowdefy, Inc
3
+
4
+ Licensed under the Apache License, Version 2.0 (the "License");
5
+ you may not use this file except in compliance with the License.
6
+ You may obtain a copy of the License at
7
+
8
+ http://www.apache.org/licenses/LICENSE-2.0
9
+
10
+ Unless required by applicable law or agreed to in writing, software
11
+ distributed under the License is distributed on an "AS IS" BASIS,
12
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ See the License for the specific language governing permissions and
14
+ limitations under the License.
15
+ */ import { Client } from '@elastic/elasticsearch';
16
+ async function elasticsearchIndex({ request , connection }) {
17
+ const client = new Client(connection);
18
+ const body = {
19
+ ...request,
20
+ index: request.index || connection.index
21
+ };
22
+ const { body: response } = await client.index(body);
23
+ return {
24
+ response,
25
+ id: response._id
26
+ };
27
+ }
28
+ export default elasticsearchIndex;
@@ -0,0 +1,100 @@
1
+ {
2
+ "$schema": "http://json-schema.org/draft-07/schema#",
3
+ "title": "Lowdefy Request Schema - ElasticsearchIndex",
4
+ "type": "object",
5
+ "description": "Adds a JSON document to the specified data stream or index and makes it searchable. If the target is an index and the document already exists, the request updates the document and increments its version.",
6
+ "required": [
7
+ "body"
8
+ ],
9
+ "properties": {
10
+ "id": {
11
+ "anyOf": [
12
+ {
13
+ "type": "string"
14
+ },
15
+ {
16
+ "type": "number"
17
+ }
18
+ ],
19
+ "description": "Unique identifier for the document."
20
+ },
21
+ "index": {
22
+ "type": "string",
23
+ "description": "The name of the index."
24
+ },
25
+ "if_seq_no": {
26
+ "type": "integer",
27
+ "description": "Only perform the operation if the document has this sequence number. See Optimistic concurrency control."
28
+ },
29
+ "if_primary_term": {
30
+ "type": "integer",
31
+ "description": "Only perform the operation if the document has this primary term. See Optimistic concurrency control."
32
+ },
33
+ "op_type": {
34
+ "type": "string",
35
+ "description": "Set to create to only index the document if it does not already exist (put if absent). If a document with the specified _id already exists, the indexing operation will fail. Same as using the <index>/_create endpoint. Valid values: index, create. If document id is specified, it defaults to index. Otherwise, it defaults to create. If the request targets a data stream, an op_type of create is required. See Add documents to a data stream.",
36
+ "enum": [
37
+ "index",
38
+ "create"
39
+ ],
40
+ "default": "create"
41
+ },
42
+ "pipeline": {
43
+ "type": "string",
44
+ "description": "ID of the pipeline to use to preprocess incoming documents."
45
+ },
46
+ "refresh": {
47
+ "type": "string",
48
+ "description": "If true, Elasticsearch refreshes the affected shards to make this operation visible to search, if wait_for then wait for a refresh to make this operation visible to search, if false do nothing with refreshes. Valid values: true, false, wait_for. Default: false.",
49
+ "enum": [
50
+ "true",
51
+ "false",
52
+ "wait_for"
53
+ ],
54
+ "default": false
55
+ },
56
+ "routing": {
57
+ "description": "Custom value used to route operations to a specific shard.",
58
+ "type": "string"
59
+ },
60
+ "timeout": {
61
+ "type": "string",
62
+ "description": "Period the request waits for the following operations:\n\nAutomatic index creation\nDynamic mapping updates\nWaiting for active shards\nDefaults to 1m (one minute). This guarantees Elasticsearch waits for at least the timeout before failing. The actual wait time could be longer, particularly when multiple waits occur.",
63
+ "default": "1m"
64
+ },
65
+ "version": {
66
+ "description": "Explicit version number for concurrency control. The specified version must match the current version of the document for the request to succeed.",
67
+ "type": "integer"
68
+ },
69
+ "version_type": {
70
+ "type": "string",
71
+ "description": "Specific version type: external, external_gte.",
72
+ "enum": [
73
+ "internal",
74
+ "external",
75
+ "external_gte"
76
+ ]
77
+ },
78
+ "wait_for_active_shard": {
79
+ "type": "string",
80
+ "description": "The number of shard copies that must be active before proceeding with the operation. Set to all or any positive integer up to the total number of shards in the index (number_of_replicas+1). Default: 1, the primary shard.",
81
+ "default": "1"
82
+ },
83
+ "require_alias": {
84
+ "type": "boolean",
85
+ "description": "If true, the destination must be an index alias. Defaults to false.",
86
+ "default": false
87
+ },
88
+ "body": {
89
+ "type": "object",
90
+ "description": "Request body contains the JSON source for the document data.",
91
+ "additionalProperties": true
92
+ }
93
+ },
94
+ "errorMessage": {
95
+ "type": "ElasticsearchIndex request properties should be an object.",
96
+ "required": {
97
+ "body": "ElasticsearchIndex request should have required property \"body\"."
98
+ }
99
+ }
100
+ }
@@ -0,0 +1,24 @@
1
+ /*
2
+ Copyright 2020-2021 Lowdefy, Inc
3
+
4
+ Licensed under the Apache License, Version 2.0 (the "License");
5
+ you may not use this file except in compliance with the License.
6
+ You may obtain a copy of the License at
7
+
8
+ http://www.apache.org/licenses/LICENSE-2.0
9
+
10
+ Unless required by applicable law or agreed to in writing, software
11
+ distributed under the License is distributed on an "AS IS" BASIS,
12
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ See the License for the specific language governing permissions and
14
+ limitations under the License.
15
+ */ export default {
16
+ import: {
17
+ path: 'connections/Elasticsearch/ElasticsearchIndex/ElasticsearchIndex.js',
18
+ schema: 'connections/Elasticsearch/ElasticsearchIndex/ElasticsearchIndex.json'
19
+ },
20
+ meta: {
21
+ checkRead: false,
22
+ checkWrite: true
23
+ }
24
+ };
@@ -0,0 +1,457 @@
1
+ {
2
+ "$schema": "http://json-schema.org/draft-07/schema#",
3
+ "title": "Lowdefy Connection Schema - Elasticsearch",
4
+ "type": "object",
5
+ "properties": {
6
+ "node": {
7
+ "description": "The Elasticsearch endpoint to use. It can be a single string, an array of strings, or an object (or an array of objects) that represents the node",
8
+ "examples": [
9
+ "http://localhost:9200",
10
+ "https://your.node.company.tld:443"
11
+ ],
12
+ "anyOf": [
13
+ {
14
+ "items": {
15
+ "type": "string",
16
+ "format": "uri",
17
+ "pattern": "^(https?)://"
18
+ },
19
+ "type": "array"
20
+ },
21
+ {
22
+ "$ref": "#/definitions/NodeOptions"
23
+ },
24
+ {
25
+ "items": {
26
+ "$ref": "#/definitions/NodeOptions"
27
+ },
28
+ "type": "array"
29
+ },
30
+ {
31
+ "type": "string",
32
+ "format": "uri",
33
+ "pattern": "^(https?)://"
34
+ }
35
+ ]
36
+ },
37
+ "nodes": {
38
+ "description": "The Elasticsearch endpoint to use. It can be a single string, an array of strings, or an object (or an array of objects) that represents the node",
39
+ "examples": [
40
+ {
41
+ "url": "http://localhost:9200",
42
+ "ssl": "ssl options",
43
+ "agent": "http agent options",
44
+ "id": "custom node id",
45
+ "headers": {
46
+ "X-Foo": "Bar"
47
+ },
48
+ "roles": {
49
+ "master": true,
50
+ "data": true,
51
+ "ingest": true,
52
+ "ml": false
53
+ }
54
+ },
55
+ "http://localhost:9200",
56
+ "https://your.node.company.tld:443"
57
+ ],
58
+ "anyOf": [
59
+ {
60
+ "items": {
61
+ "type": "string",
62
+ "format": "uri",
63
+ "pattern": "^(https?)://"
64
+ },
65
+ "type": "array"
66
+ },
67
+ {
68
+ "$ref": "#/definitions/NodeOptions"
69
+ },
70
+ {
71
+ "items": {
72
+ "$ref": "#/definitions/NodeOptions"
73
+ },
74
+ "type": "array"
75
+ },
76
+ {
77
+ "type": "string",
78
+ "format": "uri",
79
+ "pattern": "^(https?)://"
80
+ }
81
+ ]
82
+ },
83
+ "index": {
84
+ "description": "Default index to use for requests.",
85
+ "type": "string"
86
+ },
87
+ "auth": {
88
+ "description": "Your authentication data. You can use both basic authentication and ApiKey.",
89
+ "examples": [
90
+ {
91
+ "username": "elastic",
92
+ "password": "changeMe"
93
+ },
94
+ {
95
+ "apiKey": "base64EncodedApiKey"
96
+ }
97
+ ],
98
+ "anyOf": [
99
+ {
100
+ "$ref": "#/definitions/ApiKeyAuth"
101
+ },
102
+ {
103
+ "$ref": "#/definitions/BasicAuth"
104
+ }
105
+ ],
106
+ "errorMessage": {
107
+ "anyOf": "Elasticsearch connection property \"auth\" should be an object containing credentials"
108
+ }
109
+ },
110
+ "maxRetries": {
111
+ "description": "Max number of retries for each request.",
112
+ "type": "number",
113
+ "default": 3,
114
+ "minimum": 0
115
+ },
116
+ "requestTimeout": {
117
+ "description": "Max request timeout in milliseconds for each request.",
118
+ "type": "number",
119
+ "default": 30000,
120
+ "exclusiveMinimum": 0
121
+ },
122
+ "pingTimeout": {
123
+ "description": "Max ping request timeout in milliseconds for each request.",
124
+ "type": "number",
125
+ "default": 3000,
126
+ "exclusiveMinimum": 0
127
+ },
128
+ "sniffInterval": {
129
+ "description": "Perform a sniff operation every n milliseconds. Sniffing might not be the best solution for you, take a look here to know more: https://www.elastic.co/blog/elasticsearch-sniffing-best-practices-what-when-why-how",
130
+ "type": [
131
+ "number",
132
+ "boolean"
133
+ ],
134
+ "default": false
135
+ },
136
+ "sniffOnStart": {
137
+ "description": "Perform a sniff once the client is started. Sniffing might not be the best solution for you, take a look here to know more: https://www.elastic.co/blog/elasticsearch-sniffing-best-practices-what-when-why-how",
138
+ "type": "boolean"
139
+ },
140
+ "sniffEndpoint": {
141
+ "description": "Endpoint to ping during a sniff.",
142
+ "type": "string",
143
+ "default": "_nodes/_all/http"
144
+ },
145
+ "sniffOnConnectionFault": {
146
+ "description": "Perform a sniff on connection fault. Sniffing might not be the best solution for you, take a look here to know more: https://www.elastic.co/blog/elasticsearch-sniffing-best-practices-what-when-why-how",
147
+ "type": "boolean",
148
+ "default": false
149
+ },
150
+ "resurrectStrategy": {
151
+ "description": "Configure the node resurrection strategy.",
152
+ "enum": [
153
+ "none",
154
+ "optimistic",
155
+ "ping"
156
+ ],
157
+ "type": "string",
158
+ "default": "ping"
159
+ },
160
+ "suggestCompression": {
161
+ "description": "Adds accept-encoding header to every request.",
162
+ "type": "boolean",
163
+ "default": false
164
+ },
165
+ "compression": {
166
+ "description": "Enables gzip request body compression.",
167
+ "enum": [
168
+ "gzip"
169
+ ],
170
+ "type": [
171
+ "string",
172
+ "boolean"
173
+ ],
174
+ "default": false
175
+ },
176
+ "ssl": {
177
+ "$ref": "#/definitions/ConnectionOptions"
178
+ },
179
+ "proxy": {
180
+ "description": "If you are using an http(s) proxy, you can put its url here. The client will automatically handle the connection to it.",
181
+ "type": "string",
182
+ "format": "uri",
183
+ "pattern": "^(https?)://",
184
+ "examples": [
185
+ "http://localhost:8080",
186
+ "http://user:pwd@localhost:8080"
187
+ ],
188
+ "default": null
189
+ },
190
+ "agent": {
191
+ "description": "HTTP agent options. If you want to disable the HTTP agent use entirely (and disable the `keep-alive` feature), set the agent to `false`. See https://nodejs.org/api/http.html#http_new_agent_options.",
192
+ "default": null,
193
+ "examples": [
194
+ {
195
+ "agent": "options"
196
+ },
197
+ {
198
+ "agent": false
199
+ }
200
+ ],
201
+ "anyOf": [
202
+ {
203
+ "$ref": "#/definitions/AgentOptions"
204
+ },
205
+ {
206
+ "enum": [
207
+ false
208
+ ],
209
+ "type": "boolean"
210
+ },
211
+ {
212
+ "type": "object"
213
+ }
214
+ ]
215
+ },
216
+ "name": {
217
+ "description": "The name to identify the client instance in the events.",
218
+ "type": "string",
219
+ "default": "elasticsearch-js"
220
+ },
221
+ "opaqueIdPrefix": {
222
+ "description": "A string that will be use to prefix any X-Opaque-Id header. See https://www.elastic.co/guide/en/elasticsearch/client/javascript-api/current/observability.html#x-opaque-id_support[X-Opaque-Id support] for more details.",
223
+ "default": null,
224
+ "type": "string"
225
+ },
226
+ "headers": {
227
+ "description": "A set of custom headers to send in every request.",
228
+ "examples": [
229
+ {
230
+ "X-Foo": "Bar"
231
+ }
232
+ ],
233
+ "type": "object",
234
+ "default": { }
235
+ },
236
+ "context": {
237
+ "description": "A custom object that you can use for observability in your events. It will be merged with the API level context option.",
238
+ "type": "object",
239
+ "default": null
240
+ },
241
+ "enableMetaHeader": {
242
+ "description": "If true, adds an header named 'x-elastic-client-meta', containing some minimal telemetry data, such as the client and platform version.",
243
+ "type": "boolean",
244
+ "default": true
245
+ },
246
+ "cloud": {
247
+ "description": "Custom configuration for connecting to Elastic Cloud. See Authentication for more details: https://www.elastic.co/guide/en/elasticsearch/client/javascript-api/current/auth-reference.html",
248
+ "examples": [
249
+ {
250
+ "id": "name:bG9jYWxob3N0JGFiY2QkZWZnaA=="
251
+ }
252
+ ],
253
+ "properties": {
254
+ "id": {
255
+ "type": "string"
256
+ },
257
+ "password": {
258
+ "type": "string"
259
+ },
260
+ "username": {
261
+ "type": "string"
262
+ }
263
+ },
264
+ "type": "object",
265
+ "default": null
266
+ },
267
+ "disablePrototypePoisoningProtection": {
268
+ "description": "By the default the client will protect you against prototype poisoning attacks. If needed you can disable prototype poisoning protection entirely or one of the two checks. Read the `secure-json-parse` documentation to learn more: https://github.com/fastify/secure-json-parse",
269
+ "enum": [
270
+ "constructor",
271
+ false,
272
+ "proto",
273
+ true
274
+ ],
275
+ "default": false
276
+ },
277
+ "read": {
278
+ "type": "boolean",
279
+ "default": true,
280
+ "description": "Allow reads from the Elasticsearch index.",
281
+ "errorMessage": {
282
+ "type": "Elasticsearch connection property \"read\" should be a boolean."
283
+ }
284
+ },
285
+ "write": {
286
+ "type": "boolean",
287
+ "default": false,
288
+ "description": "Allow writes to the Elasticsearch index.",
289
+ "errorMessage": {
290
+ "type": "Elasticsearch connection property \"write\" should be a boolean."
291
+ }
292
+ }
293
+ },
294
+ "definitions": {
295
+ "AgentOptions": {
296
+ "description": "Set of configurable options to set on the agent.",
297
+ "properties": {
298
+ "keepAlive": {
299
+ "description": "Keep sockets around even when there are no outstanding requests, so they can be used for future requests without having to reestablish a TCP connection. Not to be confused with the `keep-alive` value of the `Connection` header. The `Connection: keep-alive` header is always sent when using an agent except when the `Connection` header is explicitly specified or when the `keepAlive` and `maxSockets` options are respectively set to `false` and `Infinity`, in which case `Connection: close` will be used.",
300
+ "default": false,
301
+ "type": "boolean"
302
+ },
303
+ "keepAliveMsecs": {
304
+ "description": "When using the `keepAlive` option, specifies the initial delay for TCP Keep-Alive packets. Ignored when the `keepAlive` option is `false` or `undefined`",
305
+ "type": "number",
306
+ "default": 1000
307
+ },
308
+ "maxFreeSockets": {
309
+ "description": "Maximum number of sockets to leave open in a free state. Only relevant if `keepAlive` is set to `true`",
310
+ "type": "number",
311
+ "default": 256
312
+ },
313
+ "maxSockets": {
314
+ "description": "Maximum number of sockets to allow per host. If the same host opens multiple concurrent connections, each request will use new socket until the `maxSockets` value is reached. If the host attempts to open more connections than `maxSockets`, the additional requests will enter into a pending request queue, and will enter active connection state when an existing connection terminates. This makes sure there are at most maxSockets active connections at any point in time, from a given host.",
315
+ "type": "number",
316
+ "default": "Infinity"
317
+ }
318
+ },
319
+ "type": "object"
320
+ },
321
+ "ApiKeyAuth": {
322
+ "description": "The apiKey parameter can be either a base64 encoded string or an object with the values that you can obtain from the create api key endpoint. If you provide both basic authentication credentials and the ApiKey configuration, the ApiKey takes precedence.",
323
+ "properties": {
324
+ "apiKey": {
325
+ "anyOf": [
326
+ {
327
+ "properties": {
328
+ "api_key": {
329
+ "type": "string"
330
+ },
331
+ "id": {
332
+ "type": "string"
333
+ }
334
+ },
335
+ "type": "object"
336
+ },
337
+ {
338
+ "type": "string"
339
+ }
340
+ ],
341
+ "errorMessage": {
342
+ "anyOf": "Elasticsearch API key should be specified as a string, or an object containing Elasticsearch cloud credentials"
343
+ }
344
+ }
345
+ },
346
+ "required": [
347
+ "apiKey"
348
+ ],
349
+ "type": "object"
350
+ },
351
+ "BasicAuth": {
352
+ "properties": {
353
+ "password": {
354
+ "type": "string"
355
+ },
356
+ "username": {
357
+ "type": "string"
358
+ }
359
+ },
360
+ "required": [
361
+ "username"
362
+ ],
363
+ "type": "object",
364
+ "errorMessage": {
365
+ "required": "Elasticsearch basic auth credentials must consist of at least a username"
366
+ }
367
+ },
368
+ "ConnectionOptions": {
369
+ "description": "http.SecureContextOptions - See node.js SSL configuration: https://nodejs.org/api/tls.html",
370
+ "type": "object",
371
+ "default": null
372
+ },
373
+ "NodeOptions": {
374
+ "examples": [
375
+ {
376
+ "url": "http://localhost:9200",
377
+ "ssl": "ssl options",
378
+ "agent": "http agent options",
379
+ "id": "custom node id",
380
+ "headers": {
381
+ "X-Foo": "Bar"
382
+ },
383
+ "roles": {
384
+ "master": true,
385
+ "data": true,
386
+ "ingest": true,
387
+ "ml": false
388
+ }
389
+ }
390
+ ],
391
+ "properties": {
392
+ "agent": {
393
+ "$ref": "#/definitions/AgentOptions"
394
+ },
395
+ "headers": {
396
+ "type": "object",
397
+ "examples": [
398
+ {
399
+ "X-Foo": "Bar"
400
+ }
401
+ ]
402
+ },
403
+ "id": {
404
+ "type": "string"
405
+ },
406
+ "roles": {
407
+ "properties": {
408
+ "data": {
409
+ "type": "boolean"
410
+ },
411
+ "ingest": {
412
+ "type": "boolean"
413
+ },
414
+ "master": {
415
+ "type": "boolean"
416
+ },
417
+ "ml": {
418
+ "type": "boolean"
419
+ }
420
+ },
421
+ "type": "object"
422
+ },
423
+ "ssl": {
424
+ "$ref": "#/definitions/ConnectionOptions"
425
+ },
426
+ "url": {
427
+ "type": "string",
428
+ "format": "uri",
429
+ "pattern": "^(https?)://"
430
+ }
431
+ },
432
+ "type": "object"
433
+ }
434
+ },
435
+ "oneOf": [
436
+ {
437
+ "required": [
438
+ "node"
439
+ ]
440
+ },
441
+ {
442
+ "required": [
443
+ "nodes"
444
+ ]
445
+ }
446
+ ],
447
+ "errorMessage": {
448
+ "type": "Elasticsearch connection properties should be an object.",
449
+ "oneOf": "Elasticsearch connection should have required property \"node\" or \"nodes\".",
450
+ "properties": {
451
+ "maxRetries": "Elasticsearch connection \"maxRetries\" should be 0 or greater",
452
+ "requestTimeout": "Elasticsearch connection \"requestTimeout\" should be 1 or greater",
453
+ "pingTimeout": "Elasticsearch connection \"pingTimeout\" should be 1 or greater",
454
+ "index": "Elasticsearch connection property \"index\" should be a string"
455
+ }
456
+ }
457
+ }
@@ -0,0 +1,54 @@
1
+ /*
2
+ Copyright 2020-2021 Lowdefy, Inc
3
+
4
+ Licensed under the Apache License, Version 2.0 (the "License");
5
+ you may not use this file except in compliance with the License.
6
+ You may obtain a copy of the License at
7
+
8
+ http://www.apache.org/licenses/LICENSE-2.0
9
+
10
+ Unless required by applicable law or agreed to in writing, software
11
+ distributed under the License is distributed on an "AS IS" BASIS,
12
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ See the License for the specific language governing permissions and
14
+ limitations under the License.
15
+ */ import { Client } from '@elastic/elasticsearch';
16
+ import { get } from '@lowdefy/helpers';
17
+ import schema from './ElasticsearchSearch.json';
18
+ async function elasticsearchSearch({ request , connection }) {
19
+ const client = new Client(connection);
20
+ const { body: response } = await client.search({
21
+ ...request,
22
+ index: request.index || connection.index
23
+ });
24
+ const rawHits = get(response, 'hits.hits', {
25
+ default: []
26
+ });
27
+ // Return the actual documents as hits.
28
+ // Map the documents to a more useful representation in our context:
29
+ // We return the results in the _source field as the main results
30
+ // and return all other fields in the _meta field.
31
+ const hits = rawHits.map((hit)=>{
32
+ const { _source , ..._meta } = hit;
33
+ return {
34
+ ..._source,
35
+ _meta
36
+ };
37
+ });
38
+ return {
39
+ response,
40
+ hits,
41
+ total: get(response, 'hits.total', {
42
+ default: {
43
+ }
44
+ }),
45
+ maxScore: get(response, 'hits.max_score', {
46
+ default: 0
47
+ }),
48
+ aggregations: get(response, 'aggregations', {
49
+ default: {
50
+ }
51
+ })
52
+ };
53
+ }
54
+ export default elasticsearchSearch;