Source: api/api/field_caps.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. 'fields',
  34. 'ignore_unavailable',
  35. 'allow_no_indices',
  36. 'expand_wildcards',
  37. 'include_unmapped',
  38. 'pretty',
  39. 'human',
  40. 'error_trace',
  41. 'source',
  42. 'filter_path',
  43. ];
  44. const snakeCase = {
  45. ignoreUnavailable: 'ignore_unavailable',
  46. allowNoIndices: 'allow_no_indices',
  47. expandWildcards: 'expand_wildcards',
  48. includeUnmapped: 'include_unmapped',
  49. errorTrace: 'error_trace',
  50. filterPath: 'filter_path',
  51. };
  52. /**
  53. * Returns the information about the capabilities of fields among multiple indices.
  54. * <br/> See also: {@link https://opensearch.org/docs/latest/opensearch/supported-field-types/alias/#using-aliases-in-field-capabilities-api-operations OpenSearch - Alias}
  55. * @memberOf API-Index
  56. *
  57. * @param {Object} params
  58. * @param {string} [params.index] - A comma-separated list of index names; use `_all` or empty string to perform the operation on all indices
  59. * @param {string} [params.fields] - A comma-separated list of field names
  60. * @param {boolean} [params.ignore_unavailable] - Whether specified concrete indices should be ignored when unavailable (missing or closed)
  61. * @param {boolean} [params.allow_no_indices] - Whether to ignore if a wildcard indices expression resolves into no concrete indices. (This includes `_all` string or when no indices have been specified)
  62. * @param {string} [params.expand_wildcards] - Whether to expand wildcard expression to concrete indices that are open, closed or both. (options: open, closed, hidden, none, all)
  63. * @param {boolean} [params.include_unmapped] - Indicates whether unmapped fields should be included in the response.
  64. * @param {Object} [params.body] - An index filter specified with the Query DSL
  65. *
  66. * @param {Object} [options] - Options for {@link Transport#request}
  67. * @param {function} [callback] - Callback that handles errors and response
  68. *
  69. * @returns {{abort: function(), then: function(), catch: function()}|Promise<never>|*}
  70. */
  71. function fieldCapsApi(params, options, callback) {
  72. [params, options, callback] = normalizeArguments(params, options, callback);
  73. let { method, body, index, ...querystring } = params;
  74. querystring = snakeCaseKeys(acceptedQuerystring, snakeCase, querystring);
  75. let path = '';
  76. if (index != null) {
  77. if (method == null) method = body == null ? 'GET' : 'POST';
  78. path = '/' + encodeURIComponent(index) + '/' + '_field_caps';
  79. } else {
  80. if (method == null) method = body == null ? 'GET' : 'POST';
  81. path = '/' + '_field_caps';
  82. }
  83. // build request object
  84. const request = {
  85. method,
  86. path,
  87. body: body || '',
  88. querystring,
  89. };
  90. return this.transport.request(request, options, callback);
  91. }
  92. module.exports = fieldCapsApi;