@elastic/elasticsearch 7.7.0-rc.2 → 7.8.0

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 (49) hide show
  1. package/README.md +2 -0
  2. package/api/api/async_search.submit.js +4 -0
  3. package/api/api/autoscaling.delete_autoscaling_policy.js +78 -0
  4. package/api/api/autoscaling.get_autoscaling_policy.js +78 -0
  5. package/api/api/autoscaling.put_autoscaling_policy.js +82 -0
  6. package/api/api/bulk.js +4 -0
  7. package/api/api/cluster.delete_component_template.js +1 -1
  8. package/api/api/cluster.delete_voting_config_exclusions.js +79 -0
  9. package/api/api/cluster.exists_component_template.js +86 -0
  10. package/api/api/cluster.get_component_template.js +1 -1
  11. package/api/api/cluster.post_voting_config_exclusions.js +82 -0
  12. package/api/api/cluster.put_component_template.js +1 -1
  13. package/api/api/delete_by_query.js +4 -0
  14. package/api/api/eql.search.js +1 -1
  15. package/api/api/exists.js +4 -0
  16. package/api/api/exists_source.js +4 -0
  17. package/api/api/explain.js +4 -0
  18. package/api/api/get.js +4 -0
  19. package/api/api/get_source.js +4 -0
  20. package/api/api/indices.delete_index_template.js +86 -0
  21. package/api/api/indices.exists_index_template.js +88 -0
  22. package/api/api/indices.get_index_template.js +87 -0
  23. package/api/api/indices.put_index_template.js +91 -0
  24. package/api/api/indices.simulate_index_template.js +87 -0
  25. package/api/api/mget.js +4 -0
  26. package/api/api/ml.delete_data_frame_analytics.js +2 -1
  27. package/api/api/ml.validate.js +1 -0
  28. package/api/api/ml.validate_detector.js +1 -0
  29. package/api/api/search.js +4 -0
  30. package/api/api/searchable_snapshots.clear_cache.js +83 -0
  31. package/api/api/searchable_snapshots.mount.js +94 -0
  32. package/api/api/searchable_snapshots.repository_stats.js +78 -0
  33. package/api/api/searchable_snapshots.stats.js +77 -0
  34. package/api/api/snapshot.cleanup_repository.js +1 -1
  35. package/api/api/tasks.cancel.js +2 -0
  36. package/api/api/update.js +4 -0
  37. package/api/api/update_by_query.js +4 -0
  38. package/api/index.js +39 -1
  39. package/api/requestParams.d.ts +119 -3
  40. package/index.d.ts +156 -16
  41. package/index.js +9 -2
  42. package/lib/Connection.js +8 -2
  43. package/lib/Helpers.d.ts +22 -5
  44. package/lib/Helpers.js +328 -32
  45. package/lib/Transport.js +30 -15
  46. package/lib/pool/BaseConnectionPool.js +2 -0
  47. package/lib/pool/CloudConnectionPool.js +1 -1
  48. package/lib/pool/ConnectionPool.js +12 -2
  49. package/package.json +21 -13
package/index.js CHANGED
@@ -4,13 +4,16 @@
4
4
 
5
5
  'use strict'
6
6
 
7
+ const nodeMajor = Number(process.versions.node.split('.')[0])
8
+
7
9
  const { EventEmitter } = require('events')
8
10
  const { URL } = require('url')
9
11
  const debug = require('debug')('elasticsearch')
10
12
  const Transport = require('./lib/Transport')
11
13
  const Connection = require('./lib/Connection')
12
14
  const { ConnectionPool, CloudConnectionPool } = require('./lib/pool')
13
- const Helpers = require('./lib/Helpers')
15
+ // Helpers works only in Node.js >= 10
16
+ const Helpers = nodeMajor < 10 ? /* istanbul ignore next */ null : require('./lib/Helpers')
14
17
  const Serializer = require('./lib/Serializer')
15
18
  const errors = require('./lib/errors')
16
19
  const { ConfigurationError } = errors
@@ -127,7 +130,10 @@ class Client extends EventEmitter {
127
130
  opaqueIdPrefix: options.opaqueIdPrefix
128
131
  })
129
132
 
130
- this.helpers = new Helpers({ client: this, maxRetries: options.maxRetries })
133
+ /* istanbul ignore else */
134
+ if (Helpers !== null) {
135
+ this.helpers = new Helpers({ client: this, maxRetries: options.maxRetries })
136
+ }
131
137
 
132
138
  const apis = buildApi({
133
139
  makeRequest: this.transport.request.bind(this.transport),
@@ -232,6 +238,7 @@ function getAuth (node) {
232
238
  return null
233
239
 
234
240
  function getUsernameAndPassword (node) {
241
+ /* istanbul ignore else */
235
242
  if (typeof node === 'string') {
236
243
  const { username, password } = new URL(node)
237
244
  return {
package/lib/Connection.js CHANGED
@@ -20,7 +20,7 @@ const {
20
20
  } = require('./errors')
21
21
 
22
22
  class Connection {
23
- constructor (opts = {}) {
23
+ constructor (opts) {
24
24
  this.url = opts.url
25
25
  this.ssl = opts.ssl || null
26
26
  this.id = opts.id || stripAuth(opts.url.href)
@@ -64,6 +64,7 @@ class Connection {
64
64
  // https://github.com/nodejs/node/commit/b961d9fd83
65
65
  if (INVALID_PATH_REGEX.test(requestParams.path) === true) {
66
66
  callback(new TypeError(`ERR_UNESCAPED_CHARACTERS: ${requestParams.path}`), null)
67
+ /* istanbul ignore next */
67
68
  return { abort: () => {} }
68
69
  }
69
70
 
@@ -73,6 +74,7 @@ class Connection {
73
74
  // listen for the response event
74
75
  // TODO: handle redirects?
75
76
  request.on('response', response => {
77
+ /* istanbul ignore else */
76
78
  if (ended === false) {
77
79
  ended = true
78
80
  this._openRequests--
@@ -87,6 +89,7 @@ class Connection {
87
89
 
88
90
  // handles request timeout
89
91
  request.on('timeout', () => {
92
+ /* istanbul ignore else */
90
93
  if (ended === false) {
91
94
  ended = true
92
95
  this._openRequests--
@@ -97,6 +100,7 @@ class Connection {
97
100
 
98
101
  // handles request error
99
102
  request.on('error', err => {
103
+ /* istanbul ignore else */
100
104
  if (ended === false) {
101
105
  ended = true
102
106
  this._openRequests--
@@ -107,6 +111,7 @@ class Connection {
107
111
  // updates the ended state
108
112
  request.on('abort', () => {
109
113
  debug('Request aborted', params)
114
+ /* istanbul ignore else */
110
115
  if (ended === false) {
111
116
  ended = true
112
117
  this._openRequests--
@@ -121,7 +126,7 @@ class Connection {
121
126
  if (isStream(params.body) === true) {
122
127
  pump(params.body, request, err => {
123
128
  /* istanbul ignore if */
124
- if (err != null && ended === false) {
129
+ if (err != null && /* istanbul ignore next */ ended === false) {
125
130
  ended = true
126
131
  this._openRequests--
127
132
  callback(err, null)
@@ -300,6 +305,7 @@ function resolve (host, path) {
300
305
 
301
306
  function prepareHeaders (headers = {}, auth) {
302
307
  if (auth != null && headers.authorization == null) {
308
+ /* istanbul ignore else */
303
309
  if (auth.apiKey) {
304
310
  if (typeof auth.apiKey === 'object') {
305
311
  headers.authorization = 'ApiKey ' + Buffer.from(`${auth.apiKey.id}:${auth.apiKey.api_key}`).toString('base64')
package/lib/Helpers.d.ts CHANGED
@@ -3,13 +3,14 @@
3
3
  // See the LICENSE file in the project root for more information
4
4
 
5
5
  import { Readable as ReadableStream } from 'stream'
6
- import { TransportRequestOptions, ApiResponse, RequestBody } from './Transport'
7
- import { Search, Bulk } from '../api/requestParams'
6
+ import { TransportRequestOptions, ApiError, ApiResponse, RequestBody } from './Transport'
7
+ import { Search, Msearch, Bulk } from '../api/requestParams'
8
8
 
9
9
  export default class Helpers {
10
10
  search<TDocument = unknown, TRequestBody extends RequestBody = Record<string, any>>(params: Search<TRequestBody>, options?: TransportRequestOptions): Promise<TDocument[]>
11
11
  scrollSearch<TDocument = unknown, TResponse = Record<string, any>, TRequestBody extends RequestBody = Record<string, any>, TContext = unknown>(params: Search<TRequestBody>, options?: TransportRequestOptions): AsyncIterable<ScrollSearchResponse<TDocument, TResponse, TContext>>
12
12
  scrollDocuments<TDocument = unknown, TRequestBody extends RequestBody = Record<string, any>>(params: Search<TRequestBody>, options?: TransportRequestOptions): AsyncIterable<TDocument>
13
+ msearch(options?: MsearchHelperOptions): MsearchHelper
13
14
  bulk<TDocument = unknown>(options: BulkHelperOptions<TDocument>): BulkHelper<BulkStats>
14
15
  }
15
16
 
@@ -68,10 +69,11 @@ export interface BulkHelperOptions<TDocument = unknown> extends Omit<Bulk, 'body
68
69
  datasource: TDocument[] | Buffer | ReadableStream | AsyncIterator<TDocument>
69
70
  onDocument: (doc: TDocument) => Action
70
71
  flushBytes?: number
72
+ flushInterval?: number
71
73
  concurrency?: number
72
74
  retries?: number
73
- wait?: number,
74
- onDrop?: (doc: OnDropDocument<TDocument>) => void,
75
+ wait?: number
76
+ onDrop?: (doc: OnDropDocument<TDocument>) => void
75
77
  refreshOnCompletion?: boolean | string
76
78
  }
77
79
 
@@ -87,4 +89,19 @@ export interface OnDropDocument<TDocument = unknown> {
87
89
  }
88
90
  document: TDocument
89
91
  retried: boolean
90
- }
92
+ }
93
+
94
+ export interface MsearchHelperOptions extends Omit<Msearch, 'body'> {
95
+ operations?: number
96
+ flushInterval?: number
97
+ concurrency?: number
98
+ retries?: number
99
+ wait?: number
100
+ }
101
+
102
+ declare type callbackFn<Response, Context> = (err: ApiError, result: ApiResponse<Response, Context>) => void;
103
+ export interface MsearchHelper extends Promise<void> {
104
+ stop(error?: Error): void
105
+ search<TResponse = Record<string, any>, TRequestBody extends RequestBody = Record<string, any>, TContext = unknown>(header: Omit<Search, 'body'>, body: TRequestBody): Promise<ApiResponse<TResponse, TContext>>
106
+ search<TResponse = Record<string, any>, TRequestBody extends RequestBody = Record<string, any>, TContext = unknown>(header: Omit<Search, 'body'>, body: TRequestBody, callback: callbackFn<TResponse, TContext>): void
107
+ }