Source: api/api/delete_by_query_rethrottle.js

  1. /*
  2. * Copyright OpenSearch Contributors
  3. * SPDX-License-Identifier: Apache-2.0
  4. *
  5. * The OpenSearch Contributors require contributions made to
  6. * this file be licensed under the Apache-2.0 license or a
  7. * compatible open source license.
  8. *
  9. */
  10. /*
  11. * Licensed to Elasticsearch B.V. under one or more contributor
  12. * license agreements. See the NOTICE file distributed with
  13. * this work for additional information regarding copyright
  14. * ownership. Elasticsearch B.V. licenses this file to you under
  15. * the Apache License, Version 2.0 (the "License"); you may
  16. * not use this file except in compliance with the License.
  17. * You may obtain a copy of the License at
  18. *
  19. * http://www.apache.org/licenses/LICENSE-2.0
  20. *
  21. * Unless required by applicable law or agreed to in writing,
  22. * software distributed under the License is distributed on an
  23. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  24. * KIND, either express or implied. See the License for the
  25. * specific language governing permissions and limitations
  26. * under the License.
  27. */
  28. 'use strict';
  29. /* eslint camelcase: 0 */
  30. /* eslint no-unused-vars: 0 */
  31. const { handleError, snakeCaseKeys, normalizeArguments, kConfigurationError } = require('../utils');
  32. const acceptedQuerystring = [
  33. 'requests_per_second',
  34. 'pretty',
  35. 'human',
  36. 'error_trace',
  37. 'source',
  38. 'filter_path',
  39. ];
  40. const snakeCase = {
  41. requestsPerSecond: 'requests_per_second',
  42. errorTrace: 'error_trace',
  43. filterPath: 'filter_path',
  44. };
  45. /**
  46. * Changes the number of requests per second for a particular Delete By Query operation.
  47. *
  48. * @memberOf API-Document
  49. *
  50. * @param {Object} params
  51. * @param {string} params.task_id - The task id to rethrottle
  52. * @param {number} params.requests_per_second - The throttle to set on this request in floating sub-requests per second. -1 means set no throttle.
  53. *
  54. * @param {Object} options - Options for {@link Transport#request}
  55. * @param {function} callback - Callback that handles errors and response
  56. *
  57. * @returns {{abort: function(), then: function(), catch: function()}|Promise<never>|*}
  58. */
  59. function deleteByQueryRethrottleApi(params, options, callback) {
  60. [params, options, callback] = normalizeArguments(params, options, callback);
  61. // check required parameters
  62. if (params.task_id == null && params.taskId == null) {
  63. const err = new this[kConfigurationError]('Missing required parameter: task_id or taskId');
  64. return handleError(err, callback);
  65. }
  66. if (params.requests_per_second == null && params.requestsPerSecond == null) {
  67. const err = new this[kConfigurationError](
  68. 'Missing required parameter: requests_per_second or requestsPerSecond'
  69. );
  70. return handleError(err, callback);
  71. }
  72. let { method, body, taskId, task_id, ...querystring } = params;
  73. querystring = snakeCaseKeys(acceptedQuerystring, snakeCase, querystring);
  74. let path = '';
  75. if (method == null) method = 'POST';
  76. path =
  77. '/' + '_delete_by_query' + '/' + encodeURIComponent(task_id || taskId) + '/' + '_rethrottle';
  78. // build request object
  79. const request = {
  80. method,
  81. path,
  82. body: body || '',
  83. querystring,
  84. };
  85. return this.transport.request(request, options, callback);
  86. }
  87. module.exports = deleteByQueryRethrottleApi;