|
| 1 | +/* |
| 2 | + * Licensed to Elasticsearch B.V. under one or more contributor |
| 3 | + * license agreements. See the NOTICE file distributed with |
| 4 | + * this work for additional information regarding copyright |
| 5 | + * ownership. Elasticsearch B.V. licenses this file to you under |
| 6 | + * the Apache License, Version 2.0 (the "License"); you may |
| 7 | + * not use this file except in compliance with the License. |
| 8 | + * You may obtain a copy of the License at |
| 9 | + * |
| 10 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 11 | + * |
| 12 | + * Unless required by applicable law or agreed to in writing, |
| 13 | + * software distributed under the License is distributed on an |
| 14 | + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY |
| 15 | + * KIND, either express or implied. See the License for the |
| 16 | + * specific language governing permissions and limitations |
| 17 | + * under the License. |
| 18 | + */ |
| 19 | + |
| 20 | +'use strict' |
| 21 | + |
| 22 | +/* eslint camelcase: 0 */ |
| 23 | +/* eslint no-unused-vars: 0 */ |
| 24 | + |
| 25 | +const { handleError, snakeCaseKeys, normalizeArguments, kConfigurationError } = require('../utils') |
| 26 | +const acceptedQuerystring = ['pretty', 'human', 'error_trace', 'source', 'filter_path', 'wait_for_completion_timeout', 'keep_alive', 'typed_keys', 'keep_on_completion', 'batched_reduce_size', 'request_cache', 'analyzer', 'analyze_wildcard', 'default_operator', 'df', 'explain', 'stored_fields', 'docvalue_fields', 'from', 'ignore_unavailable', 'ignore_throttled', 'allow_no_indices', 'expand_wildcards', 'lenient', 'preference', 'q', 'routing', 'search_type', 'size', 'sort', '_source', '_source_excludes', '_source_exclude', '_source_includes', '_source_include', 'terminate_after', 'stats', 'suggest_field', 'suggest_mode', 'suggest_size', 'suggest_text', 'timeout', 'track_scores', 'track_total_hits', 'allow_partial_search_results', 'version', 'seq_no_primary_term', 'max_concurrent_shard_requests'] |
| 27 | +const snakeCase = { errorTrace: 'error_trace', filterPath: 'filter_path', waitForCompletionTimeout: 'wait_for_completion_timeout', keepAlive: 'keep_alive', typedKeys: 'typed_keys', keepOnCompletion: 'keep_on_completion', batchedReduceSize: 'batched_reduce_size', requestCache: 'request_cache', analyzeWildcard: 'analyze_wildcard', defaultOperator: 'default_operator', storedFields: 'stored_fields', docvalueFields: 'docvalue_fields', ignoreUnavailable: 'ignore_unavailable', ignoreThrottled: 'ignore_throttled', allowNoIndices: 'allow_no_indices', expandWildcards: 'expand_wildcards', searchType: 'search_type', _sourceExcludes: '_source_excludes', _sourceExclude: '_source_exclude', _sourceIncludes: '_source_includes', _sourceInclude: '_source_include', terminateAfter: 'terminate_after', suggestField: 'suggest_field', suggestMode: 'suggest_mode', suggestSize: 'suggest_size', suggestText: 'suggest_text', trackScores: 'track_scores', trackTotalHits: 'track_total_hits', allowPartialSearchResults: 'allow_partial_search_results', seqNoPrimaryTerm: 'seq_no_primary_term', maxConcurrentShardRequests: 'max_concurrent_shard_requests' } |
| 28 | + |
| 29 | +function AsyncSearchApi (transport, ConfigurationError) { |
| 30 | + this.transport = transport |
| 31 | + this[kConfigurationError] = ConfigurationError |
| 32 | +} |
| 33 | + |
| 34 | +AsyncSearchApi.prototype.delete = function asyncSearchDeleteApi (params, options, callback) { |
| 35 | + ;[params, options, callback] = normalizeArguments(params, options, callback) |
| 36 | + |
| 37 | + // check required parameters |
| 38 | + if (params['id'] == null) { |
| 39 | + const err = new this[kConfigurationError]('Missing required parameter: id') |
| 40 | + return handleError(err, callback) |
| 41 | + } |
| 42 | + |
| 43 | + var { method, body, id, ...querystring } = params |
| 44 | + querystring = snakeCaseKeys(acceptedQuerystring, snakeCase, querystring) |
| 45 | + |
| 46 | + var path = '' |
| 47 | + if (method == null) method = 'DELETE' |
| 48 | + path = '/' + '_async_search' + '/' + encodeURIComponent(id) |
| 49 | + |
| 50 | + // build request object |
| 51 | + const request = { |
| 52 | + method, |
| 53 | + path, |
| 54 | + body: body || '', |
| 55 | + querystring |
| 56 | + } |
| 57 | + |
| 58 | + return this.transport.request(request, options, callback) |
| 59 | +} |
| 60 | + |
| 61 | +AsyncSearchApi.prototype.get = function asyncSearchGetApi (params, options, callback) { |
| 62 | + ;[params, options, callback] = normalizeArguments(params, options, callback) |
| 63 | + |
| 64 | + // check required parameters |
| 65 | + if (params['id'] == null) { |
| 66 | + const err = new this[kConfigurationError]('Missing required parameter: id') |
| 67 | + return handleError(err, callback) |
| 68 | + } |
| 69 | + |
| 70 | + var { method, body, id, ...querystring } = params |
| 71 | + querystring = snakeCaseKeys(acceptedQuerystring, snakeCase, querystring) |
| 72 | + |
| 73 | + var path = '' |
| 74 | + if (method == null) method = 'GET' |
| 75 | + path = '/' + '_async_search' + '/' + encodeURIComponent(id) |
| 76 | + |
| 77 | + // build request object |
| 78 | + const request = { |
| 79 | + method, |
| 80 | + path, |
| 81 | + body: null, |
| 82 | + querystring |
| 83 | + } |
| 84 | + |
| 85 | + return this.transport.request(request, options, callback) |
| 86 | +} |
| 87 | + |
| 88 | +AsyncSearchApi.prototype.submit = function asyncSearchSubmitApi (params, options, callback) { |
| 89 | + ;[params, options, callback] = normalizeArguments(params, options, callback) |
| 90 | + |
| 91 | + var { method, body, index, ...querystring } = params |
| 92 | + querystring = snakeCaseKeys(acceptedQuerystring, snakeCase, querystring) |
| 93 | + |
| 94 | + var path = '' |
| 95 | + if ((index) != null) { |
| 96 | + if (method == null) method = 'POST' |
| 97 | + path = '/' + encodeURIComponent(index) + '/' + '_async_search' |
| 98 | + } else { |
| 99 | + if (method == null) method = 'POST' |
| 100 | + path = '/' + '_async_search' |
| 101 | + } |
| 102 | + |
| 103 | + // build request object |
| 104 | + const request = { |
| 105 | + method, |
| 106 | + path, |
| 107 | + body: body || '', |
| 108 | + querystring |
| 109 | + } |
| 110 | + |
| 111 | + return this.transport.request(request, options, callback) |
| 112 | +} |
| 113 | + |
| 114 | +module.exports = AsyncSearchApi |
0 commit comments