@elastic/elasticsearch 7.11.0 → 7.14.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.
- package/README.md +4 -2
- package/api/api/async_search.js +11 -11
- package/api/api/autoscaling.js +12 -12
- package/api/api/bulk.js +4 -4
- package/api/api/cat.js +127 -127
- package/api/api/ccr.js +40 -40
- package/api/api/clear_scroll.js +2 -2
- package/api/api/close_point_in_time.js +2 -2
- package/api/api/cluster.js +36 -36
- package/api/api/count.js +3 -3
- package/api/api/create.js +5 -5
- package/api/api/dangling_indices.js +8 -8
- package/api/api/delete.js +4 -4
- package/api/api/delete_by_query.js +5 -5
- package/api/api/delete_by_query_rethrottle.js +4 -4
- package/api/api/delete_script.js +3 -3
- package/api/api/enrich.js +14 -14
- package/api/api/eql.js +41 -10
- package/api/api/exists.js +4 -4
- package/api/api/exists_source.js +6 -6
- package/api/api/explain.js +4 -4
- package/api/api/features.js +81 -0
- package/api/api/field_caps.js +2 -2
- package/api/api/fleet.js +65 -0
- package/api/api/get.js +4 -4
- package/api/api/get_script.js +3 -3
- package/api/api/get_script_context.js +2 -2
- package/api/api/get_script_languages.js +2 -2
- package/api/api/get_source.js +4 -4
- package/api/api/graph.js +4 -4
- package/api/api/ilm.js +50 -28
- package/api/api/index.js +4 -4
- package/api/api/indices.js +381 -381
- package/api/api/info.js +2 -2
- package/api/api/ingest.js +37 -15
- package/api/api/license.js +14 -14
- package/api/api/logstash.js +125 -0
- package/api/api/mget.js +4 -4
- package/api/api/migration.js +2 -2
- package/api/api/ml.js +338 -208
- package/api/api/monitoring.js +3 -3
- package/api/api/msearch.js +4 -4
- package/api/api/msearch_template.js +4 -4
- package/api/api/mtermvectors.js +3 -3
- package/api/api/nodes.js +12 -12
- package/api/api/open_point_in_time.js +2 -2
- package/api/api/ping.js +2 -2
- package/api/api/put_script.js +5 -5
- package/api/api/rank_eval.js +3 -3
- package/api/api/reindex.js +3 -3
- package/api/api/reindex_rethrottle.js +4 -4
- package/api/api/render_search_template.js +2 -2
- package/api/api/rollup.js +31 -31
- package/api/api/scripts_painless_execute.js +2 -2
- package/api/api/scroll.js +2 -2
- package/api/api/search.js +5 -5
- package/api/api/search_shards.js +2 -2
- package/api/api/search_template.js +4 -4
- package/api/api/searchable_snapshots.js +42 -15
- package/api/api/security.js +464 -86
- package/api/api/shutdown.js +124 -0
- package/api/api/slm.js +21 -21
- package/api/api/snapshot.js +76 -48
- package/api/api/sql.js +96 -12
- package/api/api/ssl.js +2 -2
- package/api/api/tasks.js +7 -7
- package/api/api/terms_enum.js +56 -0
- package/api/api/termvectors.js +3 -3
- package/api/api/text_structure.js +65 -0
- package/api/api/transform.js +25 -25
- package/api/api/update.js +5 -5
- package/api/api/update_by_query.js +4 -4
- package/api/api/update_by_query_rethrottle.js +4 -4
- package/api/api/watcher.js +29 -29
- package/api/api/xpack.js +4 -4
- package/api/index.js +179 -120
- package/api/new.d.ts +1584 -0
- package/api/requestParams.d.ts +203 -7
- package/api/types.d.ts +15455 -0
- package/api/utils.js +4 -4
- package/free-report-junit.xml +3410 -0
- package/index.d.ts +326 -23
- package/index.js +28 -36
- package/lib/Connection.js +6 -4
- package/lib/Helpers.d.ts +4 -2
- package/lib/Helpers.js +31 -17
- package/lib/Serializer.d.ts +5 -0
- package/lib/Serializer.js +17 -6
- package/lib/Transport.d.ts +4 -2
- package/lib/Transport.js +194 -79
- package/lib/errors.d.ts +7 -0
- package/lib/errors.js +26 -2
- package/lib/pool/BaseConnectionPool.js +3 -3
- package/lib/pool/ConnectionPool.js +4 -5
- package/lib/pool/index.d.ts +5 -0
- package/package.json +26 -26
- package/api/kibana.d.ts +0 -485
package/lib/Transport.js
CHANGED
|
@@ -24,12 +24,14 @@ const os = require('os')
|
|
|
24
24
|
const { gzip, unzip, createGzip } = require('zlib')
|
|
25
25
|
const buffer = require('buffer')
|
|
26
26
|
const ms = require('ms')
|
|
27
|
+
const { EventEmitter } = require('events')
|
|
27
28
|
const {
|
|
28
29
|
ConnectionError,
|
|
29
30
|
RequestAbortedError,
|
|
30
31
|
NoLivingConnectionsError,
|
|
31
32
|
ResponseError,
|
|
32
|
-
ConfigurationError
|
|
33
|
+
ConfigurationError,
|
|
34
|
+
ProductNotSupportedError
|
|
33
35
|
} = require('./errors')
|
|
34
36
|
|
|
35
37
|
const noop = () => {}
|
|
@@ -38,6 +40,9 @@ const clientVersion = require('../package.json').version
|
|
|
38
40
|
const userAgent = `elasticsearch-js/${clientVersion} (${os.platform()} ${os.release()}-${os.arch()}; Node.js ${process.version})`
|
|
39
41
|
const MAX_BUFFER_LENGTH = buffer.constants.MAX_LENGTH
|
|
40
42
|
const MAX_STRING_LENGTH = buffer.constants.MAX_STRING_LENGTH
|
|
43
|
+
const kProductCheck = Symbol('product check')
|
|
44
|
+
const kApiVersioning = Symbol('api versioning')
|
|
45
|
+
const kEventEmitter = Symbol('event emitter')
|
|
41
46
|
|
|
42
47
|
class Transport {
|
|
43
48
|
constructor (opts) {
|
|
@@ -64,6 +69,9 @@ class Transport {
|
|
|
64
69
|
this.generateRequestId = opts.generateRequestId || generateRequestId()
|
|
65
70
|
this.name = opts.name
|
|
66
71
|
this.opaqueIdPrefix = opts.opaqueIdPrefix
|
|
72
|
+
this[kProductCheck] = 0 // 0 = to be checked, 1 = checking, 2 = checked-ok, 3 checked-notok, 4 checked-nodefault
|
|
73
|
+
this[kApiVersioning] = process.env.ELASTIC_CLIENT_APIVERSIONING === 'true'
|
|
74
|
+
this[kEventEmitter] = new EventEmitter()
|
|
67
75
|
|
|
68
76
|
this.nodeFilter = opts.nodeFilter || defaultNodeFilter
|
|
69
77
|
if (typeof opts.nodeSelector === 'function') {
|
|
@@ -81,7 +89,11 @@ class Transport {
|
|
|
81
89
|
this._isSniffing = false
|
|
82
90
|
|
|
83
91
|
if (opts.sniffOnStart === true) {
|
|
84
|
-
|
|
92
|
+
// timer needed otherwise it will clash
|
|
93
|
+
// with the product check testing
|
|
94
|
+
setTimeout(() => {
|
|
95
|
+
this.sniff({ reason: Transport.sniffReasons.SNIFF_ON_START })
|
|
96
|
+
}, 10)
|
|
85
97
|
}
|
|
86
98
|
}
|
|
87
99
|
|
|
@@ -91,7 +103,7 @@ class Transport {
|
|
|
91
103
|
callback = options
|
|
92
104
|
options = {}
|
|
93
105
|
}
|
|
94
|
-
|
|
106
|
+
let p = null
|
|
95
107
|
|
|
96
108
|
// promises support
|
|
97
109
|
if (callback === undefined) {
|
|
@@ -147,9 +159,10 @@ class Transport {
|
|
|
147
159
|
// the size of the stream, we risk to take too much memory.
|
|
148
160
|
// Furthermore, copying everytime the stream is very a expensive operation.
|
|
149
161
|
const maxRetries = isStream(params.body) || isStream(params.bulkBody)
|
|
150
|
-
? 0
|
|
162
|
+
? 0
|
|
163
|
+
: (typeof options.maxRetries === 'number' ? options.maxRetries : this.maxRetries)
|
|
151
164
|
const compression = options.compression !== undefined ? options.compression : this.compression
|
|
152
|
-
|
|
165
|
+
let request = { abort: noop }
|
|
153
166
|
const transportReturn = {
|
|
154
167
|
then (onFulfilled, onRejected) {
|
|
155
168
|
return p.then(onFulfilled, onRejected)
|
|
@@ -162,6 +175,9 @@ class Transport {
|
|
|
162
175
|
request.abort()
|
|
163
176
|
debug('Aborting request', params)
|
|
164
177
|
return this
|
|
178
|
+
},
|
|
179
|
+
finally (onFinally) {
|
|
180
|
+
return p.finally(onFinally)
|
|
165
181
|
}
|
|
166
182
|
}
|
|
167
183
|
|
|
@@ -291,7 +307,8 @@ class Transport {
|
|
|
291
307
|
// - the request is not a HEAD request
|
|
292
308
|
// - the payload is not an empty string
|
|
293
309
|
if (result.headers['content-type'] !== undefined &&
|
|
294
|
-
result.headers['content-type'].indexOf('application/json') > -1
|
|
310
|
+
(result.headers['content-type'].indexOf('application/json') > -1 ||
|
|
311
|
+
result.headers['content-type'].indexOf('application/vnd.elasticsearch+json') > -1) &&
|
|
295
312
|
isHead === false &&
|
|
296
313
|
payload !== ''
|
|
297
314
|
) {
|
|
@@ -302,8 +319,8 @@ class Transport {
|
|
|
302
319
|
return callback(err, result)
|
|
303
320
|
}
|
|
304
321
|
} else {
|
|
305
|
-
// cast to boolean if the request method was HEAD
|
|
306
|
-
result.body = isHead === true ? true : payload
|
|
322
|
+
// cast to boolean if the request method was HEAD and there was no error
|
|
323
|
+
result.body = isHead === true && result.statusCode < 400 ? true : payload
|
|
307
324
|
}
|
|
308
325
|
|
|
309
326
|
// we should ignore the statusCode if the user has configured the `ignore` field with
|
|
@@ -343,91 +360,130 @@ class Transport {
|
|
|
343
360
|
}
|
|
344
361
|
}
|
|
345
362
|
|
|
346
|
-
|
|
347
|
-
|
|
363
|
+
const prepareRequest = () => {
|
|
364
|
+
this.emit('serialization', null, result)
|
|
365
|
+
const headers = Object.assign({}, this.headers, lowerCaseHeaders(options.headers))
|
|
348
366
|
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
367
|
+
if (options.opaqueId !== undefined) {
|
|
368
|
+
headers['x-opaque-id'] = this.opaqueIdPrefix !== null
|
|
369
|
+
? this.opaqueIdPrefix + options.opaqueId
|
|
370
|
+
: options.opaqueId
|
|
371
|
+
}
|
|
354
372
|
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
373
|
+
// handle json body
|
|
374
|
+
if (params.body != null) {
|
|
375
|
+
if (shouldSerialize(params.body) === true) {
|
|
376
|
+
try {
|
|
377
|
+
params.body = this.serializer.serialize(params.body)
|
|
378
|
+
} catch (err) {
|
|
379
|
+
this.emit('request', err, result)
|
|
380
|
+
process.nextTick(callback, err, result)
|
|
381
|
+
return transportReturn
|
|
382
|
+
}
|
|
383
|
+
}
|
|
384
|
+
|
|
385
|
+
if (params.body !== '') {
|
|
386
|
+
headers['content-type'] = headers['content-type'] || (this[kApiVersioning] ? 'application/vnd.elasticsearch+json; compatible-with=7' : 'application/json')
|
|
387
|
+
}
|
|
388
|
+
|
|
389
|
+
// handle ndjson body
|
|
390
|
+
} else if (params.bulkBody != null) {
|
|
391
|
+
if (shouldSerialize(params.bulkBody) === true) {
|
|
392
|
+
try {
|
|
393
|
+
params.body = this.serializer.ndserialize(params.bulkBody)
|
|
394
|
+
} catch (err) {
|
|
395
|
+
this.emit('request', err, result)
|
|
396
|
+
process.nextTick(callback, err, result)
|
|
397
|
+
return transportReturn
|
|
398
|
+
}
|
|
399
|
+
} else {
|
|
400
|
+
params.body = params.bulkBody
|
|
401
|
+
}
|
|
402
|
+
if (params.body !== '') {
|
|
403
|
+
headers['content-type'] = headers['content-type'] || (this[kApiVersioning] ? 'application/vnd.elasticsearch+x-ndjson; compatible-with=7' : 'application/x-ndjson')
|
|
364
404
|
}
|
|
365
405
|
}
|
|
366
406
|
|
|
367
|
-
|
|
368
|
-
|
|
407
|
+
params.headers = headers
|
|
408
|
+
// serializes the querystring
|
|
409
|
+
if (options.querystring == null) {
|
|
410
|
+
params.querystring = this.serializer.qserialize(params.querystring)
|
|
411
|
+
} else {
|
|
412
|
+
params.querystring = this.serializer.qserialize(
|
|
413
|
+
Object.assign({}, params.querystring, options.querystring)
|
|
414
|
+
)
|
|
369
415
|
}
|
|
370
416
|
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
if (
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
417
|
+
// handles request timeout
|
|
418
|
+
params.timeout = toMs(options.requestTimeout || this.requestTimeout)
|
|
419
|
+
if (options.asStream === true) params.asStream = true
|
|
420
|
+
meta.request.params = params
|
|
421
|
+
meta.request.options = options
|
|
422
|
+
|
|
423
|
+
// handle compression
|
|
424
|
+
if (params.body !== '' && params.body != null) {
|
|
425
|
+
if (isStream(params.body) === true) {
|
|
426
|
+
if (compression === 'gzip') {
|
|
427
|
+
params.headers['content-encoding'] = compression
|
|
428
|
+
params.body = params.body.pipe(createGzip())
|
|
429
|
+
}
|
|
430
|
+
makeRequest()
|
|
431
|
+
} else if (compression === 'gzip') {
|
|
432
|
+
gzip(params.body, (err, buffer) => {
|
|
433
|
+
/* istanbul ignore next */
|
|
434
|
+
if (err) {
|
|
435
|
+
this.emit('request', err, result)
|
|
436
|
+
return callback(err, result)
|
|
437
|
+
}
|
|
438
|
+
params.headers['content-encoding'] = compression
|
|
439
|
+
params.headers['content-length'] = '' + Buffer.byteLength(buffer)
|
|
440
|
+
params.body = buffer
|
|
441
|
+
makeRequest()
|
|
442
|
+
})
|
|
443
|
+
} else {
|
|
444
|
+
params.headers['content-length'] = '' + Buffer.byteLength(params.body)
|
|
445
|
+
makeRequest()
|
|
380
446
|
}
|
|
381
447
|
} else {
|
|
382
|
-
|
|
383
|
-
}
|
|
384
|
-
if (params.body !== '') {
|
|
385
|
-
headers['content-type'] = headers['content-type'] || 'application/x-ndjson'
|
|
448
|
+
makeRequest()
|
|
386
449
|
}
|
|
387
450
|
}
|
|
388
451
|
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
params.
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
meta.request.params = params
|
|
403
|
-
meta.request.options = options
|
|
404
|
-
|
|
405
|
-
// handle compression
|
|
406
|
-
if (params.body !== '' && params.body != null) {
|
|
407
|
-
if (isStream(params.body) === true) {
|
|
408
|
-
if (compression === 'gzip') {
|
|
409
|
-
params.headers['content-encoding'] = compression
|
|
410
|
-
params.body = params.body.pipe(createGzip())
|
|
411
|
-
}
|
|
412
|
-
makeRequest()
|
|
413
|
-
} else if (compression === 'gzip') {
|
|
414
|
-
gzip(params.body, (err, buffer) => {
|
|
415
|
-
/* istanbul ignore next */
|
|
416
|
-
if (err) {
|
|
452
|
+
// still need to check the product or waiting for the check to finish
|
|
453
|
+
if (this[kProductCheck] === 0 || this[kProductCheck] === 1) {
|
|
454
|
+
// let pass info requests
|
|
455
|
+
if (params.method === 'GET' && params.path === '/') {
|
|
456
|
+
prepareRequest()
|
|
457
|
+
} else {
|
|
458
|
+
// wait for product check to finish
|
|
459
|
+
this[kEventEmitter].once('product-check', (error, status) => {
|
|
460
|
+
if (status === false) {
|
|
461
|
+
const err = error || new ProductNotSupportedError(result)
|
|
462
|
+
if (this[kProductCheck] === 4) {
|
|
463
|
+
err.message = 'The client noticed that the server is not a supported distribution of Elasticsearch'
|
|
464
|
+
}
|
|
417
465
|
this.emit('request', err, result)
|
|
418
|
-
|
|
466
|
+
process.nextTick(callback, err, result)
|
|
467
|
+
} else {
|
|
468
|
+
prepareRequest()
|
|
419
469
|
}
|
|
420
|
-
params.headers['content-encoding'] = compression
|
|
421
|
-
params.headers['content-length'] = '' + Buffer.byteLength(buffer)
|
|
422
|
-
params.body = buffer
|
|
423
|
-
makeRequest()
|
|
424
470
|
})
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
471
|
+
// the very first request triggers the product check
|
|
472
|
+
if (this[kProductCheck] === 0) {
|
|
473
|
+
this.productCheck()
|
|
474
|
+
}
|
|
428
475
|
}
|
|
476
|
+
// the product check is finished and it's not Elasticsearch
|
|
477
|
+
} else if (this[kProductCheck] === 3 || this[kProductCheck] === 4) {
|
|
478
|
+
const err = new ProductNotSupportedError(result)
|
|
479
|
+
if (this[kProductCheck] === 4) {
|
|
480
|
+
err.message = 'The client noticed that the server is not a supported distribution of Elasticsearch'
|
|
481
|
+
}
|
|
482
|
+
this.emit('request', err, result)
|
|
483
|
+
process.nextTick(callback, err, result)
|
|
484
|
+
// the product check finished and it's Elasticsearch
|
|
429
485
|
} else {
|
|
430
|
-
|
|
486
|
+
prepareRequest()
|
|
431
487
|
}
|
|
432
488
|
|
|
433
489
|
return transportReturn
|
|
@@ -487,6 +543,65 @@ class Transport {
|
|
|
487
543
|
callback(null, hosts)
|
|
488
544
|
})
|
|
489
545
|
}
|
|
546
|
+
|
|
547
|
+
productCheck () {
|
|
548
|
+
debug('Start product check')
|
|
549
|
+
this[kProductCheck] = 1
|
|
550
|
+
this.request({
|
|
551
|
+
method: 'GET',
|
|
552
|
+
path: '/'
|
|
553
|
+
}, (err, result) => {
|
|
554
|
+
this[kProductCheck] = 3
|
|
555
|
+
if (err) {
|
|
556
|
+
debug('Product check failed', err)
|
|
557
|
+
if (err.statusCode === 401 || err.statusCode === 403) {
|
|
558
|
+
this[kProductCheck] = 2
|
|
559
|
+
process.emitWarning('The client is unable to verify that the server is Elasticsearch due to security privileges on the server side. Some functionality may not be compatible if the server is running an unsupported product.')
|
|
560
|
+
this[kEventEmitter].emit('product-check', null, true)
|
|
561
|
+
} else {
|
|
562
|
+
this[kProductCheck] = 0
|
|
563
|
+
this[kEventEmitter].emit('product-check', err, false)
|
|
564
|
+
}
|
|
565
|
+
} else {
|
|
566
|
+
debug('Checking elasticsearch version', result.body, result.headers)
|
|
567
|
+
if (result.body.version == null || typeof result.body.version.number !== 'string') {
|
|
568
|
+
debug('Can\'t access Elasticsearch version')
|
|
569
|
+
return this[kEventEmitter].emit('product-check', null, false)
|
|
570
|
+
}
|
|
571
|
+
const tagline = result.body.tagline
|
|
572
|
+
const version = result.body.version.number.split('.')
|
|
573
|
+
const major = Number(version[0])
|
|
574
|
+
const minor = Number(version[1])
|
|
575
|
+
if (major < 6) {
|
|
576
|
+
return this[kEventEmitter].emit('product-check', null, false)
|
|
577
|
+
} else if (major >= 6 && major < 7) {
|
|
578
|
+
if (tagline !== 'You Know, for Search') {
|
|
579
|
+
debug('Bad tagline')
|
|
580
|
+
return this[kEventEmitter].emit('product-check', null, false)
|
|
581
|
+
}
|
|
582
|
+
} else if (major === 7 && minor < 14) {
|
|
583
|
+
if (tagline !== 'You Know, for Search') {
|
|
584
|
+
debug('Bad tagline')
|
|
585
|
+
return this[kEventEmitter].emit('product-check', null, false)
|
|
586
|
+
}
|
|
587
|
+
|
|
588
|
+
if (result.body.version.build_flavor !== 'default') {
|
|
589
|
+
debug('Bad build_flavor')
|
|
590
|
+
this[kProductCheck] = 4
|
|
591
|
+
return this[kEventEmitter].emit('product-check', null, false)
|
|
592
|
+
}
|
|
593
|
+
} else {
|
|
594
|
+
if (result.headers['x-elastic-product'] !== 'Elasticsearch') {
|
|
595
|
+
debug('x-elastic-product not recognized')
|
|
596
|
+
return this[kEventEmitter].emit('product-check', null, false)
|
|
597
|
+
}
|
|
598
|
+
}
|
|
599
|
+
debug('Valid Elasticsearch distribution')
|
|
600
|
+
this[kProductCheck] = 2
|
|
601
|
+
this[kEventEmitter].emit('product-check', null, true)
|
|
602
|
+
}
|
|
603
|
+
})
|
|
604
|
+
}
|
|
490
605
|
}
|
|
491
606
|
|
|
492
607
|
Transport.sniffReasons = {
|
|
@@ -525,7 +640,7 @@ function defaultNodeFilter (node) {
|
|
|
525
640
|
}
|
|
526
641
|
|
|
527
642
|
function roundRobinSelector () {
|
|
528
|
-
|
|
643
|
+
let current = -1
|
|
529
644
|
return function _roundRobinSelector (connections) {
|
|
530
645
|
if (++current >= connections.length) {
|
|
531
646
|
current = 0
|
|
@@ -540,8 +655,8 @@ function randomSelector (connections) {
|
|
|
540
655
|
}
|
|
541
656
|
|
|
542
657
|
function generateRequestId () {
|
|
543
|
-
|
|
544
|
-
|
|
658
|
+
const maxInt = 2147483647
|
|
659
|
+
let nextReqId = 0
|
|
545
660
|
return function genReqId (params, options) {
|
|
546
661
|
return (nextReqId = (nextReqId + 1) & maxInt)
|
|
547
662
|
}
|
package/lib/errors.d.ts
CHANGED
|
@@ -81,3 +81,10 @@ export declare class RequestAbortedError<TResponse = Record<string, any>, TConte
|
|
|
81
81
|
meta: ApiResponse<TResponse, TContext>;
|
|
82
82
|
constructor(message: string, meta: ApiResponse);
|
|
83
83
|
}
|
|
84
|
+
|
|
85
|
+
export declare class ProductNotSupportedError<TResponse = Record<string, any>, TContext = Context> extends ElasticsearchClientError {
|
|
86
|
+
name: string;
|
|
87
|
+
message: string;
|
|
88
|
+
meta: ApiResponse<TResponse, TContext>;
|
|
89
|
+
constructor(meta: ApiResponse);
|
|
90
|
+
}
|
package/lib/errors.js
CHANGED
|
@@ -90,7 +90,16 @@ class ResponseError extends ElasticsearchClientError {
|
|
|
90
90
|
super('Response Error')
|
|
91
91
|
Error.captureStackTrace(this, ResponseError)
|
|
92
92
|
this.name = 'ResponseError'
|
|
93
|
-
|
|
93
|
+
if (meta.body && meta.body.error && meta.body.error.type) {
|
|
94
|
+
if (Array.isArray(meta.body.error.root_cause)) {
|
|
95
|
+
this.message = meta.body.error.type + ': '
|
|
96
|
+
this.message += meta.body.error.root_cause.map(entry => `[${entry.type}] Reason: ${entry.reason}`).join('; ')
|
|
97
|
+
} else {
|
|
98
|
+
this.message = meta.body.error.type
|
|
99
|
+
}
|
|
100
|
+
} else {
|
|
101
|
+
this.message = 'Response Error'
|
|
102
|
+
}
|
|
94
103
|
this.meta = meta
|
|
95
104
|
}
|
|
96
105
|
|
|
@@ -108,6 +117,10 @@ class ResponseError extends ElasticsearchClientError {
|
|
|
108
117
|
get headers () {
|
|
109
118
|
return this.meta.headers
|
|
110
119
|
}
|
|
120
|
+
|
|
121
|
+
toString () {
|
|
122
|
+
return JSON.stringify(this.meta.body)
|
|
123
|
+
}
|
|
111
124
|
}
|
|
112
125
|
|
|
113
126
|
class RequestAbortedError extends ElasticsearchClientError {
|
|
@@ -120,6 +133,16 @@ class RequestAbortedError extends ElasticsearchClientError {
|
|
|
120
133
|
}
|
|
121
134
|
}
|
|
122
135
|
|
|
136
|
+
class ProductNotSupportedError extends ElasticsearchClientError {
|
|
137
|
+
constructor (meta) {
|
|
138
|
+
super('Product Not Supported Error')
|
|
139
|
+
Error.captureStackTrace(this, ProductNotSupportedError)
|
|
140
|
+
this.name = 'ProductNotSupportedError'
|
|
141
|
+
this.message = 'The client noticed that the server is not Elasticsearch and we do not support this unknown product.'
|
|
142
|
+
this.meta = meta
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
|
|
123
146
|
module.exports = {
|
|
124
147
|
ElasticsearchClientError,
|
|
125
148
|
TimeoutError,
|
|
@@ -129,5 +152,6 @@ module.exports = {
|
|
|
129
152
|
DeserializationError,
|
|
130
153
|
ConfigurationError,
|
|
131
154
|
ResponseError,
|
|
132
|
-
RequestAbortedError
|
|
155
|
+
RequestAbortedError,
|
|
156
|
+
ProductNotSupportedError
|
|
133
157
|
}
|
|
@@ -128,7 +128,7 @@ class BaseConnectionPool {
|
|
|
128
128
|
*/
|
|
129
129
|
empty (callback) {
|
|
130
130
|
debug('Emptying the connection pool')
|
|
131
|
-
|
|
131
|
+
let openConnections = this.size
|
|
132
132
|
this.connections.forEach(connection => {
|
|
133
133
|
connection.close(() => {
|
|
134
134
|
if (--openConnections === 0) {
|
|
@@ -201,7 +201,7 @@ class BaseConnectionPool {
|
|
|
201
201
|
const ids = Object.keys(nodes)
|
|
202
202
|
const hosts = []
|
|
203
203
|
|
|
204
|
-
for (
|
|
204
|
+
for (let i = 0, len = ids.length; i < len; i++) {
|
|
205
205
|
const node = nodes[ids[i]]
|
|
206
206
|
// If there is no protocol in
|
|
207
207
|
// the `publish_address` new URL will throw
|
|
@@ -210,7 +210,7 @@ class BaseConnectionPool {
|
|
|
210
210
|
// - hostname/ip:port
|
|
211
211
|
// if we encounter the second case, we should
|
|
212
212
|
// use the hostname instead of the ip
|
|
213
|
-
|
|
213
|
+
let address = node.http.publish_address
|
|
214
214
|
const parts = address.split('/')
|
|
215
215
|
// the url is in the form of hostname/ip:port
|
|
216
216
|
if (parts.length > 1) {
|
|
@@ -80,7 +80,7 @@ class ConnectionPool extends BaseConnectionPool {
|
|
|
80
80
|
// list a node that no longer exist. The following check verify
|
|
81
81
|
// that the connection is still part of the pool before
|
|
82
82
|
// marking it as dead.
|
|
83
|
-
for (
|
|
83
|
+
for (let i = 0; i < this.size; i++) {
|
|
84
84
|
if (this.connections[i].id === id) {
|
|
85
85
|
this.dead.push(id)
|
|
86
86
|
break
|
|
@@ -138,7 +138,7 @@ class ConnectionPool extends BaseConnectionPool {
|
|
|
138
138
|
path: '/',
|
|
139
139
|
timeout: this.pingTimeout
|
|
140
140
|
}, (err, response) => {
|
|
141
|
-
|
|
141
|
+
let isAlive = true
|
|
142
142
|
const statusCode = response !== null ? response.statusCode : 0
|
|
143
143
|
if (err != null ||
|
|
144
144
|
(statusCode === 502 || statusCode === 503 || statusCode === 504)) {
|
|
@@ -170,8 +170,7 @@ class ConnectionPool extends BaseConnectionPool {
|
|
|
170
170
|
isAlive: true,
|
|
171
171
|
connection
|
|
172
172
|
})
|
|
173
|
-
// eslint-disable-
|
|
174
|
-
callback(true, connection)
|
|
173
|
+
callback(true, connection) // eslint-disable-line
|
|
175
174
|
}
|
|
176
175
|
}
|
|
177
176
|
|
|
@@ -199,7 +198,7 @@ class ConnectionPool extends BaseConnectionPool {
|
|
|
199
198
|
|
|
200
199
|
// TODO: can we cache this?
|
|
201
200
|
const connections = []
|
|
202
|
-
for (
|
|
201
|
+
for (let i = 0; i < this.size; i++) {
|
|
203
202
|
const connection = this.connections[i]
|
|
204
203
|
if (noAliveConnections || connection.status === Connection.statuses.ALIVE) {
|
|
205
204
|
if (filter(connection) === true) {
|
package/lib/pool/index.d.ts
CHANGED
|
@@ -61,6 +61,10 @@ interface BasicAuth {
|
|
|
61
61
|
password: string;
|
|
62
62
|
}
|
|
63
63
|
|
|
64
|
+
interface BearerAuth {
|
|
65
|
+
bearer: string
|
|
66
|
+
}
|
|
67
|
+
|
|
64
68
|
interface resurrectOptions {
|
|
65
69
|
now?: number;
|
|
66
70
|
requestId: string;
|
|
@@ -204,6 +208,7 @@ export {
|
|
|
204
208
|
getConnectionOptions,
|
|
205
209
|
ApiKeyAuth,
|
|
206
210
|
BasicAuth,
|
|
211
|
+
BearerAuth,
|
|
207
212
|
internals,
|
|
208
213
|
resurrectOptions,
|
|
209
214
|
ResurrectEvent,
|
package/package.json
CHANGED
|
@@ -11,7 +11,8 @@
|
|
|
11
11
|
"./": "./"
|
|
12
12
|
},
|
|
13
13
|
"homepage": "http://www.elastic.co/guide/en/elasticsearch/client/javascript-api/current/index.html",
|
|
14
|
-
"version": "7.
|
|
14
|
+
"version": "7.14.1",
|
|
15
|
+
"versionCanary": "7.14.0-canary.7",
|
|
15
16
|
"keywords": [
|
|
16
17
|
"elasticsearch",
|
|
17
18
|
"elastic",
|
|
@@ -24,7 +25,6 @@
|
|
|
24
25
|
],
|
|
25
26
|
"scripts": {
|
|
26
27
|
"test": "npm run lint && tap test/{unit,acceptance}/{*,**/*}.test.js && npm run test:types",
|
|
27
|
-
"test:node8": "npm run lint && tap test/{unit,acceptance}/*.test.js",
|
|
28
28
|
"test:unit": "tap test/unit/{*,**/*}.test.js",
|
|
29
29
|
"test:acceptance": "tap test/acceptance/*.test.js",
|
|
30
30
|
"test:integration": "node test/integration/index.js",
|
|
@@ -48,37 +48,38 @@
|
|
|
48
48
|
},
|
|
49
49
|
"devDependencies": {
|
|
50
50
|
"@sinonjs/fake-timers": "github:sinonjs/fake-timers#0bfffc1",
|
|
51
|
-
"@types/node": "^
|
|
52
|
-
"convert-hrtime": "^
|
|
51
|
+
"@types/node": "^15.3.1",
|
|
52
|
+
"convert-hrtime": "^5.0.0",
|
|
53
|
+
"cross-zip": "^4.0.0",
|
|
53
54
|
"dedent": "^0.7.0",
|
|
54
|
-
"deepmerge": "^4.
|
|
55
|
+
"deepmerge": "^4.2.2",
|
|
55
56
|
"dezalgo": "^1.0.3",
|
|
56
|
-
"fast-deep-equal": "^3.1.
|
|
57
|
-
"into-stream": "^
|
|
58
|
-
"js-yaml": "^
|
|
57
|
+
"fast-deep-equal": "^3.1.3",
|
|
58
|
+
"into-stream": "^6.0.0",
|
|
59
|
+
"js-yaml": "^4.1.0",
|
|
59
60
|
"license-checker": "^25.0.1",
|
|
60
|
-
"minimist": "^1.2.
|
|
61
|
-
"
|
|
61
|
+
"minimist": "^1.2.5",
|
|
62
|
+
"node-fetch": "^2.6.1",
|
|
63
|
+
"ora": "^5.4.0",
|
|
62
64
|
"pretty-hrtime": "^1.0.3",
|
|
63
65
|
"proxy": "^1.0.2",
|
|
64
|
-
"rimraf": "^
|
|
65
|
-
"semver": "^
|
|
66
|
-
"simple-git": "^
|
|
67
|
-
"simple-statistics": "^7.0
|
|
68
|
-
"split2": "^3.
|
|
69
|
-
"standard": "^
|
|
66
|
+
"rimraf": "^3.0.2",
|
|
67
|
+
"semver": "^7.3.5",
|
|
68
|
+
"simple-git": "^2.39.0",
|
|
69
|
+
"simple-statistics": "^7.7.0",
|
|
70
|
+
"split2": "^3.2.2",
|
|
71
|
+
"standard": "^16.0.3",
|
|
70
72
|
"stoppable": "^1.1.0",
|
|
71
|
-
"tap": "^
|
|
72
|
-
"tsd": "^0.
|
|
73
|
-
"workq": "^
|
|
74
|
-
"xmlbuilder2": "^2.1
|
|
73
|
+
"tap": "^15.0.9",
|
|
74
|
+
"tsd": "^0.15.1",
|
|
75
|
+
"workq": "^3.0.0",
|
|
76
|
+
"xmlbuilder2": "^2.4.1"
|
|
75
77
|
},
|
|
76
78
|
"dependencies": {
|
|
77
|
-
"debug": "^4.
|
|
79
|
+
"debug": "^4.3.1",
|
|
78
80
|
"hpagent": "^0.1.1",
|
|
79
|
-
"ms": "^2.1.
|
|
80
|
-
"
|
|
81
|
-
"secure-json-parse": "^2.1.0"
|
|
81
|
+
"ms": "^2.1.3",
|
|
82
|
+
"secure-json-parse": "^2.4.0"
|
|
82
83
|
},
|
|
83
84
|
"license": "Apache-2.0",
|
|
84
85
|
"repository": {
|
|
@@ -89,13 +90,12 @@
|
|
|
89
90
|
"url": "https://github.com/elastic/elasticsearch-js/issues"
|
|
90
91
|
},
|
|
91
92
|
"engines": {
|
|
92
|
-
"node": ">=
|
|
93
|
+
"node": ">=12"
|
|
93
94
|
},
|
|
94
95
|
"tsd": {
|
|
95
96
|
"directory": "test/types"
|
|
96
97
|
},
|
|
97
98
|
"tap": {
|
|
98
|
-
"esm": false,
|
|
99
99
|
"ts": false,
|
|
100
100
|
"jsx": false,
|
|
101
101
|
"flow": false,
|