Source: api/api/clear_scroll.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 = ['pretty', 'human', 'error_trace', 'source', 'filter_path'];
  33. const snakeCase = { errorTrace: 'error_trace', filterPath: 'filter_path' };
  34. /**
  35. * Close the search context when you’re done scrolling, because the scroll operation continues to consume computing resources until the timeout.
  36. * <br/> See Also: {@link https://opensearch.org/docs/latest/api-reference/scroll/ OpenSearch - Scroll }
  37. *
  38. * @memberOf API-Search
  39. *
  40. * @param {Object} params
  41. * @param {string} [params.scroll_id] The ID of the scroll to be terminated. Use `_all` to close all open scroll contexts.
  42. *
  43. * @param {Object} [options] - Options for {@link Transport#request}
  44. * @param {function} [callback] - Callback that handles errors and response
  45. *
  46. * @returns {{abort: function(), then: function(), catch: function()}|Promise<never>|*}
  47. */
  48. function clearScrollApi(params, options, callback) {
  49. [params, options, callback] = normalizeArguments(params, options, callback);
  50. let { method, body, scrollId, scroll_id, ...querystring } = params;
  51. querystring = snakeCaseKeys(acceptedQuerystring, snakeCase, querystring);
  52. let path = '';
  53. if ((scroll_id || scrollId) != null) {
  54. if (method == null) method = 'DELETE';
  55. path = '/' + '_search' + '/' + 'scroll' + '/' + encodeURIComponent(scroll_id || scrollId);
  56. } else {
  57. if (method == null) method = 'DELETE';
  58. path = '/' + '_search' + '/' + 'scroll';
  59. }
  60. // build request object
  61. const request = {
  62. method,
  63. path,
  64. body: body || '',
  65. querystring,
  66. };
  67. return this.transport.request(request, options, callback);
  68. }
  69. module.exports = clearScrollApi;