@elastic/elasticsearch 7.15.0 → 8.0.0-beta.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 (344) hide show
  1. package/README.md +10 -11
  2. package/index.d.ts +4 -2971
  3. package/index.js +25 -321
  4. package/lib/api/api/async_search.d.ts +23 -0
  5. package/lib/api/api/async_search.js +130 -0
  6. package/lib/api/api/async_search.js.map +1 -0
  7. package/lib/api/api/autoscaling.d.ts +23 -0
  8. package/lib/api/api/autoscaling.js +109 -0
  9. package/lib/api/api/autoscaling.js.map +1 -0
  10. package/lib/api/api/bulk.d.ts +10 -0
  11. package/lib/api/api/bulk.js +58 -0
  12. package/lib/api/api/bulk.js.map +1 -0
  13. package/lib/api/api/cat.d.ts +86 -0
  14. package/lib/api/api/cat.js +611 -0
  15. package/lib/api/api/cat.js.map +1 -0
  16. package/lib/api/api/ccr.d.ts +50 -0
  17. package/lib/api/api/ccr.js +320 -0
  18. package/lib/api/api/ccr.js.map +1 -0
  19. package/lib/api/api/clear_scroll.d.ts +10 -0
  20. package/lib/api/api/clear_scroll.js +54 -0
  21. package/lib/api/api/clear_scroll.js.map +1 -0
  22. package/lib/api/api/close_point_in_time.d.ts +10 -0
  23. package/lib/api/api/close_point_in_time.js +53 -0
  24. package/lib/api/api/close_point_in_time.js.map +1 -0
  25. package/lib/api/api/cluster.d.ts +56 -0
  26. package/lib/api/api/cluster.js +392 -0
  27. package/lib/api/api/cluster.js.map +1 -0
  28. package/lib/api/api/count.d.ts +10 -0
  29. package/lib/api/api/count.js +62 -0
  30. package/lib/api/api/count.js.map +1 -0
  31. package/lib/api/api/create.d.ts +10 -0
  32. package/lib/api/api/create.js +46 -0
  33. package/lib/api/api/create.js.map +1 -0
  34. package/lib/api/api/dangling_indices.d.ts +20 -0
  35. package/lib/api/api/dangling_indices.js +85 -0
  36. package/lib/api/api/dangling_indices.js.map +1 -0
  37. package/lib/api/api/delete.d.ts +10 -0
  38. package/lib/api/api/delete.js +39 -0
  39. package/lib/api/api/delete.js.map +1 -0
  40. package/lib/api/api/delete_by_query.d.ts +10 -0
  41. package/lib/api/api/delete_by_query.js +53 -0
  42. package/lib/api/api/delete_by_query.js.map +1 -0
  43. package/lib/api/api/delete_by_query_rethrottle.d.ts +10 -0
  44. package/lib/api/api/delete_by_query_rethrottle.js +39 -0
  45. package/lib/api/api/delete_by_query_rethrottle.js.map +1 -0
  46. package/lib/api/api/delete_script.d.ts +10 -0
  47. package/lib/api/api/delete_script.js +39 -0
  48. package/lib/api/api/delete_script.js.map +1 -0
  49. package/lib/api/api/enrich.d.ts +26 -0
  50. package/lib/api/api/enrich.js +142 -0
  51. package/lib/api/api/enrich.js.map +1 -0
  52. package/lib/api/api/eql.d.ts +23 -0
  53. package/lib/api/api/eql.js +115 -0
  54. package/lib/api/api/eql.js.map +1 -0
  55. package/lib/api/api/exists.d.ts +10 -0
  56. package/lib/api/api/exists.js +39 -0
  57. package/lib/api/api/exists.js.map +1 -0
  58. package/lib/api/api/exists_source.d.ts +10 -0
  59. package/lib/api/api/exists_source.js +39 -0
  60. package/lib/api/api/exists_source.js.map +1 -0
  61. package/lib/api/api/explain.d.ts +10 -0
  62. package/lib/api/api/explain.js +53 -0
  63. package/lib/api/api/explain.js.map +1 -0
  64. package/lib/api/api/features.d.ts +17 -0
  65. package/lib/api/api/features.js +69 -0
  66. package/lib/api/api/features.js.map +1 -0
  67. package/lib/api/api/field_caps.d.ts +10 -0
  68. package/lib/api/api/field_caps.js +62 -0
  69. package/lib/api/api/field_caps.js.map +1 -0
  70. package/lib/api/api/fleet.d.ts +20 -0
  71. package/lib/api/api/fleet.js +92 -0
  72. package/lib/api/api/fleet.js.map +1 -0
  73. package/lib/api/api/get.d.ts +10 -0
  74. package/lib/api/api/get.js +39 -0
  75. package/lib/api/api/get.js.map +1 -0
  76. package/lib/api/api/get_script.d.ts +10 -0
  77. package/lib/api/api/get_script.js +39 -0
  78. package/lib/api/api/get_script.js.map +1 -0
  79. package/lib/api/api/get_script_context.d.ts +10 -0
  80. package/lib/api/api/get_script_context.js +40 -0
  81. package/lib/api/api/get_script_context.js.map +1 -0
  82. package/lib/api/api/get_script_languages.d.ts +10 -0
  83. package/lib/api/api/get_script_languages.js +40 -0
  84. package/lib/api/api/get_script_languages.js.map +1 -0
  85. package/lib/api/api/get_source.d.ts +10 -0
  86. package/lib/api/api/get_source.js +39 -0
  87. package/lib/api/api/get_source.js.map +1 -0
  88. package/lib/api/api/graph.d.ts +14 -0
  89. package/lib/api/api/graph.js +64 -0
  90. package/lib/api/api/graph.js.map +1 -0
  91. package/lib/api/api/ilm.d.ts +44 -0
  92. package/lib/api/api/ilm.js +260 -0
  93. package/lib/api/api/ilm.js.map +1 -0
  94. package/lib/api/api/index.d.ts +10 -0
  95. package/lib/api/api/index.js +54 -0
  96. package/lib/api/api/index.js.map +1 -0
  97. package/lib/api/api/indices.d.ts +173 -0
  98. package/lib/api/api/indices.js +1381 -0
  99. package/lib/api/api/indices.js.map +1 -0
  100. package/lib/api/api/info.d.ts +10 -0
  101. package/lib/{Serializer.d.ts → api/api/info.js} +21 -11
  102. package/lib/api/api/info.js.map +1 -0
  103. package/lib/api/api/ingest.d.ts +29 -0
  104. package/lib/api/api/ingest.js +183 -0
  105. package/lib/api/api/ingest.js.map +1 -0
  106. package/lib/api/api/knn_search.d.ts +10 -0
  107. package/lib/api/api/knn_search.js +53 -0
  108. package/lib/api/api/knn_search.js.map +1 -0
  109. package/lib/api/api/license.d.ts +32 -0
  110. package/lib/api/api/license.js +173 -0
  111. package/lib/api/api/license.js.map +1 -0
  112. package/lib/api/api/logstash.d.ts +20 -0
  113. package/lib/api/api/logstash.js +91 -0
  114. package/lib/api/api/logstash.js.map +1 -0
  115. package/lib/api/api/mget.d.ts +10 -0
  116. package/lib/api/api/mget.js +62 -0
  117. package/lib/api/api/mget.js.map +1 -0
  118. package/lib/api/api/migration.d.ts +20 -0
  119. package/lib/api/api/migration.js +93 -0
  120. package/lib/api/api/migration.js.map +1 -0
  121. package/lib/api/api/ml.d.ts +221 -0
  122. package/lib/api/api/ml.js +1818 -0
  123. package/lib/api/api/ml.js.map +1 -0
  124. package/lib/api/api/monitoring.d.ts +14 -0
  125. package/lib/api/api/monitoring.js +57 -0
  126. package/lib/api/api/monitoring.js.map +1 -0
  127. package/lib/api/api/msearch.d.ts +10 -0
  128. package/lib/api/api/msearch.js +54 -0
  129. package/lib/api/api/msearch.js.map +1 -0
  130. package/lib/api/api/msearch_template.d.ts +10 -0
  131. package/lib/api/api/msearch_template.js +54 -0
  132. package/lib/api/api/msearch_template.js.map +1 -0
  133. package/lib/api/api/mtermvectors.d.ts +10 -0
  134. package/lib/api/api/mtermvectors.js +62 -0
  135. package/lib/api/api/mtermvectors.js.map +1 -0
  136. package/lib/api/api/nodes.d.ts +32 -0
  137. package/lib/api/api/nodes.js +243 -0
  138. package/lib/api/api/nodes.js.map +1 -0
  139. package/lib/api/api/open_point_in_time.d.ts +10 -0
  140. package/lib/api/api/open_point_in_time.js +39 -0
  141. package/lib/api/api/open_point_in_time.js.map +1 -0
  142. package/lib/api/api/ping.d.ts +10 -0
  143. package/lib/api/api/ping.js +40 -0
  144. package/lib/api/api/ping.js.map +1 -0
  145. package/lib/api/api/put_script.d.ts +10 -0
  146. package/lib/api/api/put_script.js +61 -0
  147. package/lib/api/api/put_script.js.map +1 -0
  148. package/lib/api/api/rank_eval.d.ts +10 -0
  149. package/lib/api/api/rank_eval.js +61 -0
  150. package/lib/api/api/rank_eval.js.map +1 -0
  151. package/lib/api/api/reindex.d.ts +10 -0
  152. package/lib/api/api/reindex.js +54 -0
  153. package/lib/api/api/reindex.js.map +1 -0
  154. package/lib/api/api/reindex_rethrottle.d.ts +10 -0
  155. package/lib/api/api/reindex_rethrottle.js +39 -0
  156. package/lib/api/api/reindex_rethrottle.js.map +1 -0
  157. package/lib/api/api/render_search_template.d.ts +10 -0
  158. package/lib/api/api/render_search_template.js +62 -0
  159. package/lib/api/api/render_search_template.js.map +1 -0
  160. package/lib/api/api/rollup.d.ts +38 -0
  161. package/lib/api/api/rollup.js +239 -0
  162. package/lib/api/api/rollup.js.map +1 -0
  163. package/lib/api/api/scripts_painless_execute.d.ts +10 -0
  164. package/lib/api/api/scripts_painless_execute.js +54 -0
  165. package/lib/api/api/scripts_painless_execute.js.map +1 -0
  166. package/lib/api/api/scroll.d.ts +10 -0
  167. package/lib/api/api/scroll.js +53 -0
  168. package/lib/api/api/scroll.js.map +1 -0
  169. package/lib/api/api/search.d.ts +10 -0
  170. package/lib/api/api/search.js +68 -0
  171. package/lib/api/api/search.js.map +1 -0
  172. package/lib/api/api/search_mvt.d.ts +10 -0
  173. package/lib/api/api/search_mvt.js +53 -0
  174. package/lib/api/api/search_mvt.js.map +1 -0
  175. package/lib/api/api/search_shards.d.ts +10 -0
  176. package/lib/api/api/search_shards.js +48 -0
  177. package/lib/api/api/search_shards.js.map +1 -0
  178. package/lib/api/api/search_template.d.ts +10 -0
  179. package/lib/api/api/search_template.js +62 -0
  180. package/lib/api/api/search_template.js.map +1 -0
  181. package/lib/api/api/searchable_snapshots.d.ts +23 -0
  182. package/lib/api/api/searchable_snapshots.js +141 -0
  183. package/lib/api/api/searchable_snapshots.js.map +1 -0
  184. package/lib/api/api/security.d.ts +140 -0
  185. package/lib/api/api/security.js +998 -0
  186. package/lib/api/api/security.js.map +1 -0
  187. package/lib/api/api/shutdown.d.ts +20 -0
  188. package/lib/api/api/shutdown.js +93 -0
  189. package/lib/api/api/shutdown.js.map +1 -0
  190. package/lib/api/api/slm.d.ts +38 -0
  191. package/lib/api/api/slm.js +214 -0
  192. package/lib/api/api/slm.js.map +1 -0
  193. package/lib/api/api/snapshot.d.ts +47 -0
  194. package/lib/api/api/snapshot.js +315 -0
  195. package/lib/api/api/snapshot.js.map +1 -0
  196. package/lib/api/api/sql.d.ts +29 -0
  197. package/lib/api/api/sql.js +178 -0
  198. package/lib/api/api/sql.js.map +1 -0
  199. package/lib/api/api/ssl.d.ts +14 -0
  200. package/lib/api/api/ssl.js +51 -0
  201. package/lib/api/api/ssl.js.map +1 -0
  202. package/lib/api/api/tasks.d.ts +20 -0
  203. package/lib/api/api/tasks.js +94 -0
  204. package/lib/api/api/tasks.js.map +1 -0
  205. package/lib/api/api/terms_enum.d.ts +10 -0
  206. package/lib/api/api/terms_enum.js +53 -0
  207. package/lib/api/api/terms_enum.js.map +1 -0
  208. package/lib/api/api/termvectors.d.ts +10 -0
  209. package/lib/api/api/termvectors.js +61 -0
  210. package/lib/api/api/termvectors.js.map +1 -0
  211. package/lib/api/api/text_structure.d.ts +14 -0
  212. package/lib/api/api/text_structure.js +57 -0
  213. package/lib/api/api/text_structure.js.map +1 -0
  214. package/lib/api/api/transform.d.ts +38 -0
  215. package/lib/api/api/transform.js +246 -0
  216. package/lib/api/api/transform.js.map +1 -0
  217. package/lib/api/api/update.d.ts +10 -0
  218. package/lib/api/api/update.js +53 -0
  219. package/lib/api/api/update.js.map +1 -0
  220. package/lib/api/api/update_by_query.d.ts +10 -0
  221. package/lib/api/api/update_by_query.js +53 -0
  222. package/lib/api/api/update_by_query.js.map +1 -0
  223. package/lib/api/api/update_by_query_rethrottle.d.ts +10 -0
  224. package/lib/api/api/update_by_query_rethrottle.js +39 -0
  225. package/lib/api/api/update_by_query_rethrottle.js.map +1 -0
  226. package/lib/api/api/watcher.d.ts +44 -0
  227. package/lib/api/api/watcher.js +291 -0
  228. package/lib/api/api/watcher.js.map +1 -0
  229. package/lib/api/api/xpack.d.ts +17 -0
  230. package/lib/api/api/xpack.js +69 -0
  231. package/lib/api/api/xpack.js.map +1 -0
  232. package/lib/api/index.d.ts +225 -0
  233. package/lib/api/index.js +520 -0
  234. package/lib/api/index.js.map +1 -0
  235. package/lib/api/types.d.ts +13525 -0
  236. package/lib/{pool/index.js → api/types.js} +3 -12
  237. package/lib/api/types.js.map +1 -0
  238. package/lib/api/typesWithBodyKey.d.ts +13931 -0
  239. package/{index.mjs → lib/api/typesWithBodyKey.js} +3 -11
  240. package/lib/api/typesWithBodyKey.js.map +1 -0
  241. package/lib/client.d.ts +69 -0
  242. package/lib/client.js +282 -0
  243. package/lib/client.js.map +1 -0
  244. package/lib/helpers.d.ts +148 -0
  245. package/lib/helpers.js +769 -0
  246. package/lib/helpers.js.map +1 -0
  247. package/lib/sniffingTransport.d.ts +4 -0
  248. package/lib/sniffingTransport.js +56 -0
  249. package/lib/sniffingTransport.js.map +1 -0
  250. package/package.json +46 -59
  251. package/tsconfig.json +37 -0
  252. package/api/api/async_search.js +0 -141
  253. package/api/api/autoscaling.js +0 -147
  254. package/api/api/bulk.js +0 -70
  255. package/api/api/cat.js +0 -648
  256. package/api/api/ccr.js +0 -403
  257. package/api/api/clear_scroll.js +0 -55
  258. package/api/api/close_point_in_time.js +0 -50
  259. package/api/api/cluster.js +0 -420
  260. package/api/api/count.js +0 -64
  261. package/api/api/create.js +0 -69
  262. package/api/api/dangling_indices.js +0 -115
  263. package/api/api/delete.js +0 -65
  264. package/api/api/delete_by_query.js +0 -71
  265. package/api/api/delete_by_query_rethrottle.js +0 -60
  266. package/api/api/delete_script.js +0 -56
  267. package/api/api/enrich.js +0 -173
  268. package/api/api/eql.js +0 -150
  269. package/api/api/exists.js +0 -65
  270. package/api/api/exists_source.js +0 -74
  271. package/api/api/explain.js +0 -65
  272. package/api/api/features.js +0 -81
  273. package/api/api/field_caps.js +0 -55
  274. package/api/api/fleet.js +0 -65
  275. package/api/api/get.js +0 -65
  276. package/api/api/get_script.js +0 -56
  277. package/api/api/get_script_context.js +0 -50
  278. package/api/api/get_script_languages.js +0 -50
  279. package/api/api/get_source.js +0 -65
  280. package/api/api/graph.js +0 -72
  281. package/api/api/ilm.js +0 -317
  282. package/api/api/index.js +0 -71
  283. package/api/api/indices.js +0 -1753
  284. package/api/api/info.js +0 -50
  285. package/api/api/ingest.js +0 -200
  286. package/api/api/license.js +0 -188
  287. package/api/api/logstash.js +0 -125
  288. package/api/api/mget.js +0 -70
  289. package/api/api/migration.js +0 -60
  290. package/api/api/ml.js +0 -2010
  291. package/api/api/monitoring.js +0 -66
  292. package/api/api/msearch.js +0 -70
  293. package/api/api/msearch_template.js +0 -70
  294. package/api/api/mtermvectors.js +0 -64
  295. package/api/api/nodes.js +0 -268
  296. package/api/api/open_point_in_time.js +0 -56
  297. package/api/api/ping.js +0 -50
  298. package/api/api/put_script.js +0 -71
  299. package/api/api/rank_eval.js +0 -61
  300. package/api/api/reindex.js +0 -56
  301. package/api/api/reindex_rethrottle.js +0 -60
  302. package/api/api/render_search_template.js +0 -55
  303. package/api/api/rollup.js +0 -319
  304. package/api/api/scripts_painless_execute.js +0 -50
  305. package/api/api/scroll.js +0 -55
  306. package/api/api/search.js +0 -64
  307. package/api/api/search_mvt.js +0 -87
  308. package/api/api/search_shards.js +0 -55
  309. package/api/api/search_template.js +0 -70
  310. package/api/api/searchable_snapshots.js +0 -186
  311. package/api/api/security.js +0 -1261
  312. package/api/api/shutdown.js +0 -124
  313. package/api/api/slm.js +0 -256
  314. package/api/api/snapshot.js +0 -439
  315. package/api/api/sql.js +0 -203
  316. package/api/api/ssl.js +0 -55
  317. package/api/api/tasks.js +0 -108
  318. package/api/api/terms_enum.js +0 -56
  319. package/api/api/termvectors.js +0 -67
  320. package/api/api/text_structure.js +0 -65
  321. package/api/api/transform.js +0 -268
  322. package/api/api/update.js +0 -69
  323. package/api/api/update_by_query.js +0 -67
  324. package/api/api/update_by_query_rethrottle.js +0 -60
  325. package/api/api/watcher.js +0 -333
  326. package/api/api/xpack.js +0 -76
  327. package/api/index.js +0 -508
  328. package/api/new.d.ts +0 -1585
  329. package/api/requestParams.d.ts +0 -2920
  330. package/api/types.d.ts +0 -15420
  331. package/api/utils.js +0 -58
  332. package/lib/Connection.d.ts +0 -99
  333. package/lib/Connection.js +0 -392
  334. package/lib/Helpers.d.ts +0 -124
  335. package/lib/Helpers.js +0 -770
  336. package/lib/Serializer.js +0 -94
  337. package/lib/Transport.d.ts +0 -162
  338. package/lib/Transport.js +0 -689
  339. package/lib/errors.d.ts +0 -90
  340. package/lib/errors.js +0 -159
  341. package/lib/pool/BaseConnectionPool.js +0 -262
  342. package/lib/pool/CloudConnectionPool.js +0 -64
  343. package/lib/pool/ConnectionPool.js +0 -246
  344. package/lib/pool/index.d.ts +0 -220
package/lib/helpers.js ADDED
@@ -0,0 +1,769 @@
1
+ "use strict";
2
+ /*
3
+ * Licensed to Elasticsearch B.V. under one or more contributor
4
+ * license agreements. See the NOTICE file distributed with
5
+ * this work for additional information regarding copyright
6
+ * ownership. Elasticsearch B.V. licenses this file to you under
7
+ * the Apache License, Version 2.0 (the "License") you may
8
+ * not use this file except in compliance with the License.
9
+ * You may obtain a copy of the License at
10
+ *
11
+ * http://www.apache.org/licenses/LICENSE-2.0
12
+ *
13
+ * Unless required by applicable law or agreed to in writing,
14
+ * software distributed under the License is distributed on an
15
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16
+ * KIND, either express or implied. See the License for the
17
+ * specific language governing permissions and limitations
18
+ * under the License.
19
+ */
20
+ var _a, _b, _c;
21
+ Object.defineProperty(exports, "__esModule", { value: true });
22
+ const tslib_1 = require("tslib");
23
+ /* eslint-disable @typescript-eslint/naming-convention */
24
+ /* eslint-disable @typescript-eslint/promise-function-async */
25
+ const assert_1 = (0, tslib_1.__importDefault)(require("assert"));
26
+ const util_1 = require("util");
27
+ const stream_1 = require("stream");
28
+ const transport_1 = require("@elastic/transport");
29
+ const { ResponseError, ConfigurationError } = transport_1.errors;
30
+ const sleep = (0, util_1.promisify)(setTimeout);
31
+ const pImmediate = (0, util_1.promisify)(setImmediate);
32
+ /* istanbul ignore next */
33
+ const noop = () => { };
34
+ const kClient = Symbol('elasticsearch-client');
35
+ const kMetaHeader = Symbol('meta header');
36
+ const kMaxRetries = Symbol('max retries');
37
+ class Helpers {
38
+ constructor(opts) {
39
+ Object.defineProperty(this, _a, {
40
+ enumerable: true,
41
+ configurable: true,
42
+ writable: true,
43
+ value: void 0
44
+ });
45
+ Object.defineProperty(this, _b, {
46
+ enumerable: true,
47
+ configurable: true,
48
+ writable: true,
49
+ value: void 0
50
+ });
51
+ Object.defineProperty(this, _c, {
52
+ enumerable: true,
53
+ configurable: true,
54
+ writable: true,
55
+ value: void 0
56
+ });
57
+ this[kClient] = opts.client;
58
+ this[kMetaHeader] = opts.metaHeader;
59
+ this[kMaxRetries] = opts.maxRetries;
60
+ }
61
+ /**
62
+ * Runs a search operation. The only difference between client.search and this utility,
63
+ * is that we are only returning the hits to the user and not the full ES response.
64
+ * This helper automatically adds `filter_path=hits.hits._source` to the querystring,
65
+ * as it will only need the documents source.
66
+ * @param {object} params - The Elasticsearch's search parameters.
67
+ * @param {object} options - The client optional configuration for this request.
68
+ * @return {array} The documents that matched the request.
69
+ */
70
+ async search(params, options = {}) {
71
+ var _d;
72
+ appendFilterPath('hits.hits._source', params, true);
73
+ options.meta = true;
74
+ const { body: result } = await this[kClient].search(params, options);
75
+ if (((_d = result.hits) === null || _d === void 0 ? void 0 : _d.hits) != null) {
76
+ return result.hits.hits.map(d => d._source);
77
+ }
78
+ return [];
79
+ }
80
+ /**
81
+ * Runs a scroll search operation. This function returns an async iterator, allowing
82
+ * the user to use a for await loop to get all the results of a given search.
83
+ * ```js
84
+ * for await (const result of client.helpers.scrollSearch({ params })) {
85
+ * console.log(result)
86
+ * }
87
+ * ```
88
+ * Each result represents the entire body of a single scroll search request,
89
+ * if you just need to scroll the results, use scrollDocuments.
90
+ * This function handles automatically retries on 429 status code.
91
+ * @param {object} params - The Elasticsearch's search parameters.
92
+ * @param {object} options - The client optional configuration for this request.
93
+ * @return {iterator} the async iterator
94
+ */
95
+ async *scrollSearch(params, options = {}) {
96
+ var _d, _e, _f, _g;
97
+ options.meta = true;
98
+ if (this[kMetaHeader] !== null) {
99
+ options.headers = (_d = options.headers) !== null && _d !== void 0 ? _d : {};
100
+ options.headers['x-elastic-client-meta'] = `${this[kMetaHeader]},h=s`;
101
+ }
102
+ const wait = (_e = options.wait) !== null && _e !== void 0 ? _e : 5000;
103
+ const maxRetries = (_f = options.maxRetries) !== null && _f !== void 0 ? _f : this[kMaxRetries];
104
+ if (Array.isArray(options.ignore)) {
105
+ options.ignore.push(429);
106
+ }
107
+ else {
108
+ options.ignore = [429];
109
+ }
110
+ params.scroll = (_g = params.scroll) !== null && _g !== void 0 ? _g : '1m';
111
+ appendFilterPath('_scroll_id', params, false);
112
+ let response;
113
+ for (let i = 0; i <= maxRetries; i++) {
114
+ response = await this[kClient].search(params, options);
115
+ if (response.statusCode !== 429)
116
+ break;
117
+ await sleep(wait);
118
+ }
119
+ (0, assert_1.default)(response !== undefined, 'The response is undefined, please file a bug report');
120
+ if (response.statusCode === 429) {
121
+ throw new ResponseError(response);
122
+ }
123
+ let scroll_id = response.body._scroll_id;
124
+ let stop = false;
125
+ const clear = async () => {
126
+ stop = true;
127
+ await this[kClient].clearScroll({ scroll_id }, { ignore: [400], ...options });
128
+ };
129
+ while (response.body.hits != null && response.body.hits.hits.length > 0) {
130
+ // scroll id is always present in the response, but it might
131
+ // change over time based on the number of shards
132
+ scroll_id = response.body._scroll_id;
133
+ // @ts-expect-error
134
+ response.clear = clear;
135
+ addDocumentsGetter(response);
136
+ // @ts-expect-error
137
+ yield response;
138
+ if (stop) {
139
+ break;
140
+ }
141
+ for (let i = 0; i <= maxRetries; i++) {
142
+ const r = await this[kClient].scroll({
143
+ scroll: params.scroll,
144
+ rest_total_hits_as_int: params.rest_total_hits_as_int,
145
+ scroll_id
146
+ }, options);
147
+ response = r;
148
+ (0, assert_1.default)(response !== undefined, 'The response is undefined, please file a bug report');
149
+ if (response.statusCode !== 429)
150
+ break;
151
+ await sleep(wait);
152
+ }
153
+ if (response.statusCode === 429) {
154
+ throw new ResponseError(response);
155
+ }
156
+ }
157
+ if (!stop) {
158
+ await clear();
159
+ }
160
+ }
161
+ /**
162
+ * Runs a scroll search operation. This function returns an async iterator, allowing
163
+ * the user to use a for await loop to get all the documents of a given search.
164
+ * ```js
165
+ * for await (const document of client.helpers.scrollSearch({ params })) {
166
+ * console.log(document)
167
+ * }
168
+ * ```
169
+ * Each document is what you will find by running a scrollSearch and iterating on the hits array.
170
+ * This helper automatically adds `filter_path=hits.hits._source` to the querystring,
171
+ * as it will only need the documents source.
172
+ * @param {object} params - The Elasticsearch's search parameters.
173
+ * @param {object} options - The client optional configuration for this request.
174
+ * @return {iterator} the async iterator
175
+ */
176
+ async *scrollDocuments(params, options = {}) {
177
+ appendFilterPath('hits.hits._source', params, true);
178
+ for await (const { documents } of this.scrollSearch(params, options)) {
179
+ for (const document of documents) {
180
+ yield document;
181
+ }
182
+ }
183
+ }
184
+ /**
185
+ * Creates a msearch helper instance. Once you configure it, you can use the provided
186
+ * `search` method to add new searches in the queue.
187
+ * @param {object} options - The configuration of the msearch operations.
188
+ * @param {object} reqOptions - The client optional configuration for this request.
189
+ * @return {object} The possible operations to run.
190
+ */
191
+ msearch(options = {}, reqOptions = {}) {
192
+ const client = this[kClient];
193
+ const { operations = 5, concurrency = 5, flushInterval = 500, retries = this[kMaxRetries], wait = 5000, ...msearchOptions } = options;
194
+ reqOptions.meta = true;
195
+ let stopReading = false;
196
+ let stopError = null;
197
+ let timeoutRef = null;
198
+ const operationsStream = new stream_1.Readable({
199
+ objectMode: true,
200
+ read(size) { }
201
+ });
202
+ const p = iterate();
203
+ const helper = {
204
+ [Symbol.toStringTag]: 'Promise',
205
+ then(onFulfilled, onRejected) {
206
+ return p.then(onFulfilled, onRejected);
207
+ },
208
+ catch(onRejected) {
209
+ return p.catch(onRejected);
210
+ },
211
+ finally(onFinally) {
212
+ return p.finally(onFinally);
213
+ },
214
+ stop(error = null) {
215
+ if (stopReading)
216
+ return;
217
+ stopReading = true;
218
+ stopError = error;
219
+ operationsStream.push(null);
220
+ },
221
+ // TODO: support abort a single search?
222
+ // NOTE: the validation checks are synchronous and the callback/promise will
223
+ // be resolved in the same tick. We might want to fix this in the future.
224
+ search(header, body) {
225
+ if (stopReading) {
226
+ const error = stopError === null
227
+ ? new ConfigurationError('The msearch processor has been stopped')
228
+ : stopError;
229
+ return Promise.reject(error);
230
+ }
231
+ if (!(typeof header === 'object' && header !== null && !Array.isArray(header))) {
232
+ return Promise.reject(new ConfigurationError('The header should be an object'));
233
+ }
234
+ if (!(typeof body === 'object' && body !== null && !Array.isArray(body))) {
235
+ return Promise.reject(new ConfigurationError('The body should be an object'));
236
+ }
237
+ let onFulfilled = null;
238
+ let onRejected = null;
239
+ const promise = new Promise((resolve, reject) => {
240
+ onFulfilled = resolve;
241
+ onRejected = reject;
242
+ });
243
+ const callback = function callback(err, result) {
244
+ err !== null ? onRejected(err) : onFulfilled(result);
245
+ };
246
+ operationsStream.push([header, body, callback]);
247
+ return promise;
248
+ }
249
+ };
250
+ return helper;
251
+ async function iterate() {
252
+ const { semaphore, finish } = buildSemaphore();
253
+ const msearchBody = [];
254
+ const callbacks = [];
255
+ let loadedOperations = 0;
256
+ timeoutRef = setTimeout(onFlushTimeout, flushInterval); // eslint-disable-line
257
+ for await (const operation of operationsStream) {
258
+ timeoutRef.refresh();
259
+ loadedOperations += 1;
260
+ msearchBody.push(operation[0], operation[1]);
261
+ callbacks.push(operation[2]);
262
+ if (loadedOperations >= operations) {
263
+ const send = await semaphore();
264
+ send(msearchBody.slice(), callbacks.slice());
265
+ msearchBody.length = 0;
266
+ callbacks.length = 0;
267
+ loadedOperations = 0;
268
+ }
269
+ }
270
+ clearTimeout(timeoutRef);
271
+ // In some cases the previos http call does not have finished,
272
+ // or we didn't reach the flush bytes threshold, so we force one last operation.
273
+ if (loadedOperations > 0) {
274
+ const send = await semaphore();
275
+ send(msearchBody, callbacks);
276
+ }
277
+ await finish();
278
+ if (stopError !== null) {
279
+ throw stopError;
280
+ }
281
+ async function onFlushTimeout() {
282
+ if (loadedOperations === 0)
283
+ return;
284
+ const msearchBodyCopy = msearchBody.slice();
285
+ const callbacksCopy = callbacks.slice();
286
+ msearchBody.length = 0;
287
+ callbacks.length = 0;
288
+ loadedOperations = 0;
289
+ try {
290
+ const send = await semaphore();
291
+ send(msearchBodyCopy, callbacksCopy);
292
+ }
293
+ catch (err) {
294
+ /* istanbul ignore next */
295
+ // @ts-expect-error
296
+ helper.stop(err);
297
+ }
298
+ }
299
+ }
300
+ // This function builds a semaphore using the concurrency
301
+ // options of the msearch helper. It is used inside the iterator
302
+ // to guarantee that no more than the number of operations
303
+ // allowed to run at the same time are executed.
304
+ // It returns a semaphore function which resolves in the next tick
305
+ // if we didn't reach the maximim concurrency yet, otherwise it returns
306
+ // a promise that resolves as soon as one of the running request has finshed.
307
+ // The semaphore function resolves a send function, which will be used
308
+ // to send the actual msearch request.
309
+ // It also returns a finish function, which returns a promise that is resolved
310
+ // when there are no longer request running.
311
+ function buildSemaphore() {
312
+ let resolveSemaphore = null;
313
+ let resolveFinish = null;
314
+ let running = 0;
315
+ return { semaphore, finish };
316
+ function finish() {
317
+ return new Promise((resolve, reject) => {
318
+ if (running === 0) {
319
+ resolve();
320
+ }
321
+ else {
322
+ resolveFinish = resolve;
323
+ }
324
+ });
325
+ }
326
+ function semaphore() {
327
+ if (running < concurrency) {
328
+ running += 1;
329
+ return pImmediate(send);
330
+ }
331
+ else {
332
+ return new Promise((resolve, reject) => {
333
+ resolveSemaphore = resolve;
334
+ });
335
+ }
336
+ }
337
+ function send(msearchBody, callbacks) {
338
+ /* istanbul ignore if */
339
+ if (running > concurrency) {
340
+ throw new Error('Max concurrency reached');
341
+ }
342
+ msearchOperation(msearchBody, callbacks, () => {
343
+ running -= 1;
344
+ if (resolveSemaphore !== null) {
345
+ running += 1;
346
+ resolveSemaphore(send);
347
+ resolveSemaphore = null;
348
+ }
349
+ else if (resolveFinish != null && running === 0) {
350
+ resolveFinish();
351
+ }
352
+ });
353
+ }
354
+ }
355
+ function msearchOperation(msearchBody, callbacks, done) {
356
+ let retryCount = retries;
357
+ // Instead of going full on async-await, which would make the code easier to read,
358
+ // we have decided to use callback style instead.
359
+ // This because every time we use async await, V8 will create multiple promises
360
+ // behind the scenes, making the code slightly slower.
361
+ tryMsearch(msearchBody, callbacks, retrySearch);
362
+ function retrySearch(msearchBody, callbacks) {
363
+ if (msearchBody.length > 0 && retryCount > 0) {
364
+ retryCount -= 1;
365
+ setTimeout(tryMsearch, wait, msearchBody, callbacks, retrySearch);
366
+ return;
367
+ }
368
+ done();
369
+ }
370
+ // This function never returns an error, if the msearch operation fails,
371
+ // the error is dispatched to all search executors.
372
+ function tryMsearch(msearchBody, callbacks, done) {
373
+ client.msearch(Object.assign({}, msearchOptions, { body: msearchBody }), reqOptions)
374
+ .then(results => {
375
+ const retryBody = [];
376
+ const retryCallbacks = [];
377
+ const { responses } = results.body;
378
+ for (let i = 0, len = responses.length; i < len; i++) {
379
+ const response = responses[i];
380
+ if (response.status === 429 && retryCount > 0) {
381
+ retryBody.push(msearchBody[i * 2]);
382
+ retryBody.push(msearchBody[(i * 2) + 1]);
383
+ retryCallbacks.push(callbacks[i]);
384
+ continue;
385
+ }
386
+ const result = { ...results, body: response };
387
+ // @ts-expect-error
388
+ addDocumentsGetter(result);
389
+ if (response.status != null && response.status >= 400) {
390
+ callbacks[i](new ResponseError(result), result);
391
+ }
392
+ else {
393
+ callbacks[i](null, result);
394
+ }
395
+ }
396
+ done(retryBody, retryCallbacks);
397
+ })
398
+ .catch(err => {
399
+ for (const callback of callbacks) {
400
+ callback(err, null);
401
+ }
402
+ return done([], []);
403
+ });
404
+ }
405
+ }
406
+ }
407
+ /**
408
+ * Creates a bulk helper instance. Once you configure it, you can pick which operation
409
+ * to execute with the given dataset, index, create, update, and delete.
410
+ * @param {object} options - The configuration of the bulk operation.
411
+ * @param {object} reqOptions - The client optional configuration for this request.
412
+ * @return {object} The possible operations to run with the datasource.
413
+ */
414
+ bulk(options, reqOptions = {}) {
415
+ var _d;
416
+ const client = this[kClient];
417
+ const { serializer } = client;
418
+ if (this[kMetaHeader] !== null) {
419
+ reqOptions.headers = (_d = reqOptions.headers) !== null && _d !== void 0 ? _d : {};
420
+ reqOptions.headers['x-elastic-client-meta'] = `${this[kMetaHeader]},h=bp`;
421
+ }
422
+ reqOptions.meta = true;
423
+ const { datasource, onDocument, flushBytes = 5000000, flushInterval = 30000, concurrency = 5, retries = this[kMaxRetries], wait = 5000, onDrop = noop, refreshOnCompletion = false, ...bulkOptions } = options;
424
+ if (datasource === undefined) {
425
+ // @ts-expect-error
426
+ return Promise.reject(new ConfigurationError('bulk helper: the datasource is required'));
427
+ }
428
+ if (!(Array.isArray(datasource) || Buffer.isBuffer(datasource) || isReadableStream(datasource) || isAsyncIterator(datasource))) {
429
+ // @ts-expect-error
430
+ return Promise.reject(new ConfigurationError('bulk helper: the datasource must be an array or a buffer or a readable stream or an async generator'));
431
+ }
432
+ if (onDocument === undefined) {
433
+ // @ts-expect-error
434
+ return Promise.reject(new ConfigurationError('bulk helper: the onDocument callback is required'));
435
+ }
436
+ let shouldAbort = false;
437
+ let timeoutRef = null;
438
+ const stats = {
439
+ total: 0,
440
+ failed: 0,
441
+ retry: 0,
442
+ successful: 0,
443
+ noop: 0,
444
+ time: 0,
445
+ bytes: 0,
446
+ aborted: false
447
+ };
448
+ const p = iterate();
449
+ const helper = {
450
+ [Symbol.toStringTag]: 'Promise',
451
+ then(onFulfilled, onRejected) {
452
+ return p.then(onFulfilled, onRejected);
453
+ },
454
+ catch(onRejected) {
455
+ return p.catch(onRejected);
456
+ },
457
+ finally(onFinally) {
458
+ return p.finally(onFinally);
459
+ },
460
+ get stats() {
461
+ return stats;
462
+ },
463
+ abort() {
464
+ clearTimeout(timeoutRef);
465
+ shouldAbort = true;
466
+ stats.aborted = true;
467
+ return this;
468
+ }
469
+ };
470
+ return helper;
471
+ /**
472
+ * Function that iterates over the given datasource and start a bulk operation as soon
473
+ * as it reaches the configured bulk size. It's designed to use the Node.js asynchronous
474
+ * model at this maximum capacity, as it will collect the next body to send while there is
475
+ * a running http call. In this way, the CPU time will be used carefully.
476
+ * The objects will be serialized right away, to approximate the byte length of the body.
477
+ * It creates an array of strings instead of a ndjson string because the bulkOperation
478
+ * will navigate the body for matching failed operations with the original document.
479
+ */
480
+ async function iterate() {
481
+ const { semaphore, finish } = buildSemaphore();
482
+ const startTime = Date.now();
483
+ const bulkBody = [];
484
+ let actionBody = '';
485
+ let payloadBody = '';
486
+ let chunkBytes = 0;
487
+ timeoutRef = setTimeout(onFlushTimeout, flushInterval); // eslint-disable-line
488
+ // @ts-expect-error datasoruce is an iterable
489
+ for await (const chunk of datasource) {
490
+ if (shouldAbort)
491
+ break;
492
+ timeoutRef.refresh();
493
+ const action = onDocument(chunk);
494
+ const operation = Array.isArray(action)
495
+ ? Object.keys(action[0])[0]
496
+ : Object.keys(action)[0];
497
+ if (operation === 'index' || operation === 'create') {
498
+ actionBody = serializer.serialize(action);
499
+ payloadBody = typeof chunk === 'string' ? chunk : serializer.serialize(chunk);
500
+ chunkBytes += Buffer.byteLength(actionBody) + Buffer.byteLength(payloadBody);
501
+ bulkBody.push(actionBody, payloadBody);
502
+ }
503
+ else if (operation === 'update') {
504
+ // @ts-expect-error in case of update action is an array
505
+ actionBody = serializer.serialize(action[0]);
506
+ payloadBody = typeof chunk === 'string'
507
+ ? `{"doc":${chunk}}`
508
+ // @ts-expect-error in case of update action is an array
509
+ : serializer.serialize({ doc: chunk, ...action[1] });
510
+ chunkBytes += Buffer.byteLength(actionBody) + Buffer.byteLength(payloadBody);
511
+ bulkBody.push(actionBody, payloadBody);
512
+ }
513
+ else if (operation === 'delete') {
514
+ actionBody = serializer.serialize(action);
515
+ chunkBytes += Buffer.byteLength(actionBody);
516
+ bulkBody.push(actionBody);
517
+ }
518
+ else {
519
+ clearTimeout(timeoutRef);
520
+ throw new ConfigurationError(`Bulk helper invalid action: '${operation}'`);
521
+ }
522
+ if (chunkBytes >= flushBytes) {
523
+ stats.bytes += chunkBytes;
524
+ const send = await semaphore();
525
+ send(bulkBody.slice());
526
+ bulkBody.length = 0;
527
+ chunkBytes = 0;
528
+ }
529
+ }
530
+ clearTimeout(timeoutRef);
531
+ // In some cases the previos http call does not have finished,
532
+ // or we didn't reach the flush bytes threshold, so we force one last operation.
533
+ if (!shouldAbort && chunkBytes > 0) {
534
+ const send = await semaphore();
535
+ stats.bytes += chunkBytes;
536
+ send(bulkBody);
537
+ }
538
+ await finish();
539
+ if (refreshOnCompletion !== false) {
540
+ await client.indices.refresh({
541
+ index: typeof refreshOnCompletion === 'string'
542
+ ? refreshOnCompletion
543
+ : '_all'
544
+ }, reqOptions);
545
+ }
546
+ stats.time = Date.now() - startTime;
547
+ stats.total = stats.successful + stats.failed;
548
+ return stats;
549
+ async function onFlushTimeout() {
550
+ if (chunkBytes === 0)
551
+ return;
552
+ stats.bytes += chunkBytes;
553
+ const bulkBodyCopy = bulkBody.slice();
554
+ bulkBody.length = 0;
555
+ chunkBytes = 0;
556
+ try {
557
+ const send = await semaphore();
558
+ send(bulkBodyCopy);
559
+ }
560
+ catch (err) {
561
+ /* istanbul ignore next */
562
+ helper.abort(); // eslint-disable-line
563
+ }
564
+ }
565
+ }
566
+ // This function builds a semaphore using the concurrency
567
+ // options of the bulk helper. It is used inside the iterator
568
+ // to guarantee that no more than the number of operations
569
+ // allowed to run at the same time are executed.
570
+ // It returns a semaphore function which resolves in the next tick
571
+ // if we didn't reach the maximim concurrency yet, otherwise it returns
572
+ // a promise that resolves as soon as one of the running request has finshed.
573
+ // The semaphore function resolves a send function, which will be used
574
+ // to send the actual bulk request.
575
+ // It also returns a finish function, which returns a promise that is resolved
576
+ // when there are no longer request running. It rejects an error if one
577
+ // of the request has failed for some reason.
578
+ function buildSemaphore() {
579
+ let resolveSemaphore = null;
580
+ let resolveFinish = null;
581
+ let rejectFinish = null;
582
+ let error = null;
583
+ let running = 0;
584
+ return { semaphore, finish };
585
+ function finish() {
586
+ return new Promise((resolve, reject) => {
587
+ if (running === 0) {
588
+ if (error !== null) {
589
+ reject(error);
590
+ }
591
+ else {
592
+ resolve();
593
+ }
594
+ }
595
+ else {
596
+ resolveFinish = resolve;
597
+ rejectFinish = reject;
598
+ }
599
+ });
600
+ }
601
+ function semaphore() {
602
+ if (running < concurrency) {
603
+ running += 1;
604
+ return pImmediate(send);
605
+ }
606
+ else {
607
+ return new Promise((resolve, reject) => {
608
+ resolveSemaphore = resolve;
609
+ });
610
+ }
611
+ }
612
+ function send(bulkBody) {
613
+ /* istanbul ignore if */
614
+ if (running > concurrency) {
615
+ throw new Error('Max concurrency reached');
616
+ }
617
+ bulkOperation(bulkBody, err => {
618
+ running -= 1;
619
+ if (err != null) {
620
+ shouldAbort = true;
621
+ error = err;
622
+ }
623
+ if (resolveSemaphore !== null) {
624
+ running += 1;
625
+ resolveSemaphore(send);
626
+ resolveSemaphore = null;
627
+ }
628
+ else if (resolveFinish != null && rejectFinish != null && running === 0) {
629
+ if (error != null) {
630
+ rejectFinish(error);
631
+ }
632
+ else {
633
+ resolveFinish();
634
+ }
635
+ }
636
+ });
637
+ }
638
+ }
639
+ function bulkOperation(bulkBody, callback) {
640
+ let retryCount = retries;
641
+ let isRetrying = false;
642
+ // Instead of going full on async-await, which would make the code easier to read,
643
+ // we have decided to use callback style instead.
644
+ // This because every time we use async await, V8 will create multiple promises
645
+ // behind the scenes, making the code slightly slower.
646
+ tryBulk(bulkBody, retryDocuments);
647
+ function retryDocuments(err, bulkBody) {
648
+ if (err != null)
649
+ return callback(err);
650
+ if (shouldAbort)
651
+ return callback();
652
+ if (bulkBody.length > 0) {
653
+ if (retryCount > 0) {
654
+ isRetrying = true;
655
+ retryCount -= 1;
656
+ stats.retry += bulkBody.length;
657
+ setTimeout(tryBulk, wait, bulkBody, retryDocuments);
658
+ return;
659
+ }
660
+ for (let i = 0, len = bulkBody.length; i < len; i = i + 2) {
661
+ const operation = Object.keys(serializer.deserialize(bulkBody[i]))[0];
662
+ onDrop({
663
+ status: 429,
664
+ error: null,
665
+ operation: serializer.deserialize(bulkBody[i]),
666
+ document: operation !== 'delete'
667
+ ? serializer.deserialize(bulkBody[i + 1])
668
+ /* istanbul ignore next */
669
+ : null,
670
+ retried: isRetrying
671
+ });
672
+ stats.failed += 1;
673
+ }
674
+ }
675
+ callback();
676
+ }
677
+ function tryBulk(bulkBody, callback) {
678
+ if (shouldAbort)
679
+ return callback(null, []);
680
+ client.bulk(Object.assign({}, bulkOptions, { body: bulkBody }), reqOptions)
681
+ .then(response => {
682
+ var _d, _e;
683
+ const result = response.body;
684
+ if (!result.errors) {
685
+ stats.successful += result.items.length;
686
+ for (const item of result.items) {
687
+ if (((_d = item.update) === null || _d === void 0 ? void 0 : _d.result) === 'noop') {
688
+ stats.noop++;
689
+ }
690
+ }
691
+ return callback(null, []);
692
+ }
693
+ const retry = [];
694
+ const { items } = result;
695
+ for (let i = 0, len = items.length; i < len; i++) {
696
+ const action = items[i];
697
+ const operation = Object.keys(action)[0];
698
+ // @ts-expect-error
699
+ const responseItem = action[operation];
700
+ (0, assert_1.default)(responseItem !== undefined, 'The responseItem is undefined, please file a bug report');
701
+ const indexSlice = operation !== 'delete' ? i * 2 : i;
702
+ if (responseItem.status >= 400) {
703
+ // 429 is the only staus code where we might want to retry
704
+ // a document, because it was not an error in the document itself,
705
+ // but the ES node were handling too many operations.
706
+ if (responseItem.status === 429) {
707
+ retry.push(bulkBody[indexSlice]);
708
+ /* istanbul ignore next */
709
+ if (operation !== 'delete') {
710
+ retry.push(bulkBody[indexSlice + 1]);
711
+ }
712
+ }
713
+ else {
714
+ onDrop({
715
+ status: responseItem.status,
716
+ error: (_e = responseItem.error) !== null && _e !== void 0 ? _e : null,
717
+ operation: serializer.deserialize(bulkBody[indexSlice]),
718
+ document: operation !== 'delete'
719
+ ? serializer.deserialize(bulkBody[indexSlice + 1])
720
+ : null,
721
+ retried: isRetrying
722
+ });
723
+ stats.failed += 1;
724
+ }
725
+ }
726
+ else {
727
+ stats.successful += 1;
728
+ }
729
+ }
730
+ callback(null, retry);
731
+ })
732
+ .catch(err => {
733
+ callback(err, []);
734
+ });
735
+ }
736
+ }
737
+ }
738
+ }
739
+ exports.default = Helpers;
740
+ _a = kClient, _b = kMetaHeader, _c = kMaxRetries;
741
+ // Using a getter will improve the overall performances of the code,
742
+ // as we will reed the documents only if needed.
743
+ function addDocumentsGetter(result) {
744
+ Object.defineProperty(result, 'documents', {
745
+ get() {
746
+ var _d;
747
+ if (((_d = this.body.hits) === null || _d === void 0 ? void 0 : _d.hits) != null) {
748
+ // @ts-expect-error
749
+ return this.body.hits.hits.map(d => d._source);
750
+ }
751
+ return [];
752
+ }
753
+ });
754
+ }
755
+ function appendFilterPath(filter, params, force) {
756
+ if (params.filter_path !== undefined) {
757
+ params.filter_path += ',' + filter; // eslint-disable-line
758
+ }
759
+ else if (force) {
760
+ params.filter_path = filter;
761
+ }
762
+ }
763
+ function isReadableStream(obj) {
764
+ return obj != null && typeof obj.pipe === 'function';
765
+ }
766
+ function isAsyncIterator(obj) {
767
+ return (obj === null || obj === void 0 ? void 0 : obj[Symbol.asyncIterator]) != null;
768
+ }
769
+ //# sourceMappingURL=helpers.js.map