Source: api/api/create_pit.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. 'use strict';
  11. /* eslint camelcase: 0 */
  12. /* eslint no-unused-vars: 0 */
  13. /** @namespace API-PIT */
  14. const { handleError, snakeCaseKeys, normalizeArguments, kConfigurationError } = require('../utils');
  15. const acceptedQuerystring = [
  16. 'allow_partial_pit_creation',
  17. 'keep_alive',
  18. 'preference',
  19. 'routing',
  20. 'pretty',
  21. 'human',
  22. 'error_trace',
  23. 'source',
  24. 'filter_path',
  25. ];
  26. const snakeCase = {
  27. allowPartialPitCreation: 'allow_partial_pit_creation',
  28. keepAlive: 'keep_alive',
  29. errorTrace: 'error_trace',
  30. filterPath: 'filter_path',
  31. };
  32. /**
  33. * Creates a point in time.
  34. * <br/> See Also: {@link https://opensearch.org/docs/latest/opensearch/point-in-time-api#create-a-pit|Opensearch - Create a PIT}
  35. * @memberOf API-PIT
  36. *
  37. * @param {Object} params
  38. * @param {string} params.index - The name(s) of the target index(es) for the PIT. May contain a comma-separated list or a wildcard index pattern.
  39. * @param {string} params.keep_alive - The amount of time to keep the PIT
  40. * @param {string} [params.preference=random] - The node or the shard used to perform the search.
  41. * @param {string} [params.routing] - Specifies to route search requests to a specific shard.
  42. * @param {string} [params.expand_wildcards=open] - The type of index that can match the wildcard pattern. Supports comma-separated values.
  43. * @param {string} [params.allow_partial_pit_creation=false] - Specifies whether to create a PIT with partial failures.
  44. *
  45. * @param {Object} [options] - Options for {@link Transport#request}
  46. * @param {function} [callback] - Callback that handles errors and response
  47. *
  48. * @returns {{abort: function(), then: function(), catch: function()}|Promise<never>|*} {@link https://opensearch.org/docs/latest/opensearch/point-in-time-api#sample-response|Create PIT Response}
  49. */
  50. function createPitApi(params, options, callback) {
  51. [params, options, callback] = normalizeArguments(params, options, callback);
  52. // check required parameters
  53. if (params['index'] == null) {
  54. const err = new this[kConfigurationError]('Missing required parameter: index');
  55. return handleError(err, callback);
  56. }
  57. if (params['keep_alive'] == null) {
  58. const err = new this[kConfigurationError]('Missing required parameter: keep_alive');
  59. return handleError(err, callback);
  60. }
  61. let { method, body, index, ...querystring } = params;
  62. querystring = snakeCaseKeys(acceptedQuerystring, snakeCase, querystring);
  63. let path = '';
  64. if (method == null) method = 'POST';
  65. path = '/' + encodeURIComponent(index) + '/' + '_search' + '/' + 'point_in_time';
  66. // build request object
  67. const request = {
  68. method,
  69. path,
  70. body: body || '',
  71. querystring,
  72. };
  73. return this.transport.request(request, options, callback);
  74. }
  75. module.exports = createPitApi;