diff --git a/docs/reference.asciidoc b/docs/reference.asciidoc index fbcf6c39f..516f02386 100644 --- a/docs/reference.asciidoc +++ b/docs/reference.asciidoc @@ -7152,7 +7152,7 @@ client.indices.putMapping({ index }) ** *`dynamic_date_formats` (Optional, string[])*: If date detection is enabled then new string fields are checked against 'dynamic_date_formats' and if the value matches then a new date field is added instead of string. -** *`dynamic_templates` (Optional, Record<string, { mapping, runtime, match, path_match, unmatch, path_unmatch, match_mapping_type, unmatch_mapping_type, match_pattern }> | Record<string, { mapping, runtime, match, path_match, unmatch, path_unmatch, match_mapping_type, unmatch_mapping_type, match_pattern }>[])*: Specify dynamic templates for the mapping. +** *`dynamic_templates` (Optional, Record<string, { mapping, runtime, match, path_match, unmatch, path_unmatch, match_mapping_type, unmatch_mapping_type, match_pattern }>[])*: Specify dynamic templates for the mapping. ** *`_field_names` (Optional, { enabled })*: Control whether field names are enabled for the index. ** *`_meta` (Optional, Record<string, User-defined value>)*: A mapping type can have custom meta data associated with it. These are not used at all by Elasticsearch, but can be used to store diff --git a/src/api/api/async_search.ts b/src/api/api/async_search.ts index b3dd631c1..9cc1582e1 100644 --- a/src/api/api/async_search.ts +++ b/src/api/api/async_search.ts @@ -35,12 +35,133 @@ import { TransportResult } from '@elastic/transport' import * as T from '../types' -interface That { transport: Transport } + +interface That { + transport: Transport + acceptedParams: Record<string, { path: string[], body: string[], query: string[] }> +} + +const commonQueryParams = ['error_trace', 'filter_path', 'human', 'pretty'] export default class AsyncSearch { transport: Transport + acceptedParams: Record<string, { path: string[], body: string[], query: string[] }> constructor (transport: Transport) { this.transport = transport + this.acceptedParams = { + 'async_search.delete': { + path: [ + 'id' + ], + body: [], + query: [] + }, + 'async_search.get': { + path: [ + 'id' + ], + body: [], + query: [ + 'keep_alive', + 'typed_keys', + 'wait_for_completion_timeout' + ] + }, + 'async_search.status': { + path: [ + 'id' + ], + body: [], + query: [ + 'keep_alive' + ] + }, + 'async_search.submit': { + path: [ + 'index' + ], + body: [ + 'aggregations', + 'aggs', + 'collapse', + 'explain', + 'ext', + 'from', + 'highlight', + 'track_total_hits', + 'indices_boost', + 'docvalue_fields', + 'knn', + 'min_score', + 'post_filter', + 'profile', + 'query', + 'rescore', + 'script_fields', + 'search_after', + 'size', + 'slice', + 'sort', + '_source', + 'fields', + 'suggest', + 'terminate_after', + 'timeout', + 'track_scores', + 'version', + 'seq_no_primary_term', + 'stored_fields', + 'pit', + 'runtime_mappings', + 'stats' + ], + query: [ + 'wait_for_completion_timeout', + 'keep_alive', + 'keep_on_completion', + 'allow_no_indices', + 'allow_partial_search_results', + 'analyzer', + 'analyze_wildcard', + 'batched_reduce_size', + 'ccs_minimize_roundtrips', + 'default_operator', + 'df', + 'docvalue_fields', + 'expand_wildcards', + 'explain', + 'ignore_throttled', + 'ignore_unavailable', + 'lenient', + 'max_concurrent_shard_requests', + 'preference', + 'request_cache', + 'routing', + 'search_type', + 'stats', + 'stored_fields', + 'suggest_field', + 'suggest_mode', + 'suggest_size', + 'suggest_text', + 'terminate_after', + 'timeout', + 'track_total_hits', + 'track_scores', + 'typed_keys', + 'rest_total_hits_as_int', + 'version', + '_source', + '_source_excludes', + '_source_includes', + 'seq_no_primary_term', + 'q', + 'size', + 'from', + 'sort' + ] + } + } } /** @@ -51,7 +172,10 @@ export default class AsyncSearch { async delete (this: That, params: T.AsyncSearchDeleteRequest, options?: TransportRequestOptionsWithMeta): Promise<TransportResult<T.AsyncSearchDeleteResponse, unknown>> async delete (this: That, params: T.AsyncSearchDeleteRequest, options?: TransportRequestOptions): Promise<T.AsyncSearchDeleteResponse> async delete (this: That, params: T.AsyncSearchDeleteRequest, options?: TransportRequestOptions): Promise<any> { - const acceptedPath: string[] = ['id'] + const { + path: acceptedPath + } = this.acceptedParams['async_search.delete'] + const userQuery = params?.querystring const querystring: Record<string, any> = userQuery != null ? { ...userQuery } : {} @@ -93,7 +217,10 @@ export default class AsyncSearch { async get<TDocument = unknown, TAggregations = Record<T.AggregateName, T.AggregationsAggregate>> (this: That, params: T.AsyncSearchGetRequest, options?: TransportRequestOptionsWithMeta): Promise<TransportResult<T.AsyncSearchGetResponse<TDocument, TAggregations>, unknown>> async get<TDocument = unknown, TAggregations = Record<T.AggregateName, T.AggregationsAggregate>> (this: That, params: T.AsyncSearchGetRequest, options?: TransportRequestOptions): Promise<T.AsyncSearchGetResponse<TDocument, TAggregations>> async get<TDocument = unknown, TAggregations = Record<T.AggregateName, T.AggregationsAggregate>> (this: That, params: T.AsyncSearchGetRequest, options?: TransportRequestOptions): Promise<any> { - const acceptedPath: string[] = ['id'] + const { + path: acceptedPath + } = this.acceptedParams['async_search.get'] + const userQuery = params?.querystring const querystring: Record<string, any> = userQuery != null ? { ...userQuery } : {} @@ -135,7 +262,10 @@ export default class AsyncSearch { async status (this: That, params: T.AsyncSearchStatusRequest, options?: TransportRequestOptionsWithMeta): Promise<TransportResult<T.AsyncSearchStatusResponse, unknown>> async status (this: That, params: T.AsyncSearchStatusRequest, options?: TransportRequestOptions): Promise<T.AsyncSearchStatusResponse> async status (this: That, params: T.AsyncSearchStatusRequest, options?: TransportRequestOptions): Promise<any> { - const acceptedPath: string[] = ['id'] + const { + path: acceptedPath + } = this.acceptedParams['async_search.status'] + const userQuery = params?.querystring const querystring: Record<string, any> = userQuery != null ? { ...userQuery } : {} @@ -177,8 +307,12 @@ export default class AsyncSearch { async submit<TDocument = unknown, TAggregations = Record<T.AggregateName, T.AggregationsAggregate>> (this: That, params?: T.AsyncSearchSubmitRequest, options?: TransportRequestOptionsWithMeta): Promise<TransportResult<T.AsyncSearchSubmitResponse<TDocument, TAggregations>, unknown>> async submit<TDocument = unknown, TAggregations = Record<T.AggregateName, T.AggregationsAggregate>> (this: That, params?: T.AsyncSearchSubmitRequest, options?: TransportRequestOptions): Promise<T.AsyncSearchSubmitResponse<TDocument, TAggregations>> async submit<TDocument = unknown, TAggregations = Record<T.AggregateName, T.AggregationsAggregate>> (this: That, params?: T.AsyncSearchSubmitRequest, options?: TransportRequestOptions): Promise<any> { - const acceptedPath: string[] = ['index'] - const acceptedBody: string[] = ['aggregations', 'aggs', 'collapse', 'explain', 'ext', 'from', 'highlight', 'track_total_hits', 'indices_boost', 'docvalue_fields', 'knn', 'min_score', 'post_filter', 'profile', 'query', 'rescore', 'script_fields', 'search_after', 'size', 'slice', 'sort', '_source', 'fields', 'suggest', 'terminate_after', 'timeout', 'track_scores', 'version', 'seq_no_primary_term', 'stored_fields', 'pit', 'runtime_mappings', 'stats'] + const { + path: acceptedPath, + body: acceptedBody, + query: acceptedQuery + } = this.acceptedParams['async_search.submit'] + const userQuery = params?.querystring const querystring: Record<string, any> = userQuery != null ? { ...userQuery } : {} @@ -205,8 +339,14 @@ export default class AsyncSearch { } else if (acceptedPath.includes(key)) { continue } else if (key !== 'body' && key !== 'querystring') { - // @ts-expect-error - querystring[key] = params[key] + if (acceptedQuery.includes(key) || commonQueryParams.includes(key)) { + // @ts-expect-error + querystring[key] = params[key] + } else { + body = body ?? {} + // @ts-expect-error + body[key] = params[key] + } } } diff --git a/src/api/api/autoscaling.ts b/src/api/api/autoscaling.ts index 7f123c5a2..e53887579 100644 --- a/src/api/api/autoscaling.ts +++ b/src/api/api/autoscaling.ts @@ -35,12 +35,59 @@ import { TransportResult } from '@elastic/transport' import * as T from '../types' -interface That { transport: Transport } + +interface That { + transport: Transport + acceptedParams: Record<string, { path: string[], body: string[], query: string[] }> +} + +const commonQueryParams = ['error_trace', 'filter_path', 'human', 'pretty'] export default class Autoscaling { transport: Transport + acceptedParams: Record<string, { path: string[], body: string[], query: string[] }> constructor (transport: Transport) { this.transport = transport + this.acceptedParams = { + 'autoscaling.delete_autoscaling_policy': { + path: [ + 'name' + ], + body: [], + query: [ + 'master_timeout', + 'timeout' + ] + }, + 'autoscaling.get_autoscaling_capacity': { + path: [], + body: [], + query: [ + 'master_timeout' + ] + }, + 'autoscaling.get_autoscaling_policy': { + path: [ + 'name' + ], + body: [], + query: [ + 'master_timeout' + ] + }, + 'autoscaling.put_autoscaling_policy': { + path: [ + 'name' + ], + body: [ + 'policy' + ], + query: [ + 'master_timeout', + 'timeout' + ] + } + } } /** @@ -51,7 +98,10 @@ export default class Autoscaling { async deleteAutoscalingPolicy (this: That, params: T.AutoscalingDeleteAutoscalingPolicyRequest, options?: TransportRequestOptionsWithMeta): Promise<TransportResult<T.AutoscalingDeleteAutoscalingPolicyResponse, unknown>> async deleteAutoscalingPolicy (this: That, params: T.AutoscalingDeleteAutoscalingPolicyRequest, options?: TransportRequestOptions): Promise<T.AutoscalingDeleteAutoscalingPolicyResponse> async deleteAutoscalingPolicy (this: That, params: T.AutoscalingDeleteAutoscalingPolicyRequest, options?: TransportRequestOptions): Promise<any> { - const acceptedPath: string[] = ['name'] + const { + path: acceptedPath + } = this.acceptedParams['autoscaling.delete_autoscaling_policy'] + const userQuery = params?.querystring const querystring: Record<string, any> = userQuery != null ? { ...userQuery } : {} @@ -93,7 +143,10 @@ export default class Autoscaling { async getAutoscalingCapacity (this: That, params?: T.AutoscalingGetAutoscalingCapacityRequest, options?: TransportRequestOptionsWithMeta): Promise<TransportResult<T.AutoscalingGetAutoscalingCapacityResponse, unknown>> async getAutoscalingCapacity (this: That, params?: T.AutoscalingGetAutoscalingCapacityRequest, options?: TransportRequestOptions): Promise<T.AutoscalingGetAutoscalingCapacityResponse> async getAutoscalingCapacity (this: That, params?: T.AutoscalingGetAutoscalingCapacityRequest, options?: TransportRequestOptions): Promise<any> { - const acceptedPath: string[] = [] + const { + path: acceptedPath + } = this.acceptedParams['autoscaling.get_autoscaling_capacity'] + const userQuery = params?.querystring const querystring: Record<string, any> = userQuery != null ? { ...userQuery } : {} @@ -133,7 +186,10 @@ export default class Autoscaling { async getAutoscalingPolicy (this: That, params: T.AutoscalingGetAutoscalingPolicyRequest, options?: TransportRequestOptionsWithMeta): Promise<TransportResult<T.AutoscalingGetAutoscalingPolicyResponse, unknown>> async getAutoscalingPolicy (this: That, params: T.AutoscalingGetAutoscalingPolicyRequest, options?: TransportRequestOptions): Promise<T.AutoscalingGetAutoscalingPolicyResponse> async getAutoscalingPolicy (this: That, params: T.AutoscalingGetAutoscalingPolicyRequest, options?: TransportRequestOptions): Promise<any> { - const acceptedPath: string[] = ['name'] + const { + path: acceptedPath + } = this.acceptedParams['autoscaling.get_autoscaling_policy'] + const userQuery = params?.querystring const querystring: Record<string, any> = userQuery != null ? { ...userQuery } : {} @@ -175,8 +231,12 @@ export default class Autoscaling { async putAutoscalingPolicy (this: That, params: T.AutoscalingPutAutoscalingPolicyRequest, options?: TransportRequestOptionsWithMeta): Promise<TransportResult<T.AutoscalingPutAutoscalingPolicyResponse, unknown>> async putAutoscalingPolicy (this: That, params: T.AutoscalingPutAutoscalingPolicyRequest, options?: TransportRequestOptions): Promise<T.AutoscalingPutAutoscalingPolicyResponse> async putAutoscalingPolicy (this: That, params: T.AutoscalingPutAutoscalingPolicyRequest, options?: TransportRequestOptions): Promise<any> { - const acceptedPath: string[] = ['name'] - const acceptedBody: string[] = ['policy'] + const { + path: acceptedPath, + body: acceptedBody, + query: acceptedQuery + } = this.acceptedParams['autoscaling.put_autoscaling_policy'] + const userQuery = params?.querystring const querystring: Record<string, any> = userQuery != null ? { ...userQuery } : {} @@ -188,8 +248,14 @@ export default class Autoscaling { } else if (acceptedPath.includes(key)) { continue } else if (key !== 'body' && key !== 'querystring') { - // @ts-expect-error - querystring[key] = params[key] + if (acceptedQuery.includes(key) || commonQueryParams.includes(key)) { + // @ts-expect-error + querystring[key] = params[key] + } else { + body = body ?? {} + // @ts-expect-error + body[key] = params[key] + } } } diff --git a/src/api/api/bulk.ts b/src/api/api/bulk.ts index ccdedfcb2..b7508e514 100644 --- a/src/api/api/bulk.ts +++ b/src/api/api/bulk.ts @@ -35,7 +35,37 @@ import { TransportResult } from '@elastic/transport' import * as T from '../types' -interface That { transport: Transport } + +interface That { + transport: Transport +} + +const commonQueryParams = ['error_trace', 'filter_path', 'human', 'pretty'] + +const acceptedParams: Record<string, { path: string[], body: string[], query: string[] }> = { + bulk: { + path: [ + 'index' + ], + body: [ + 'operations' + ], + query: [ + 'include_source_on_error', + 'list_executed_pipelines', + 'pipeline', + 'refresh', + 'routing', + '_source', + '_source_excludes', + '_source_includes', + 'timeout', + 'wait_for_active_shards', + 'require_alias', + 'require_data_stream' + ] + } +} /** * Bulk index or delete documents. Perform multiple `index`, `create`, `delete`, and `update` actions in a single request. This reduces overhead and can greatly increase indexing speed. If the Elasticsearch security features are enabled, you must have the following index privileges for the target data stream, index, or index alias: * To use the `create` action, you must have the `create_doc`, `create`, `index`, or `write` index privilege. Data streams support only the `create` action. * To use the `index` action, you must have the `create`, `index`, or `write` index privilege. * To use the `delete` action, you must have the `delete` or `write` index privilege. * To use the `update` action, you must have the `index` or `write` index privilege. * To automatically create a data stream or index with a bulk API request, you must have the `auto_configure`, `create_index`, or `manage` index privilege. * To make the result of a bulk operation visible to search using the `refresh` parameter, you must have the `maintenance` or `manage` index privilege. Automatic data stream creation requires a matching index template with data stream enabled. The actions are specified in the request body using a newline delimited JSON (NDJSON) structure: ``` action_and_meta_data\n optional_source\n action_and_meta_data\n optional_source\n .... action_and_meta_data\n optional_source\n ``` The `index` and `create` actions expect a source on the next line and have the same semantics as the `op_type` parameter in the standard index API. A `create` action fails if a document with the same ID already exists in the target An `index` action adds or replaces a document as necessary. NOTE: Data streams support only the `create` action. To update or delete a document in a data stream, you must target the backing index containing the document. An `update` action expects that the partial doc, upsert, and script and its options are specified on the next line. A `delete` action does not expect a source on the next line and has the same semantics as the standard delete API. NOTE: The final line of data must end with a newline character (`\n`). Each newline character may be preceded by a carriage return (`\r`). When sending NDJSON data to the `_bulk` endpoint, use a `Content-Type` header of `application/json` or `application/x-ndjson`. Because this format uses literal newline characters (`\n`) as delimiters, make sure that the JSON actions and sources are not pretty printed. If you provide a target in the request path, it is used for any actions that don't explicitly specify an `_index` argument. A note on the format: the idea here is to make processing as fast as possible. As some of the actions are redirected to other shards on other nodes, only `action_meta_data` is parsed on the receiving node side. Client libraries using this protocol should try and strive to do something similar on the client side, and reduce buffering as much as possible. There is no "correct" number of actions to perform in a single bulk request. Experiment with different settings to find the optimal size for your particular workload. Note that Elasticsearch limits the maximum size of a HTTP request to 100mb by default so clients must ensure that no request exceeds this size. It is not possible to index a single document that exceeds the size limit, so you must pre-process any such documents into smaller pieces before sending them to Elasticsearch. For instance, split documents into pages or chapters before indexing them, or store raw binary data in a system outside Elasticsearch and replace the raw data with a link to the external system in the documents that you send to Elasticsearch. **Client suppport for bulk requests** Some of the officially supported clients provide helpers to assist with bulk requests and reindexing: * Go: Check out `esutil.BulkIndexer` * Perl: Check out `Search::Elasticsearch::Client::5_0::Bulk` and `Search::Elasticsearch::Client::5_0::Scroll` * Python: Check out `elasticsearch.helpers.*` * JavaScript: Check out `client.helpers.*` * .NET: Check out `BulkAllObservable` * PHP: Check out bulk indexing. **Submitting bulk requests with cURL** If you're providing text file input to `curl`, you must use the `--data-binary` flag instead of plain `-d`. The latter doesn't preserve newlines. For example: ``` $ cat requests { "index" : { "_index" : "test", "_id" : "1" } } { "field1" : "value1" } $ curl -s -H "Content-Type: application/x-ndjson" -XPOST localhost:9200/_bulk --data-binary "@requests"; echo {"took":7, "errors": false, "items":[{"index":{"_index":"test","_id":"1","_version":1,"result":"created","forced_refresh":false}}]} ``` **Optimistic concurrency control** Each `index` and `delete` action within a bulk API call may include the `if_seq_no` and `if_primary_term` parameters in their respective action and meta data lines. The `if_seq_no` and `if_primary_term` parameters control how operations are run, based on the last modification to existing documents. See Optimistic concurrency control for more details. **Versioning** Each bulk item can include the version value using the `version` field. It automatically follows the behavior of the index or delete operation based on the `_version` mapping. It also support the `version_type`. **Routing** Each bulk item can include the routing value using the `routing` field. It automatically follows the behavior of the index or delete operation based on the `_routing` mapping. NOTE: Data streams do not support custom routing unless they were created with the `allow_custom_routing` setting enabled in the template. **Wait for active shards** When making bulk calls, you can set the `wait_for_active_shards` parameter to require a minimum number of shard copies to be active before starting to process the bulk request. **Refresh** Control when the changes made by this request are visible to search. NOTE: Only the shards that receive the bulk request will be affected by refresh. Imagine a `_bulk?refresh=wait_for` request with three documents in it that happen to be routed to different shards in an index with five shards. The request will only wait for those three shards to refresh. The other two shards that make up the index do not participate in the `_bulk` request at all. @@ -45,8 +75,12 @@ export default async function BulkApi<TDocument = unknown, TPartialDocument = un export default async function BulkApi<TDocument = unknown, TPartialDocument = unknown> (this: That, params: T.BulkRequest<TDocument, TPartialDocument>, options?: TransportRequestOptionsWithMeta): Promise<TransportResult<T.BulkResponse, unknown>> export default async function BulkApi<TDocument = unknown, TPartialDocument = unknown> (this: That, params: T.BulkRequest<TDocument, TPartialDocument>, options?: TransportRequestOptions): Promise<T.BulkResponse> export default async function BulkApi<TDocument = unknown, TPartialDocument = unknown> (this: That, params: T.BulkRequest<TDocument, TPartialDocument>, options?: TransportRequestOptions): Promise<any> { - const acceptedPath: string[] = ['index'] - const acceptedBody: string[] = ['operations'] + const { + path: acceptedPath, + body: acceptedBody, + query: acceptedQuery + } = acceptedParams.bulk + const userQuery = params?.querystring const querystring: Record<string, any> = userQuery != null ? { ...userQuery } : {} @@ -58,8 +92,14 @@ export default async function BulkApi<TDocument = unknown, TPartialDocument = un } else if (acceptedPath.includes(key)) { continue } else if (key !== 'body' && key !== 'querystring') { - // @ts-expect-error - querystring[key] = params[key] + if (acceptedQuery.includes(key) || commonQueryParams.includes(key)) { + // @ts-expect-error + querystring[key] = params[key] + } else { + body = body ?? {} + // @ts-expect-error + body[key] = params[key] + } } } diff --git a/src/api/api/capabilities.ts b/src/api/api/capabilities.ts index 1d52df861..ecb8aa285 100644 --- a/src/api/api/capabilities.ts +++ b/src/api/api/capabilities.ts @@ -35,7 +35,18 @@ import { TransportResult } from '@elastic/transport' import * as T from '../types' -interface That { transport: Transport } + +interface That { + transport: Transport +} + +const acceptedParams: Record<string, { path: string[], body: string[], query: string[] }> = { + capabilities: { + path: [], + body: [], + query: [] + } +} /** * Checks if the specified combination of method, API, parameters, and arbitrary capabilities are supported @@ -45,7 +56,10 @@ export default async function CapabilitiesApi (this: That, params?: T.TODO, opti export default async function CapabilitiesApi (this: That, params?: T.TODO, options?: TransportRequestOptionsWithMeta): Promise<TransportResult<T.TODO, unknown>> export default async function CapabilitiesApi (this: That, params?: T.TODO, options?: TransportRequestOptions): Promise<T.TODO> export default async function CapabilitiesApi (this: That, params?: T.TODO, options?: TransportRequestOptions): Promise<any> { - const acceptedPath: string[] = [] + const { + path: acceptedPath + } = acceptedParams.capabilities + const userQuery = params?.querystring const querystring: Record<string, any> = userQuery != null ? { ...userQuery } : {} diff --git a/src/api/api/cat.ts b/src/api/api/cat.ts index bc397b310..c163f4c8b 100644 --- a/src/api/api/cat.ts +++ b/src/api/api/cat.ts @@ -35,12 +35,336 @@ import { TransportResult } from '@elastic/transport' import * as T from '../types' -interface That { transport: Transport } + +interface That { + transport: Transport + acceptedParams: Record<string, { path: string[], body: string[], query: string[] }> +} export default class Cat { transport: Transport + acceptedParams: Record<string, { path: string[], body: string[], query: string[] }> constructor (transport: Transport) { this.transport = transport + this.acceptedParams = { + 'cat.aliases': { + path: [ + 'name' + ], + body: [], + query: [ + 'h', + 's', + 'expand_wildcards', + 'master_timeout' + ] + }, + 'cat.allocation': { + path: [ + 'node_id' + ], + body: [], + query: [ + 'bytes', + 'h', + 's', + 'local', + 'master_timeout' + ] + }, + 'cat.component_templates': { + path: [ + 'name' + ], + body: [], + query: [ + 'h', + 's', + 'local', + 'master_timeout' + ] + }, + 'cat.count': { + path: [ + 'index' + ], + body: [], + query: [ + 'h', + 's' + ] + }, + 'cat.fielddata': { + path: [ + 'fields' + ], + body: [], + query: [ + 'bytes', + 'fields', + 'h', + 's' + ] + }, + 'cat.health': { + path: [], + body: [], + query: [ + 'time', + 'ts', + 'h', + 's' + ] + }, + 'cat.help': { + path: [], + body: [], + query: [] + }, + 'cat.indices': { + path: [ + 'index' + ], + body: [], + query: [ + 'bytes', + 'expand_wildcards', + 'health', + 'include_unloaded_segments', + 'pri', + 'time', + 'master_timeout', + 'h', + 's' + ] + }, + 'cat.master': { + path: [], + body: [], + query: [ + 'h', + 's', + 'local', + 'master_timeout' + ] + }, + 'cat.ml_data_frame_analytics': { + path: [ + 'id' + ], + body: [], + query: [ + 'allow_no_match', + 'bytes', + 'h', + 's', + 'time' + ] + }, + 'cat.ml_datafeeds': { + path: [ + 'datafeed_id' + ], + body: [], + query: [ + 'allow_no_match', + 'h', + 's', + 'time' + ] + }, + 'cat.ml_jobs': { + path: [ + 'job_id' + ], + body: [], + query: [ + 'allow_no_match', + 'bytes', + 'h', + 's', + 'time' + ] + }, + 'cat.ml_trained_models': { + path: [ + 'model_id' + ], + body: [], + query: [ + 'allow_no_match', + 'bytes', + 'h', + 's', + 'from', + 'size', + 'time' + ] + }, + 'cat.nodeattrs': { + path: [], + body: [], + query: [ + 'h', + 's', + 'local', + 'master_timeout' + ] + }, + 'cat.nodes': { + path: [], + body: [], + query: [ + 'bytes', + 'full_id', + 'include_unloaded_segments', + 'h', + 's', + 'master_timeout', + 'time' + ] + }, + 'cat.pending_tasks': { + path: [], + body: [], + query: [ + 'h', + 's', + 'local', + 'master_timeout', + 'time' + ] + }, + 'cat.plugins': { + path: [], + body: [], + query: [ + 'h', + 's', + 'include_bootstrap', + 'local', + 'master_timeout' + ] + }, + 'cat.recovery': { + path: [ + 'index' + ], + body: [], + query: [ + 'active_only', + 'bytes', + 'detailed', + 'index', + 'h', + 's', + 'time' + ] + }, + 'cat.repositories': { + path: [], + body: [], + query: [ + 'h', + 's', + 'local', + 'master_timeout' + ] + }, + 'cat.segments': { + path: [ + 'index' + ], + body: [], + query: [ + 'bytes', + 'h', + 's', + 'local', + 'master_timeout' + ] + }, + 'cat.shards': { + path: [ + 'index' + ], + body: [], + query: [ + 'bytes', + 'h', + 's', + 'master_timeout', + 'time' + ] + }, + 'cat.snapshots': { + path: [ + 'repository' + ], + body: [], + query: [ + 'ignore_unavailable', + 'h', + 's', + 'master_timeout', + 'time' + ] + }, + 'cat.tasks': { + path: [], + body: [], + query: [ + 'actions', + 'detailed', + 'nodes', + 'parent_task_id', + 'h', + 's', + 'time', + 'timeout', + 'wait_for_completion' + ] + }, + 'cat.templates': { + path: [ + 'name' + ], + body: [], + query: [ + 'h', + 's', + 'local', + 'master_timeout' + ] + }, + 'cat.thread_pool': { + path: [ + 'thread_pool_patterns' + ], + body: [], + query: [ + 'h', + 's', + 'time', + 'local', + 'master_timeout' + ] + }, + 'cat.transforms': { + path: [ + 'transform_id' + ], + body: [], + query: [ + 'allow_no_match', + 'from', + 'h', + 's', + 'time', + 'size' + ] + } + } } /** @@ -51,7 +375,10 @@ export default class Cat { async aliases (this: That, params?: T.CatAliasesRequest, options?: TransportRequestOptionsWithMeta): Promise<TransportResult<T.CatAliasesResponse, unknown>> async aliases (this: That, params?: T.CatAliasesRequest, options?: TransportRequestOptions): Promise<T.CatAliasesResponse> async aliases (this: That, params?: T.CatAliasesRequest, options?: TransportRequestOptions): Promise<any> { - const acceptedPath: string[] = ['name'] + const { + path: acceptedPath + } = this.acceptedParams['cat.aliases'] + const userQuery = params?.querystring const querystring: Record<string, any> = userQuery != null ? { ...userQuery } : {} @@ -101,7 +428,10 @@ export default class Cat { async allocation (this: That, params?: T.CatAllocationRequest, options?: TransportRequestOptionsWithMeta): Promise<TransportResult<T.CatAllocationResponse, unknown>> async allocation (this: That, params?: T.CatAllocationRequest, options?: TransportRequestOptions): Promise<T.CatAllocationResponse> async allocation (this: That, params?: T.CatAllocationRequest, options?: TransportRequestOptions): Promise<any> { - const acceptedPath: string[] = ['node_id'] + const { + path: acceptedPath + } = this.acceptedParams['cat.allocation'] + const userQuery = params?.querystring const querystring: Record<string, any> = userQuery != null ? { ...userQuery } : {} @@ -151,7 +481,10 @@ export default class Cat { async componentTemplates (this: That, params?: T.CatComponentTemplatesRequest, options?: TransportRequestOptionsWithMeta): Promise<TransportResult<T.CatComponentTemplatesResponse, unknown>> async componentTemplates (this: That, params?: T.CatComponentTemplatesRequest, options?: TransportRequestOptions): Promise<T.CatComponentTemplatesResponse> async componentTemplates (this: That, params?: T.CatComponentTemplatesRequest, options?: TransportRequestOptions): Promise<any> { - const acceptedPath: string[] = ['name'] + const { + path: acceptedPath + } = this.acceptedParams['cat.component_templates'] + const userQuery = params?.querystring const querystring: Record<string, any> = userQuery != null ? { ...userQuery } : {} @@ -201,7 +534,10 @@ export default class Cat { async count (this: That, params?: T.CatCountRequest, options?: TransportRequestOptionsWithMeta): Promise<TransportResult<T.CatCountResponse, unknown>> async count (this: That, params?: T.CatCountRequest, options?: TransportRequestOptions): Promise<T.CatCountResponse> async count (this: That, params?: T.CatCountRequest, options?: TransportRequestOptions): Promise<any> { - const acceptedPath: string[] = ['index'] + const { + path: acceptedPath + } = this.acceptedParams['cat.count'] + const userQuery = params?.querystring const querystring: Record<string, any> = userQuery != null ? { ...userQuery } : {} @@ -251,7 +587,10 @@ export default class Cat { async fielddata (this: That, params?: T.CatFielddataRequest, options?: TransportRequestOptionsWithMeta): Promise<TransportResult<T.CatFielddataResponse, unknown>> async fielddata (this: That, params?: T.CatFielddataRequest, options?: TransportRequestOptions): Promise<T.CatFielddataResponse> async fielddata (this: That, params?: T.CatFielddataRequest, options?: TransportRequestOptions): Promise<any> { - const acceptedPath: string[] = ['fields'] + const { + path: acceptedPath + } = this.acceptedParams['cat.fielddata'] + const userQuery = params?.querystring const querystring: Record<string, any> = userQuery != null ? { ...userQuery } : {} @@ -301,7 +640,10 @@ export default class Cat { async health (this: That, params?: T.CatHealthRequest, options?: TransportRequestOptionsWithMeta): Promise<TransportResult<T.CatHealthResponse, unknown>> async health (this: That, params?: T.CatHealthRequest, options?: TransportRequestOptions): Promise<T.CatHealthResponse> async health (this: That, params?: T.CatHealthRequest, options?: TransportRequestOptions): Promise<any> { - const acceptedPath: string[] = [] + const { + path: acceptedPath + } = this.acceptedParams['cat.health'] + const userQuery = params?.querystring const querystring: Record<string, any> = userQuery != null ? { ...userQuery } : {} @@ -341,7 +683,10 @@ export default class Cat { async help (this: That, params?: T.CatHelpRequest, options?: TransportRequestOptionsWithMeta): Promise<TransportResult<T.CatHelpResponse, unknown>> async help (this: That, params?: T.CatHelpRequest, options?: TransportRequestOptions): Promise<T.CatHelpResponse> async help (this: That, params?: T.CatHelpRequest, options?: TransportRequestOptions): Promise<any> { - const acceptedPath: string[] = [] + const { + path: acceptedPath + } = this.acceptedParams['cat.help'] + const userQuery = params?.querystring const querystring: Record<string, any> = userQuery != null ? { ...userQuery } : {} @@ -381,7 +726,10 @@ export default class Cat { async indices (this: That, params?: T.CatIndicesRequest, options?: TransportRequestOptionsWithMeta): Promise<TransportResult<T.CatIndicesResponse, unknown>> async indices (this: That, params?: T.CatIndicesRequest, options?: TransportRequestOptions): Promise<T.CatIndicesResponse> async indices (this: That, params?: T.CatIndicesRequest, options?: TransportRequestOptions): Promise<any> { - const acceptedPath: string[] = ['index'] + const { + path: acceptedPath + } = this.acceptedParams['cat.indices'] + const userQuery = params?.querystring const querystring: Record<string, any> = userQuery != null ? { ...userQuery } : {} @@ -431,7 +779,10 @@ export default class Cat { async master (this: That, params?: T.CatMasterRequest, options?: TransportRequestOptionsWithMeta): Promise<TransportResult<T.CatMasterResponse, unknown>> async master (this: That, params?: T.CatMasterRequest, options?: TransportRequestOptions): Promise<T.CatMasterResponse> async master (this: That, params?: T.CatMasterRequest, options?: TransportRequestOptions): Promise<any> { - const acceptedPath: string[] = [] + const { + path: acceptedPath + } = this.acceptedParams['cat.master'] + const userQuery = params?.querystring const querystring: Record<string, any> = userQuery != null ? { ...userQuery } : {} @@ -471,7 +822,10 @@ export default class Cat { async mlDataFrameAnalytics (this: That, params?: T.CatMlDataFrameAnalyticsRequest, options?: TransportRequestOptionsWithMeta): Promise<TransportResult<T.CatMlDataFrameAnalyticsResponse, unknown>> async mlDataFrameAnalytics (this: That, params?: T.CatMlDataFrameAnalyticsRequest, options?: TransportRequestOptions): Promise<T.CatMlDataFrameAnalyticsResponse> async mlDataFrameAnalytics (this: That, params?: T.CatMlDataFrameAnalyticsRequest, options?: TransportRequestOptions): Promise<any> { - const acceptedPath: string[] = ['id'] + const { + path: acceptedPath + } = this.acceptedParams['cat.ml_data_frame_analytics'] + const userQuery = params?.querystring const querystring: Record<string, any> = userQuery != null ? { ...userQuery } : {} @@ -521,7 +875,10 @@ export default class Cat { async mlDatafeeds (this: That, params?: T.CatMlDatafeedsRequest, options?: TransportRequestOptionsWithMeta): Promise<TransportResult<T.CatMlDatafeedsResponse, unknown>> async mlDatafeeds (this: That, params?: T.CatMlDatafeedsRequest, options?: TransportRequestOptions): Promise<T.CatMlDatafeedsResponse> async mlDatafeeds (this: That, params?: T.CatMlDatafeedsRequest, options?: TransportRequestOptions): Promise<any> { - const acceptedPath: string[] = ['datafeed_id'] + const { + path: acceptedPath + } = this.acceptedParams['cat.ml_datafeeds'] + const userQuery = params?.querystring const querystring: Record<string, any> = userQuery != null ? { ...userQuery } : {} @@ -571,7 +928,10 @@ export default class Cat { async mlJobs (this: That, params?: T.CatMlJobsRequest, options?: TransportRequestOptionsWithMeta): Promise<TransportResult<T.CatMlJobsResponse, unknown>> async mlJobs (this: That, params?: T.CatMlJobsRequest, options?: TransportRequestOptions): Promise<T.CatMlJobsResponse> async mlJobs (this: That, params?: T.CatMlJobsRequest, options?: TransportRequestOptions): Promise<any> { - const acceptedPath: string[] = ['job_id'] + const { + path: acceptedPath + } = this.acceptedParams['cat.ml_jobs'] + const userQuery = params?.querystring const querystring: Record<string, any> = userQuery != null ? { ...userQuery } : {} @@ -621,7 +981,10 @@ export default class Cat { async mlTrainedModels (this: That, params?: T.CatMlTrainedModelsRequest, options?: TransportRequestOptionsWithMeta): Promise<TransportResult<T.CatMlTrainedModelsResponse, unknown>> async mlTrainedModels (this: That, params?: T.CatMlTrainedModelsRequest, options?: TransportRequestOptions): Promise<T.CatMlTrainedModelsResponse> async mlTrainedModels (this: That, params?: T.CatMlTrainedModelsRequest, options?: TransportRequestOptions): Promise<any> { - const acceptedPath: string[] = ['model_id'] + const { + path: acceptedPath + } = this.acceptedParams['cat.ml_trained_models'] + const userQuery = params?.querystring const querystring: Record<string, any> = userQuery != null ? { ...userQuery } : {} @@ -671,7 +1034,10 @@ export default class Cat { async nodeattrs (this: That, params?: T.CatNodeattrsRequest, options?: TransportRequestOptionsWithMeta): Promise<TransportResult<T.CatNodeattrsResponse, unknown>> async nodeattrs (this: That, params?: T.CatNodeattrsRequest, options?: TransportRequestOptions): Promise<T.CatNodeattrsResponse> async nodeattrs (this: That, params?: T.CatNodeattrsRequest, options?: TransportRequestOptions): Promise<any> { - const acceptedPath: string[] = [] + const { + path: acceptedPath + } = this.acceptedParams['cat.nodeattrs'] + const userQuery = params?.querystring const querystring: Record<string, any> = userQuery != null ? { ...userQuery } : {} @@ -711,7 +1077,10 @@ export default class Cat { async nodes (this: That, params?: T.CatNodesRequest, options?: TransportRequestOptionsWithMeta): Promise<TransportResult<T.CatNodesResponse, unknown>> async nodes (this: That, params?: T.CatNodesRequest, options?: TransportRequestOptions): Promise<T.CatNodesResponse> async nodes (this: That, params?: T.CatNodesRequest, options?: TransportRequestOptions): Promise<any> { - const acceptedPath: string[] = [] + const { + path: acceptedPath + } = this.acceptedParams['cat.nodes'] + const userQuery = params?.querystring const querystring: Record<string, any> = userQuery != null ? { ...userQuery } : {} @@ -751,7 +1120,10 @@ export default class Cat { async pendingTasks (this: That, params?: T.CatPendingTasksRequest, options?: TransportRequestOptionsWithMeta): Promise<TransportResult<T.CatPendingTasksResponse, unknown>> async pendingTasks (this: That, params?: T.CatPendingTasksRequest, options?: TransportRequestOptions): Promise<T.CatPendingTasksResponse> async pendingTasks (this: That, params?: T.CatPendingTasksRequest, options?: TransportRequestOptions): Promise<any> { - const acceptedPath: string[] = [] + const { + path: acceptedPath + } = this.acceptedParams['cat.pending_tasks'] + const userQuery = params?.querystring const querystring: Record<string, any> = userQuery != null ? { ...userQuery } : {} @@ -791,7 +1163,10 @@ export default class Cat { async plugins (this: That, params?: T.CatPluginsRequest, options?: TransportRequestOptionsWithMeta): Promise<TransportResult<T.CatPluginsResponse, unknown>> async plugins (this: That, params?: T.CatPluginsRequest, options?: TransportRequestOptions): Promise<T.CatPluginsResponse> async plugins (this: That, params?: T.CatPluginsRequest, options?: TransportRequestOptions): Promise<any> { - const acceptedPath: string[] = [] + const { + path: acceptedPath + } = this.acceptedParams['cat.plugins'] + const userQuery = params?.querystring const querystring: Record<string, any> = userQuery != null ? { ...userQuery } : {} @@ -831,7 +1206,10 @@ export default class Cat { async recovery (this: That, params?: T.CatRecoveryRequest, options?: TransportRequestOptionsWithMeta): Promise<TransportResult<T.CatRecoveryResponse, unknown>> async recovery (this: That, params?: T.CatRecoveryRequest, options?: TransportRequestOptions): Promise<T.CatRecoveryResponse> async recovery (this: That, params?: T.CatRecoveryRequest, options?: TransportRequestOptions): Promise<any> { - const acceptedPath: string[] = ['index'] + const { + path: acceptedPath + } = this.acceptedParams['cat.recovery'] + const userQuery = params?.querystring const querystring: Record<string, any> = userQuery != null ? { ...userQuery } : {} @@ -881,7 +1259,10 @@ export default class Cat { async repositories (this: That, params?: T.CatRepositoriesRequest, options?: TransportRequestOptionsWithMeta): Promise<TransportResult<T.CatRepositoriesResponse, unknown>> async repositories (this: That, params?: T.CatRepositoriesRequest, options?: TransportRequestOptions): Promise<T.CatRepositoriesResponse> async repositories (this: That, params?: T.CatRepositoriesRequest, options?: TransportRequestOptions): Promise<any> { - const acceptedPath: string[] = [] + const { + path: acceptedPath + } = this.acceptedParams['cat.repositories'] + const userQuery = params?.querystring const querystring: Record<string, any> = userQuery != null ? { ...userQuery } : {} @@ -921,7 +1302,10 @@ export default class Cat { async segments (this: That, params?: T.CatSegmentsRequest, options?: TransportRequestOptionsWithMeta): Promise<TransportResult<T.CatSegmentsResponse, unknown>> async segments (this: That, params?: T.CatSegmentsRequest, options?: TransportRequestOptions): Promise<T.CatSegmentsResponse> async segments (this: That, params?: T.CatSegmentsRequest, options?: TransportRequestOptions): Promise<any> { - const acceptedPath: string[] = ['index'] + const { + path: acceptedPath + } = this.acceptedParams['cat.segments'] + const userQuery = params?.querystring const querystring: Record<string, any> = userQuery != null ? { ...userQuery } : {} @@ -971,7 +1355,10 @@ export default class Cat { async shards (this: That, params?: T.CatShardsRequest, options?: TransportRequestOptionsWithMeta): Promise<TransportResult<T.CatShardsResponse, unknown>> async shards (this: That, params?: T.CatShardsRequest, options?: TransportRequestOptions): Promise<T.CatShardsResponse> async shards (this: That, params?: T.CatShardsRequest, options?: TransportRequestOptions): Promise<any> { - const acceptedPath: string[] = ['index'] + const { + path: acceptedPath + } = this.acceptedParams['cat.shards'] + const userQuery = params?.querystring const querystring: Record<string, any> = userQuery != null ? { ...userQuery } : {} @@ -1021,7 +1408,10 @@ export default class Cat { async snapshots (this: That, params?: T.CatSnapshotsRequest, options?: TransportRequestOptionsWithMeta): Promise<TransportResult<T.CatSnapshotsResponse, unknown>> async snapshots (this: That, params?: T.CatSnapshotsRequest, options?: TransportRequestOptions): Promise<T.CatSnapshotsResponse> async snapshots (this: That, params?: T.CatSnapshotsRequest, options?: TransportRequestOptions): Promise<any> { - const acceptedPath: string[] = ['repository'] + const { + path: acceptedPath + } = this.acceptedParams['cat.snapshots'] + const userQuery = params?.querystring const querystring: Record<string, any> = userQuery != null ? { ...userQuery } : {} @@ -1071,7 +1461,10 @@ export default class Cat { async tasks (this: That, params?: T.CatTasksRequest, options?: TransportRequestOptionsWithMeta): Promise<TransportResult<T.CatTasksResponse, unknown>> async tasks (this: That, params?: T.CatTasksRequest, options?: TransportRequestOptions): Promise<T.CatTasksResponse> async tasks (this: That, params?: T.CatTasksRequest, options?: TransportRequestOptions): Promise<any> { - const acceptedPath: string[] = [] + const { + path: acceptedPath + } = this.acceptedParams['cat.tasks'] + const userQuery = params?.querystring const querystring: Record<string, any> = userQuery != null ? { ...userQuery } : {} @@ -1111,7 +1504,10 @@ export default class Cat { async templates (this: That, params?: T.CatTemplatesRequest, options?: TransportRequestOptionsWithMeta): Promise<TransportResult<T.CatTemplatesResponse, unknown>> async templates (this: That, params?: T.CatTemplatesRequest, options?: TransportRequestOptions): Promise<T.CatTemplatesResponse> async templates (this: That, params?: T.CatTemplatesRequest, options?: TransportRequestOptions): Promise<any> { - const acceptedPath: string[] = ['name'] + const { + path: acceptedPath + } = this.acceptedParams['cat.templates'] + const userQuery = params?.querystring const querystring: Record<string, any> = userQuery != null ? { ...userQuery } : {} @@ -1161,7 +1557,10 @@ export default class Cat { async threadPool (this: That, params?: T.CatThreadPoolRequest, options?: TransportRequestOptionsWithMeta): Promise<TransportResult<T.CatThreadPoolResponse, unknown>> async threadPool (this: That, params?: T.CatThreadPoolRequest, options?: TransportRequestOptions): Promise<T.CatThreadPoolResponse> async threadPool (this: That, params?: T.CatThreadPoolRequest, options?: TransportRequestOptions): Promise<any> { - const acceptedPath: string[] = ['thread_pool_patterns'] + const { + path: acceptedPath + } = this.acceptedParams['cat.thread_pool'] + const userQuery = params?.querystring const querystring: Record<string, any> = userQuery != null ? { ...userQuery } : {} @@ -1211,7 +1610,10 @@ export default class Cat { async transforms (this: That, params?: T.CatTransformsRequest, options?: TransportRequestOptionsWithMeta): Promise<TransportResult<T.CatTransformsResponse, unknown>> async transforms (this: That, params?: T.CatTransformsRequest, options?: TransportRequestOptions): Promise<T.CatTransformsResponse> async transforms (this: That, params?: T.CatTransformsRequest, options?: TransportRequestOptions): Promise<any> { - const acceptedPath: string[] = ['transform_id'] + const { + path: acceptedPath + } = this.acceptedParams['cat.transforms'] + const userQuery = params?.querystring const querystring: Record<string, any> = userQuery != null ? { ...userQuery } : {} diff --git a/src/api/api/ccr.ts b/src/api/api/ccr.ts index 29455527c..dd704a23f 100644 --- a/src/api/api/ccr.ts +++ b/src/api/api/ccr.ts @@ -35,12 +35,185 @@ import { TransportResult } from '@elastic/transport' import * as T from '../types' -interface That { transport: Transport } + +interface That { + transport: Transport + acceptedParams: Record<string, { path: string[], body: string[], query: string[] }> +} + +const commonQueryParams = ['error_trace', 'filter_path', 'human', 'pretty'] export default class Ccr { transport: Transport + acceptedParams: Record<string, { path: string[], body: string[], query: string[] }> constructor (transport: Transport) { this.transport = transport + this.acceptedParams = { + 'ccr.delete_auto_follow_pattern': { + path: [ + 'name' + ], + body: [], + query: [ + 'master_timeout' + ] + }, + 'ccr.follow': { + path: [ + 'index' + ], + body: [ + 'data_stream_name', + 'leader_index', + 'max_outstanding_read_requests', + 'max_outstanding_write_requests', + 'max_read_request_operation_count', + 'max_read_request_size', + 'max_retry_delay', + 'max_write_buffer_count', + 'max_write_buffer_size', + 'max_write_request_operation_count', + 'max_write_request_size', + 'read_poll_timeout', + 'remote_cluster', + 'settings' + ], + query: [ + 'master_timeout', + 'wait_for_active_shards' + ] + }, + 'ccr.follow_info': { + path: [ + 'index' + ], + body: [], + query: [ + 'master_timeout' + ] + }, + 'ccr.follow_stats': { + path: [ + 'index' + ], + body: [], + query: [ + 'timeout' + ] + }, + 'ccr.forget_follower': { + path: [ + 'index' + ], + body: [ + 'follower_cluster', + 'follower_index', + 'follower_index_uuid', + 'leader_remote_cluster' + ], + query: [ + 'timeout' + ] + }, + 'ccr.get_auto_follow_pattern': { + path: [ + 'name' + ], + body: [], + query: [ + 'master_timeout' + ] + }, + 'ccr.pause_auto_follow_pattern': { + path: [ + 'name' + ], + body: [], + query: [ + 'master_timeout' + ] + }, + 'ccr.pause_follow': { + path: [ + 'index' + ], + body: [], + query: [ + 'master_timeout' + ] + }, + 'ccr.put_auto_follow_pattern': { + path: [ + 'name' + ], + body: [ + 'remote_cluster', + 'follow_index_pattern', + 'leader_index_patterns', + 'leader_index_exclusion_patterns', + 'max_outstanding_read_requests', + 'settings', + 'max_outstanding_write_requests', + 'read_poll_timeout', + 'max_read_request_operation_count', + 'max_read_request_size', + 'max_retry_delay', + 'max_write_buffer_count', + 'max_write_buffer_size', + 'max_write_request_operation_count', + 'max_write_request_size' + ], + query: [ + 'master_timeout' + ] + }, + 'ccr.resume_auto_follow_pattern': { + path: [ + 'name' + ], + body: [], + query: [ + 'master_timeout' + ] + }, + 'ccr.resume_follow': { + path: [ + 'index' + ], + body: [ + 'max_outstanding_read_requests', + 'max_outstanding_write_requests', + 'max_read_request_operation_count', + 'max_read_request_size', + 'max_retry_delay', + 'max_write_buffer_count', + 'max_write_buffer_size', + 'max_write_request_operation_count', + 'max_write_request_size', + 'read_poll_timeout' + ], + query: [ + 'master_timeout' + ] + }, + 'ccr.stats': { + path: [], + body: [], + query: [ + 'master_timeout', + 'timeout' + ] + }, + 'ccr.unfollow': { + path: [ + 'index' + ], + body: [], + query: [ + 'master_timeout' + ] + } + } } /** @@ -51,7 +224,10 @@ export default class Ccr { async deleteAutoFollowPattern (this: That, params: T.CcrDeleteAutoFollowPatternRequest, options?: TransportRequestOptionsWithMeta): Promise<TransportResult<T.CcrDeleteAutoFollowPatternResponse, unknown>> async deleteAutoFollowPattern (this: That, params: T.CcrDeleteAutoFollowPatternRequest, options?: TransportRequestOptions): Promise<T.CcrDeleteAutoFollowPatternResponse> async deleteAutoFollowPattern (this: That, params: T.CcrDeleteAutoFollowPatternRequest, options?: TransportRequestOptions): Promise<any> { - const acceptedPath: string[] = ['name'] + const { + path: acceptedPath + } = this.acceptedParams['ccr.delete_auto_follow_pattern'] + const userQuery = params?.querystring const querystring: Record<string, any> = userQuery != null ? { ...userQuery } : {} @@ -93,8 +269,12 @@ export default class Ccr { async follow (this: That, params: T.CcrFollowRequest, options?: TransportRequestOptionsWithMeta): Promise<TransportResult<T.CcrFollowResponse, unknown>> async follow (this: That, params: T.CcrFollowRequest, options?: TransportRequestOptions): Promise<T.CcrFollowResponse> async follow (this: That, params: T.CcrFollowRequest, options?: TransportRequestOptions): Promise<any> { - const acceptedPath: string[] = ['index'] - const acceptedBody: string[] = ['data_stream_name', 'leader_index', 'max_outstanding_read_requests', 'max_outstanding_write_requests', 'max_read_request_operation_count', 'max_read_request_size', 'max_retry_delay', 'max_write_buffer_count', 'max_write_buffer_size', 'max_write_request_operation_count', 'max_write_request_size', 'read_poll_timeout', 'remote_cluster', 'settings'] + const { + path: acceptedPath, + body: acceptedBody, + query: acceptedQuery + } = this.acceptedParams['ccr.follow'] + const userQuery = params?.querystring const querystring: Record<string, any> = userQuery != null ? { ...userQuery } : {} @@ -116,8 +296,14 @@ export default class Ccr { } else if (acceptedPath.includes(key)) { continue } else if (key !== 'body' && key !== 'querystring') { - // @ts-expect-error - querystring[key] = params[key] + if (acceptedQuery.includes(key) || commonQueryParams.includes(key)) { + // @ts-expect-error + querystring[key] = params[key] + } else { + body = body ?? {} + // @ts-expect-error + body[key] = params[key] + } } } @@ -140,7 +326,10 @@ export default class Ccr { async followInfo (this: That, params: T.CcrFollowInfoRequest, options?: TransportRequestOptionsWithMeta): Promise<TransportResult<T.CcrFollowInfoResponse, unknown>> async followInfo (this: That, params: T.CcrFollowInfoRequest, options?: TransportRequestOptions): Promise<T.CcrFollowInfoResponse> async followInfo (this: That, params: T.CcrFollowInfoRequest, options?: TransportRequestOptions): Promise<any> { - const acceptedPath: string[] = ['index'] + const { + path: acceptedPath + } = this.acceptedParams['ccr.follow_info'] + const userQuery = params?.querystring const querystring: Record<string, any> = userQuery != null ? { ...userQuery } : {} @@ -182,7 +371,10 @@ export default class Ccr { async followStats (this: That, params: T.CcrFollowStatsRequest, options?: TransportRequestOptionsWithMeta): Promise<TransportResult<T.CcrFollowStatsResponse, unknown>> async followStats (this: That, params: T.CcrFollowStatsRequest, options?: TransportRequestOptions): Promise<T.CcrFollowStatsResponse> async followStats (this: That, params: T.CcrFollowStatsRequest, options?: TransportRequestOptions): Promise<any> { - const acceptedPath: string[] = ['index'] + const { + path: acceptedPath + } = this.acceptedParams['ccr.follow_stats'] + const userQuery = params?.querystring const querystring: Record<string, any> = userQuery != null ? { ...userQuery } : {} @@ -224,8 +416,12 @@ export default class Ccr { async forgetFollower (this: That, params: T.CcrForgetFollowerRequest, options?: TransportRequestOptionsWithMeta): Promise<TransportResult<T.CcrForgetFollowerResponse, unknown>> async forgetFollower (this: That, params: T.CcrForgetFollowerRequest, options?: TransportRequestOptions): Promise<T.CcrForgetFollowerResponse> async forgetFollower (this: That, params: T.CcrForgetFollowerRequest, options?: TransportRequestOptions): Promise<any> { - const acceptedPath: string[] = ['index'] - const acceptedBody: string[] = ['follower_cluster', 'follower_index', 'follower_index_uuid', 'leader_remote_cluster'] + const { + path: acceptedPath, + body: acceptedBody, + query: acceptedQuery + } = this.acceptedParams['ccr.forget_follower'] + const userQuery = params?.querystring const querystring: Record<string, any> = userQuery != null ? { ...userQuery } : {} @@ -247,8 +443,14 @@ export default class Ccr { } else if (acceptedPath.includes(key)) { continue } else if (key !== 'body' && key !== 'querystring') { - // @ts-expect-error - querystring[key] = params[key] + if (acceptedQuery.includes(key) || commonQueryParams.includes(key)) { + // @ts-expect-error + querystring[key] = params[key] + } else { + body = body ?? {} + // @ts-expect-error + body[key] = params[key] + } } } @@ -271,7 +473,10 @@ export default class Ccr { async getAutoFollowPattern (this: That, params?: T.CcrGetAutoFollowPatternRequest, options?: TransportRequestOptionsWithMeta): Promise<TransportResult<T.CcrGetAutoFollowPatternResponse, unknown>> async getAutoFollowPattern (this: That, params?: T.CcrGetAutoFollowPatternRequest, options?: TransportRequestOptions): Promise<T.CcrGetAutoFollowPatternResponse> async getAutoFollowPattern (this: That, params?: T.CcrGetAutoFollowPatternRequest, options?: TransportRequestOptions): Promise<any> { - const acceptedPath: string[] = ['name'] + const { + path: acceptedPath + } = this.acceptedParams['ccr.get_auto_follow_pattern'] + const userQuery = params?.querystring const querystring: Record<string, any> = userQuery != null ? { ...userQuery } : {} @@ -321,7 +526,10 @@ export default class Ccr { async pauseAutoFollowPattern (this: That, params: T.CcrPauseAutoFollowPatternRequest, options?: TransportRequestOptionsWithMeta): Promise<TransportResult<T.CcrPauseAutoFollowPatternResponse, unknown>> async pauseAutoFollowPattern (this: That, params: T.CcrPauseAutoFollowPatternRequest, options?: TransportRequestOptions): Promise<T.CcrPauseAutoFollowPatternResponse> async pauseAutoFollowPattern (this: That, params: T.CcrPauseAutoFollowPatternRequest, options?: TransportRequestOptions): Promise<any> { - const acceptedPath: string[] = ['name'] + const { + path: acceptedPath + } = this.acceptedParams['ccr.pause_auto_follow_pattern'] + const userQuery = params?.querystring const querystring: Record<string, any> = userQuery != null ? { ...userQuery } : {} @@ -363,7 +571,10 @@ export default class Ccr { async pauseFollow (this: That, params: T.CcrPauseFollowRequest, options?: TransportRequestOptionsWithMeta): Promise<TransportResult<T.CcrPauseFollowResponse, unknown>> async pauseFollow (this: That, params: T.CcrPauseFollowRequest, options?: TransportRequestOptions): Promise<T.CcrPauseFollowResponse> async pauseFollow (this: That, params: T.CcrPauseFollowRequest, options?: TransportRequestOptions): Promise<any> { - const acceptedPath: string[] = ['index'] + const { + path: acceptedPath + } = this.acceptedParams['ccr.pause_follow'] + const userQuery = params?.querystring const querystring: Record<string, any> = userQuery != null ? { ...userQuery } : {} @@ -405,8 +616,12 @@ export default class Ccr { async putAutoFollowPattern (this: That, params: T.CcrPutAutoFollowPatternRequest, options?: TransportRequestOptionsWithMeta): Promise<TransportResult<T.CcrPutAutoFollowPatternResponse, unknown>> async putAutoFollowPattern (this: That, params: T.CcrPutAutoFollowPatternRequest, options?: TransportRequestOptions): Promise<T.CcrPutAutoFollowPatternResponse> async putAutoFollowPattern (this: That, params: T.CcrPutAutoFollowPatternRequest, options?: TransportRequestOptions): Promise<any> { - const acceptedPath: string[] = ['name'] - const acceptedBody: string[] = ['remote_cluster', 'follow_index_pattern', 'leader_index_patterns', 'leader_index_exclusion_patterns', 'max_outstanding_read_requests', 'settings', 'max_outstanding_write_requests', 'read_poll_timeout', 'max_read_request_operation_count', 'max_read_request_size', 'max_retry_delay', 'max_write_buffer_count', 'max_write_buffer_size', 'max_write_request_operation_count', 'max_write_request_size'] + const { + path: acceptedPath, + body: acceptedBody, + query: acceptedQuery + } = this.acceptedParams['ccr.put_auto_follow_pattern'] + const userQuery = params?.querystring const querystring: Record<string, any> = userQuery != null ? { ...userQuery } : {} @@ -428,8 +643,14 @@ export default class Ccr { } else if (acceptedPath.includes(key)) { continue } else if (key !== 'body' && key !== 'querystring') { - // @ts-expect-error - querystring[key] = params[key] + if (acceptedQuery.includes(key) || commonQueryParams.includes(key)) { + // @ts-expect-error + querystring[key] = params[key] + } else { + body = body ?? {} + // @ts-expect-error + body[key] = params[key] + } } } @@ -452,7 +673,10 @@ export default class Ccr { async resumeAutoFollowPattern (this: That, params: T.CcrResumeAutoFollowPatternRequest, options?: TransportRequestOptionsWithMeta): Promise<TransportResult<T.CcrResumeAutoFollowPatternResponse, unknown>> async resumeAutoFollowPattern (this: That, params: T.CcrResumeAutoFollowPatternRequest, options?: TransportRequestOptions): Promise<T.CcrResumeAutoFollowPatternResponse> async resumeAutoFollowPattern (this: That, params: T.CcrResumeAutoFollowPatternRequest, options?: TransportRequestOptions): Promise<any> { - const acceptedPath: string[] = ['name'] + const { + path: acceptedPath + } = this.acceptedParams['ccr.resume_auto_follow_pattern'] + const userQuery = params?.querystring const querystring: Record<string, any> = userQuery != null ? { ...userQuery } : {} @@ -494,8 +718,12 @@ export default class Ccr { async resumeFollow (this: That, params: T.CcrResumeFollowRequest, options?: TransportRequestOptionsWithMeta): Promise<TransportResult<T.CcrResumeFollowResponse, unknown>> async resumeFollow (this: That, params: T.CcrResumeFollowRequest, options?: TransportRequestOptions): Promise<T.CcrResumeFollowResponse> async resumeFollow (this: That, params: T.CcrResumeFollowRequest, options?: TransportRequestOptions): Promise<any> { - const acceptedPath: string[] = ['index'] - const acceptedBody: string[] = ['max_outstanding_read_requests', 'max_outstanding_write_requests', 'max_read_request_operation_count', 'max_read_request_size', 'max_retry_delay', 'max_write_buffer_count', 'max_write_buffer_size', 'max_write_request_operation_count', 'max_write_request_size', 'read_poll_timeout'] + const { + path: acceptedPath, + body: acceptedBody, + query: acceptedQuery + } = this.acceptedParams['ccr.resume_follow'] + const userQuery = params?.querystring const querystring: Record<string, any> = userQuery != null ? { ...userQuery } : {} @@ -517,8 +745,14 @@ export default class Ccr { } else if (acceptedPath.includes(key)) { continue } else if (key !== 'body' && key !== 'querystring') { - // @ts-expect-error - querystring[key] = params[key] + if (acceptedQuery.includes(key) || commonQueryParams.includes(key)) { + // @ts-expect-error + querystring[key] = params[key] + } else { + body = body ?? {} + // @ts-expect-error + body[key] = params[key] + } } } @@ -541,7 +775,10 @@ export default class Ccr { async stats (this: That, params?: T.CcrStatsRequest, options?: TransportRequestOptionsWithMeta): Promise<TransportResult<T.CcrStatsResponse, unknown>> async stats (this: That, params?: T.CcrStatsRequest, options?: TransportRequestOptions): Promise<T.CcrStatsResponse> async stats (this: That, params?: T.CcrStatsRequest, options?: TransportRequestOptions): Promise<any> { - const acceptedPath: string[] = [] + const { + path: acceptedPath + } = this.acceptedParams['ccr.stats'] + const userQuery = params?.querystring const querystring: Record<string, any> = userQuery != null ? { ...userQuery } : {} @@ -581,7 +818,10 @@ export default class Ccr { async unfollow (this: That, params: T.CcrUnfollowRequest, options?: TransportRequestOptionsWithMeta): Promise<TransportResult<T.CcrUnfollowResponse, unknown>> async unfollow (this: That, params: T.CcrUnfollowRequest, options?: TransportRequestOptions): Promise<T.CcrUnfollowResponse> async unfollow (this: That, params: T.CcrUnfollowRequest, options?: TransportRequestOptions): Promise<any> { - const acceptedPath: string[] = ['index'] + const { + path: acceptedPath + } = this.acceptedParams['ccr.unfollow'] + const userQuery = params?.querystring const querystring: Record<string, any> = userQuery != null ? { ...userQuery } : {} diff --git a/src/api/api/clear_scroll.ts b/src/api/api/clear_scroll.ts index 7b7258503..e78c05005 100644 --- a/src/api/api/clear_scroll.ts +++ b/src/api/api/clear_scroll.ts @@ -35,7 +35,22 @@ import { TransportResult } from '@elastic/transport' import * as T from '../types' -interface That { transport: Transport } + +interface That { + transport: Transport +} + +const commonQueryParams = ['error_trace', 'filter_path', 'human', 'pretty'] + +const acceptedParams: Record<string, { path: string[], body: string[], query: string[] }> = { + clear_scroll: { + path: [], + body: [ + 'scroll_id' + ], + query: [] + } +} /** * Clear a scrolling search. Clear the search context and results for a scrolling search. @@ -45,8 +60,12 @@ export default async function ClearScrollApi (this: That, params?: T.ClearScroll export default async function ClearScrollApi (this: That, params?: T.ClearScrollRequest, options?: TransportRequestOptionsWithMeta): Promise<TransportResult<T.ClearScrollResponse, unknown>> export default async function ClearScrollApi (this: That, params?: T.ClearScrollRequest, options?: TransportRequestOptions): Promise<T.ClearScrollResponse> export default async function ClearScrollApi (this: That, params?: T.ClearScrollRequest, options?: TransportRequestOptions): Promise<any> { - const acceptedPath: string[] = [] - const acceptedBody: string[] = ['scroll_id'] + const { + path: acceptedPath, + body: acceptedBody, + query: acceptedQuery + } = acceptedParams.clear_scroll + const userQuery = params?.querystring const querystring: Record<string, any> = userQuery != null ? { ...userQuery } : {} @@ -69,8 +88,14 @@ export default async function ClearScrollApi (this: That, params?: T.ClearScroll } else if (acceptedPath.includes(key)) { continue } else if (key !== 'body' && key !== 'querystring') { - // @ts-expect-error - querystring[key] = params[key] + if (acceptedQuery.includes(key) || commonQueryParams.includes(key)) { + // @ts-expect-error + querystring[key] = params[key] + } else { + body = body ?? {} + // @ts-expect-error + body[key] = params[key] + } } } diff --git a/src/api/api/close_point_in_time.ts b/src/api/api/close_point_in_time.ts index 26d5b0e26..96d22ced1 100644 --- a/src/api/api/close_point_in_time.ts +++ b/src/api/api/close_point_in_time.ts @@ -35,7 +35,22 @@ import { TransportResult } from '@elastic/transport' import * as T from '../types' -interface That { transport: Transport } + +interface That { + transport: Transport +} + +const commonQueryParams = ['error_trace', 'filter_path', 'human', 'pretty'] + +const acceptedParams: Record<string, { path: string[], body: string[], query: string[] }> = { + close_point_in_time: { + path: [], + body: [ + 'id' + ], + query: [] + } +} /** * Close a point in time. A point in time must be opened explicitly before being used in search requests. The `keep_alive` parameter tells Elasticsearch how long it should persist. A point in time is automatically closed when the `keep_alive` period has elapsed. However, keeping points in time has a cost; close them as soon as they are no longer required for search requests. @@ -45,8 +60,12 @@ export default async function ClosePointInTimeApi (this: That, params: T.ClosePo export default async function ClosePointInTimeApi (this: That, params: T.ClosePointInTimeRequest, options?: TransportRequestOptionsWithMeta): Promise<TransportResult<T.ClosePointInTimeResponse, unknown>> export default async function ClosePointInTimeApi (this: That, params: T.ClosePointInTimeRequest, options?: TransportRequestOptions): Promise<T.ClosePointInTimeResponse> export default async function ClosePointInTimeApi (this: That, params: T.ClosePointInTimeRequest, options?: TransportRequestOptions): Promise<any> { - const acceptedPath: string[] = [] - const acceptedBody: string[] = ['id'] + const { + path: acceptedPath, + body: acceptedBody, + query: acceptedQuery + } = acceptedParams.close_point_in_time + const userQuery = params?.querystring const querystring: Record<string, any> = userQuery != null ? { ...userQuery } : {} @@ -68,8 +87,14 @@ export default async function ClosePointInTimeApi (this: That, params: T.ClosePo } else if (acceptedPath.includes(key)) { continue } else if (key !== 'body' && key !== 'querystring') { - // @ts-expect-error - querystring[key] = params[key] + if (acceptedQuery.includes(key) || commonQueryParams.includes(key)) { + // @ts-expect-error + querystring[key] = params[key] + } else { + body = body ?? {} + // @ts-expect-error + body[key] = params[key] + } } } diff --git a/src/api/api/cluster.ts b/src/api/api/cluster.ts index 730c942d2..a2e8e4495 100644 --- a/src/api/api/cluster.ts +++ b/src/api/api/cluster.ts @@ -35,12 +35,202 @@ import { TransportResult } from '@elastic/transport' import * as T from '../types' -interface That { transport: Transport } + +interface That { + transport: Transport + acceptedParams: Record<string, { path: string[], body: string[], query: string[] }> +} + +const commonQueryParams = ['error_trace', 'filter_path', 'human', 'pretty'] export default class Cluster { transport: Transport + acceptedParams: Record<string, { path: string[], body: string[], query: string[] }> constructor (transport: Transport) { this.transport = transport + this.acceptedParams = { + 'cluster.allocation_explain': { + path: [], + body: [ + 'current_node', + 'index', + 'primary', + 'shard' + ], + query: [ + 'include_disk_info', + 'include_yes_decisions', + 'master_timeout' + ] + }, + 'cluster.delete_component_template': { + path: [ + 'name' + ], + body: [], + query: [ + 'master_timeout', + 'timeout' + ] + }, + 'cluster.delete_voting_config_exclusions': { + path: [], + body: [], + query: [ + 'master_timeout', + 'wait_for_removal' + ] + }, + 'cluster.exists_component_template': { + path: [ + 'name' + ], + body: [], + query: [ + 'master_timeout', + 'local' + ] + }, + 'cluster.get_component_template': { + path: [ + 'name' + ], + body: [], + query: [ + 'flat_settings', + 'include_defaults', + 'local', + 'master_timeout' + ] + }, + 'cluster.get_settings': { + path: [], + body: [], + query: [ + 'flat_settings', + 'include_defaults', + 'master_timeout', + 'timeout' + ] + }, + 'cluster.health': { + path: [ + 'index' + ], + body: [], + query: [ + 'expand_wildcards', + 'level', + 'local', + 'master_timeout', + 'timeout', + 'wait_for_active_shards', + 'wait_for_events', + 'wait_for_nodes', + 'wait_for_no_initializing_shards', + 'wait_for_no_relocating_shards', + 'wait_for_status' + ] + }, + 'cluster.info': { + path: [ + 'target' + ], + body: [], + query: [] + }, + 'cluster.pending_tasks': { + path: [], + body: [], + query: [ + 'local', + 'master_timeout' + ] + }, + 'cluster.post_voting_config_exclusions': { + path: [], + body: [], + query: [ + 'node_names', + 'node_ids', + 'master_timeout', + 'timeout' + ] + }, + 'cluster.put_component_template': { + path: [ + 'name' + ], + body: [ + 'template', + 'version', + '_meta', + 'deprecated' + ], + query: [ + 'create', + 'master_timeout' + ] + }, + 'cluster.put_settings': { + path: [], + body: [ + 'persistent', + 'transient' + ], + query: [ + 'flat_settings', + 'master_timeout', + 'timeout' + ] + }, + 'cluster.remote_info': { + path: [], + body: [], + query: [] + }, + 'cluster.reroute': { + path: [], + body: [ + 'commands' + ], + query: [ + 'dry_run', + 'explain', + 'metric', + 'retry_failed', + 'master_timeout', + 'timeout' + ] + }, + 'cluster.state': { + path: [ + 'metric', + 'index' + ], + body: [], + query: [ + 'allow_no_indices', + 'expand_wildcards', + 'flat_settings', + 'ignore_unavailable', + 'local', + 'master_timeout', + 'wait_for_metadata_version', + 'wait_for_timeout' + ] + }, + 'cluster.stats': { + path: [ + 'node_id' + ], + body: [], + query: [ + 'include_remotes', + 'timeout' + ] + } + } } /** @@ -51,8 +241,12 @@ export default class Cluster { async allocationExplain (this: That, params?: T.ClusterAllocationExplainRequest, options?: TransportRequestOptionsWithMeta): Promise<TransportResult<T.ClusterAllocationExplainResponse, unknown>> async allocationExplain (this: That, params?: T.ClusterAllocationExplainRequest, options?: TransportRequestOptions): Promise<T.ClusterAllocationExplainResponse> async allocationExplain (this: That, params?: T.ClusterAllocationExplainRequest, options?: TransportRequestOptions): Promise<any> { - const acceptedPath: string[] = [] - const acceptedBody: string[] = ['current_node', 'index', 'primary', 'shard'] + const { + path: acceptedPath, + body: acceptedBody, + query: acceptedQuery + } = this.acceptedParams['cluster.allocation_explain'] + const userQuery = params?.querystring const querystring: Record<string, any> = userQuery != null ? { ...userQuery } : {} @@ -75,8 +269,14 @@ export default class Cluster { } else if (acceptedPath.includes(key)) { continue } else if (key !== 'body' && key !== 'querystring') { - // @ts-expect-error - querystring[key] = params[key] + if (acceptedQuery.includes(key) || commonQueryParams.includes(key)) { + // @ts-expect-error + querystring[key] = params[key] + } else { + body = body ?? {} + // @ts-expect-error + body[key] = params[key] + } } } @@ -96,7 +296,10 @@ export default class Cluster { async deleteComponentTemplate (this: That, params: T.ClusterDeleteComponentTemplateRequest, options?: TransportRequestOptionsWithMeta): Promise<TransportResult<T.ClusterDeleteComponentTemplateResponse, unknown>> async deleteComponentTemplate (this: That, params: T.ClusterDeleteComponentTemplateRequest, options?: TransportRequestOptions): Promise<T.ClusterDeleteComponentTemplateResponse> async deleteComponentTemplate (this: That, params: T.ClusterDeleteComponentTemplateRequest, options?: TransportRequestOptions): Promise<any> { - const acceptedPath: string[] = ['name'] + const { + path: acceptedPath + } = this.acceptedParams['cluster.delete_component_template'] + const userQuery = params?.querystring const querystring: Record<string, any> = userQuery != null ? { ...userQuery } : {} @@ -138,7 +341,10 @@ export default class Cluster { async deleteVotingConfigExclusions (this: That, params?: T.ClusterDeleteVotingConfigExclusionsRequest, options?: TransportRequestOptionsWithMeta): Promise<TransportResult<T.ClusterDeleteVotingConfigExclusionsResponse, unknown>> async deleteVotingConfigExclusions (this: That, params?: T.ClusterDeleteVotingConfigExclusionsRequest, options?: TransportRequestOptions): Promise<T.ClusterDeleteVotingConfigExclusionsResponse> async deleteVotingConfigExclusions (this: That, params?: T.ClusterDeleteVotingConfigExclusionsRequest, options?: TransportRequestOptions): Promise<any> { - const acceptedPath: string[] = [] + const { + path: acceptedPath + } = this.acceptedParams['cluster.delete_voting_config_exclusions'] + const userQuery = params?.querystring const querystring: Record<string, any> = userQuery != null ? { ...userQuery } : {} @@ -178,7 +384,10 @@ export default class Cluster { async existsComponentTemplate (this: That, params: T.ClusterExistsComponentTemplateRequest, options?: TransportRequestOptionsWithMeta): Promise<TransportResult<T.ClusterExistsComponentTemplateResponse, unknown>> async existsComponentTemplate (this: That, params: T.ClusterExistsComponentTemplateRequest, options?: TransportRequestOptions): Promise<T.ClusterExistsComponentTemplateResponse> async existsComponentTemplate (this: That, params: T.ClusterExistsComponentTemplateRequest, options?: TransportRequestOptions): Promise<any> { - const acceptedPath: string[] = ['name'] + const { + path: acceptedPath + } = this.acceptedParams['cluster.exists_component_template'] + const userQuery = params?.querystring const querystring: Record<string, any> = userQuery != null ? { ...userQuery } : {} @@ -220,7 +429,10 @@ export default class Cluster { async getComponentTemplate (this: That, params?: T.ClusterGetComponentTemplateRequest, options?: TransportRequestOptionsWithMeta): Promise<TransportResult<T.ClusterGetComponentTemplateResponse, unknown>> async getComponentTemplate (this: That, params?: T.ClusterGetComponentTemplateRequest, options?: TransportRequestOptions): Promise<T.ClusterGetComponentTemplateResponse> async getComponentTemplate (this: That, params?: T.ClusterGetComponentTemplateRequest, options?: TransportRequestOptions): Promise<any> { - const acceptedPath: string[] = ['name'] + const { + path: acceptedPath + } = this.acceptedParams['cluster.get_component_template'] + const userQuery = params?.querystring const querystring: Record<string, any> = userQuery != null ? { ...userQuery } : {} @@ -270,7 +482,10 @@ export default class Cluster { async getSettings (this: That, params?: T.ClusterGetSettingsRequest, options?: TransportRequestOptionsWithMeta): Promise<TransportResult<T.ClusterGetSettingsResponse, unknown>> async getSettings (this: That, params?: T.ClusterGetSettingsRequest, options?: TransportRequestOptions): Promise<T.ClusterGetSettingsResponse> async getSettings (this: That, params?: T.ClusterGetSettingsRequest, options?: TransportRequestOptions): Promise<any> { - const acceptedPath: string[] = [] + const { + path: acceptedPath + } = this.acceptedParams['cluster.get_settings'] + const userQuery = params?.querystring const querystring: Record<string, any> = userQuery != null ? { ...userQuery } : {} @@ -310,7 +525,10 @@ export default class Cluster { async health (this: That, params?: T.ClusterHealthRequest, options?: TransportRequestOptionsWithMeta): Promise<TransportResult<T.ClusterHealthResponse, unknown>> async health (this: That, params?: T.ClusterHealthRequest, options?: TransportRequestOptions): Promise<T.ClusterHealthResponse> async health (this: That, params?: T.ClusterHealthRequest, options?: TransportRequestOptions): Promise<any> { - const acceptedPath: string[] = ['index'] + const { + path: acceptedPath + } = this.acceptedParams['cluster.health'] + const userQuery = params?.querystring const querystring: Record<string, any> = userQuery != null ? { ...userQuery } : {} @@ -360,7 +578,10 @@ export default class Cluster { async info (this: That, params: T.ClusterInfoRequest, options?: TransportRequestOptionsWithMeta): Promise<TransportResult<T.ClusterInfoResponse, unknown>> async info (this: That, params: T.ClusterInfoRequest, options?: TransportRequestOptions): Promise<T.ClusterInfoResponse> async info (this: That, params: T.ClusterInfoRequest, options?: TransportRequestOptions): Promise<any> { - const acceptedPath: string[] = ['target'] + const { + path: acceptedPath + } = this.acceptedParams['cluster.info'] + const userQuery = params?.querystring const querystring: Record<string, any> = userQuery != null ? { ...userQuery } : {} @@ -402,7 +623,10 @@ export default class Cluster { async pendingTasks (this: That, params?: T.ClusterPendingTasksRequest, options?: TransportRequestOptionsWithMeta): Promise<TransportResult<T.ClusterPendingTasksResponse, unknown>> async pendingTasks (this: That, params?: T.ClusterPendingTasksRequest, options?: TransportRequestOptions): Promise<T.ClusterPendingTasksResponse> async pendingTasks (this: That, params?: T.ClusterPendingTasksRequest, options?: TransportRequestOptions): Promise<any> { - const acceptedPath: string[] = [] + const { + path: acceptedPath + } = this.acceptedParams['cluster.pending_tasks'] + const userQuery = params?.querystring const querystring: Record<string, any> = userQuery != null ? { ...userQuery } : {} @@ -442,7 +666,10 @@ export default class Cluster { async postVotingConfigExclusions (this: That, params?: T.ClusterPostVotingConfigExclusionsRequest, options?: TransportRequestOptionsWithMeta): Promise<TransportResult<T.ClusterPostVotingConfigExclusionsResponse, unknown>> async postVotingConfigExclusions (this: That, params?: T.ClusterPostVotingConfigExclusionsRequest, options?: TransportRequestOptions): Promise<T.ClusterPostVotingConfigExclusionsResponse> async postVotingConfigExclusions (this: That, params?: T.ClusterPostVotingConfigExclusionsRequest, options?: TransportRequestOptions): Promise<any> { - const acceptedPath: string[] = [] + const { + path: acceptedPath + } = this.acceptedParams['cluster.post_voting_config_exclusions'] + const userQuery = params?.querystring const querystring: Record<string, any> = userQuery != null ? { ...userQuery } : {} @@ -482,8 +709,12 @@ export default class Cluster { async putComponentTemplate (this: That, params: T.ClusterPutComponentTemplateRequest, options?: TransportRequestOptionsWithMeta): Promise<TransportResult<T.ClusterPutComponentTemplateResponse, unknown>> async putComponentTemplate (this: That, params: T.ClusterPutComponentTemplateRequest, options?: TransportRequestOptions): Promise<T.ClusterPutComponentTemplateResponse> async putComponentTemplate (this: That, params: T.ClusterPutComponentTemplateRequest, options?: TransportRequestOptions): Promise<any> { - const acceptedPath: string[] = ['name'] - const acceptedBody: string[] = ['template', 'version', '_meta', 'deprecated'] + const { + path: acceptedPath, + body: acceptedBody, + query: acceptedQuery + } = this.acceptedParams['cluster.put_component_template'] + const userQuery = params?.querystring const querystring: Record<string, any> = userQuery != null ? { ...userQuery } : {} @@ -505,8 +736,14 @@ export default class Cluster { } else if (acceptedPath.includes(key)) { continue } else if (key !== 'body' && key !== 'querystring') { - // @ts-expect-error - querystring[key] = params[key] + if (acceptedQuery.includes(key) || commonQueryParams.includes(key)) { + // @ts-expect-error + querystring[key] = params[key] + } else { + body = body ?? {} + // @ts-expect-error + body[key] = params[key] + } } } @@ -529,8 +766,12 @@ export default class Cluster { async putSettings (this: That, params?: T.ClusterPutSettingsRequest, options?: TransportRequestOptionsWithMeta): Promise<TransportResult<T.ClusterPutSettingsResponse, unknown>> async putSettings (this: That, params?: T.ClusterPutSettingsRequest, options?: TransportRequestOptions): Promise<T.ClusterPutSettingsResponse> async putSettings (this: That, params?: T.ClusterPutSettingsRequest, options?: TransportRequestOptions): Promise<any> { - const acceptedPath: string[] = [] - const acceptedBody: string[] = ['persistent', 'transient'] + const { + path: acceptedPath, + body: acceptedBody, + query: acceptedQuery + } = this.acceptedParams['cluster.put_settings'] + const userQuery = params?.querystring const querystring: Record<string, any> = userQuery != null ? { ...userQuery } : {} @@ -553,8 +794,14 @@ export default class Cluster { } else if (acceptedPath.includes(key)) { continue } else if (key !== 'body' && key !== 'querystring') { - // @ts-expect-error - querystring[key] = params[key] + if (acceptedQuery.includes(key) || commonQueryParams.includes(key)) { + // @ts-expect-error + querystring[key] = params[key] + } else { + body = body ?? {} + // @ts-expect-error + body[key] = params[key] + } } } @@ -574,7 +821,10 @@ export default class Cluster { async remoteInfo (this: That, params?: T.ClusterRemoteInfoRequest, options?: TransportRequestOptionsWithMeta): Promise<TransportResult<T.ClusterRemoteInfoResponse, unknown>> async remoteInfo (this: That, params?: T.ClusterRemoteInfoRequest, options?: TransportRequestOptions): Promise<T.ClusterRemoteInfoResponse> async remoteInfo (this: That, params?: T.ClusterRemoteInfoRequest, options?: TransportRequestOptions): Promise<any> { - const acceptedPath: string[] = [] + const { + path: acceptedPath + } = this.acceptedParams['cluster.remote_info'] + const userQuery = params?.querystring const querystring: Record<string, any> = userQuery != null ? { ...userQuery } : {} @@ -614,8 +864,12 @@ export default class Cluster { async reroute (this: That, params?: T.ClusterRerouteRequest, options?: TransportRequestOptionsWithMeta): Promise<TransportResult<T.ClusterRerouteResponse, unknown>> async reroute (this: That, params?: T.ClusterRerouteRequest, options?: TransportRequestOptions): Promise<T.ClusterRerouteResponse> async reroute (this: That, params?: T.ClusterRerouteRequest, options?: TransportRequestOptions): Promise<any> { - const acceptedPath: string[] = [] - const acceptedBody: string[] = ['commands'] + const { + path: acceptedPath, + body: acceptedBody, + query: acceptedQuery + } = this.acceptedParams['cluster.reroute'] + const userQuery = params?.querystring const querystring: Record<string, any> = userQuery != null ? { ...userQuery } : {} @@ -638,8 +892,14 @@ export default class Cluster { } else if (acceptedPath.includes(key)) { continue } else if (key !== 'body' && key !== 'querystring') { - // @ts-expect-error - querystring[key] = params[key] + if (acceptedQuery.includes(key) || commonQueryParams.includes(key)) { + // @ts-expect-error + querystring[key] = params[key] + } else { + body = body ?? {} + // @ts-expect-error + body[key] = params[key] + } } } @@ -659,7 +919,10 @@ export default class Cluster { async state (this: That, params?: T.ClusterStateRequest, options?: TransportRequestOptionsWithMeta): Promise<TransportResult<T.ClusterStateResponse, unknown>> async state (this: That, params?: T.ClusterStateRequest, options?: TransportRequestOptions): Promise<T.ClusterStateResponse> async state (this: That, params?: T.ClusterStateRequest, options?: TransportRequestOptions): Promise<any> { - const acceptedPath: string[] = ['metric', 'index'] + const { + path: acceptedPath + } = this.acceptedParams['cluster.state'] + const userQuery = params?.querystring const querystring: Record<string, any> = userQuery != null ? { ...userQuery } : {} @@ -713,7 +976,10 @@ export default class Cluster { async stats (this: That, params?: T.ClusterStatsRequest, options?: TransportRequestOptionsWithMeta): Promise<TransportResult<T.ClusterStatsResponse, unknown>> async stats (this: That, params?: T.ClusterStatsRequest, options?: TransportRequestOptions): Promise<T.ClusterStatsResponse> async stats (this: That, params?: T.ClusterStatsRequest, options?: TransportRequestOptions): Promise<any> { - const acceptedPath: string[] = ['node_id'] + const { + path: acceptedPath + } = this.acceptedParams['cluster.stats'] + const userQuery = params?.querystring const querystring: Record<string, any> = userQuery != null ? { ...userQuery } : {} diff --git a/src/api/api/connector.ts b/src/api/api/connector.ts index 141aa8002..41cdb4316 100644 --- a/src/api/api/connector.ts +++ b/src/api/api/connector.ts @@ -35,12 +35,342 @@ import { TransportResult } from '@elastic/transport' import * as T from '../types' -interface That { transport: Transport } + +interface That { + transport: Transport + acceptedParams: Record<string, { path: string[], body: string[], query: string[] }> +} + +const commonQueryParams = ['error_trace', 'filter_path', 'human', 'pretty'] export default class Connector { transport: Transport + acceptedParams: Record<string, { path: string[], body: string[], query: string[] }> constructor (transport: Transport) { this.transport = transport + this.acceptedParams = { + 'connector.check_in': { + path: [ + 'connector_id' + ], + body: [], + query: [] + }, + 'connector.delete': { + path: [ + 'connector_id' + ], + body: [], + query: [ + 'delete_sync_jobs', + 'hard' + ] + }, + 'connector.get': { + path: [ + 'connector_id' + ], + body: [], + query: [ + 'include_deleted' + ] + }, + 'connector.last_sync': { + path: [ + 'connector_id' + ], + body: [ + 'last_access_control_sync_error', + 'last_access_control_sync_scheduled_at', + 'last_access_control_sync_status', + 'last_deleted_document_count', + 'last_incremental_sync_scheduled_at', + 'last_indexed_document_count', + 'last_seen', + 'last_sync_error', + 'last_sync_scheduled_at', + 'last_sync_status', + 'last_synced', + 'sync_cursor' + ], + query: [] + }, + 'connector.list': { + path: [], + body: [], + query: [ + 'from', + 'size', + 'index_name', + 'connector_name', + 'service_type', + 'include_deleted', + 'query' + ] + }, + 'connector.post': { + path: [], + body: [ + 'description', + 'index_name', + 'is_native', + 'language', + 'name', + 'service_type' + ], + query: [] + }, + 'connector.put': { + path: [ + 'connector_id' + ], + body: [ + 'description', + 'index_name', + 'is_native', + 'language', + 'name', + 'service_type' + ], + query: [] + }, + 'connector.secret_delete': { + path: [ + 'id' + ], + body: [], + query: [] + }, + 'connector.secret_get': { + path: [ + 'id' + ], + body: [], + query: [] + }, + 'connector.secret_post': { + path: [], + body: [], + query: [] + }, + 'connector.secret_put': { + path: [ + 'id' + ], + body: [], + query: [] + }, + 'connector.sync_job_cancel': { + path: [ + 'connector_sync_job_id' + ], + body: [], + query: [] + }, + 'connector.sync_job_check_in': { + path: [ + 'connector_sync_job_id' + ], + body: [], + query: [] + }, + 'connector.sync_job_claim': { + path: [ + 'connector_sync_job_id' + ], + body: [ + 'sync_cursor', + 'worker_hostname' + ], + query: [] + }, + 'connector.sync_job_delete': { + path: [ + 'connector_sync_job_id' + ], + body: [], + query: [] + }, + 'connector.sync_job_error': { + path: [ + 'connector_sync_job_id' + ], + body: [ + 'error' + ], + query: [] + }, + 'connector.sync_job_get': { + path: [ + 'connector_sync_job_id' + ], + body: [], + query: [] + }, + 'connector.sync_job_list': { + path: [], + body: [], + query: [ + 'from', + 'size', + 'status', + 'connector_id', + 'job_type' + ] + }, + 'connector.sync_job_post': { + path: [], + body: [ + 'id', + 'job_type', + 'trigger_method' + ], + query: [] + }, + 'connector.sync_job_update_stats': { + path: [ + 'connector_sync_job_id' + ], + body: [ + 'deleted_document_count', + 'indexed_document_count', + 'indexed_document_volume', + 'last_seen', + 'metadata', + 'total_document_count' + ], + query: [] + }, + 'connector.update_active_filtering': { + path: [ + 'connector_id' + ], + body: [], + query: [] + }, + 'connector.update_api_key_id': { + path: [ + 'connector_id' + ], + body: [ + 'api_key_id', + 'api_key_secret_id' + ], + query: [] + }, + 'connector.update_configuration': { + path: [ + 'connector_id' + ], + body: [ + 'configuration', + 'values' + ], + query: [] + }, + 'connector.update_error': { + path: [ + 'connector_id' + ], + body: [ + 'error' + ], + query: [] + }, + 'connector.update_features': { + path: [ + 'connector_id' + ], + body: [ + 'features' + ], + query: [] + }, + 'connector.update_filtering': { + path: [ + 'connector_id' + ], + body: [ + 'filtering', + 'rules', + 'advanced_snippet' + ], + query: [] + }, + 'connector.update_filtering_validation': { + path: [ + 'connector_id' + ], + body: [ + 'validation' + ], + query: [] + }, + 'connector.update_index_name': { + path: [ + 'connector_id' + ], + body: [ + 'index_name' + ], + query: [] + }, + 'connector.update_name': { + path: [ + 'connector_id' + ], + body: [ + 'name', + 'description' + ], + query: [] + }, + 'connector.update_native': { + path: [ + 'connector_id' + ], + body: [ + 'is_native' + ], + query: [] + }, + 'connector.update_pipeline': { + path: [ + 'connector_id' + ], + body: [ + 'pipeline' + ], + query: [] + }, + 'connector.update_scheduling': { + path: [ + 'connector_id' + ], + body: [ + 'scheduling' + ], + query: [] + }, + 'connector.update_service_type': { + path: [ + 'connector_id' + ], + body: [ + 'service_type' + ], + query: [] + }, + 'connector.update_status': { + path: [ + 'connector_id' + ], + body: [ + 'status' + ], + query: [] + } + } } /** @@ -51,7 +381,10 @@ export default class Connector { async checkIn (this: That, params: T.ConnectorCheckInRequest, options?: TransportRequestOptionsWithMeta): Promise<TransportResult<T.ConnectorCheckInResponse, unknown>> async checkIn (this: That, params: T.ConnectorCheckInRequest, options?: TransportRequestOptions): Promise<T.ConnectorCheckInResponse> async checkIn (this: That, params: T.ConnectorCheckInRequest, options?: TransportRequestOptions): Promise<any> { - const acceptedPath: string[] = ['connector_id'] + const { + path: acceptedPath + } = this.acceptedParams['connector.check_in'] + const userQuery = params?.querystring const querystring: Record<string, any> = userQuery != null ? { ...userQuery } : {} @@ -93,7 +426,10 @@ export default class Connector { async delete (this: That, params: T.ConnectorDeleteRequest, options?: TransportRequestOptionsWithMeta): Promise<TransportResult<T.ConnectorDeleteResponse, unknown>> async delete (this: That, params: T.ConnectorDeleteRequest, options?: TransportRequestOptions): Promise<T.ConnectorDeleteResponse> async delete (this: That, params: T.ConnectorDeleteRequest, options?: TransportRequestOptions): Promise<any> { - const acceptedPath: string[] = ['connector_id'] + const { + path: acceptedPath + } = this.acceptedParams['connector.delete'] + const userQuery = params?.querystring const querystring: Record<string, any> = userQuery != null ? { ...userQuery } : {} @@ -135,7 +471,10 @@ export default class Connector { async get (this: That, params: T.ConnectorGetRequest, options?: TransportRequestOptionsWithMeta): Promise<TransportResult<T.ConnectorGetResponse, unknown>> async get (this: That, params: T.ConnectorGetRequest, options?: TransportRequestOptions): Promise<T.ConnectorGetResponse> async get (this: That, params: T.ConnectorGetRequest, options?: TransportRequestOptions): Promise<any> { - const acceptedPath: string[] = ['connector_id'] + const { + path: acceptedPath + } = this.acceptedParams['connector.get'] + const userQuery = params?.querystring const querystring: Record<string, any> = userQuery != null ? { ...userQuery } : {} @@ -177,8 +516,12 @@ export default class Connector { async lastSync (this: That, params: T.ConnectorLastSyncRequest, options?: TransportRequestOptionsWithMeta): Promise<TransportResult<T.ConnectorLastSyncResponse, unknown>> async lastSync (this: That, params: T.ConnectorLastSyncRequest, options?: TransportRequestOptions): Promise<T.ConnectorLastSyncResponse> async lastSync (this: That, params: T.ConnectorLastSyncRequest, options?: TransportRequestOptions): Promise<any> { - const acceptedPath: string[] = ['connector_id'] - const acceptedBody: string[] = ['last_access_control_sync_error', 'last_access_control_sync_scheduled_at', 'last_access_control_sync_status', 'last_deleted_document_count', 'last_incremental_sync_scheduled_at', 'last_indexed_document_count', 'last_seen', 'last_sync_error', 'last_sync_scheduled_at', 'last_sync_status', 'last_synced', 'sync_cursor'] + const { + path: acceptedPath, + body: acceptedBody, + query: acceptedQuery + } = this.acceptedParams['connector.last_sync'] + const userQuery = params?.querystring const querystring: Record<string, any> = userQuery != null ? { ...userQuery } : {} @@ -200,8 +543,14 @@ export default class Connector { } else if (acceptedPath.includes(key)) { continue } else if (key !== 'body' && key !== 'querystring') { - // @ts-expect-error - querystring[key] = params[key] + if (acceptedQuery.includes(key) || commonQueryParams.includes(key)) { + // @ts-expect-error + querystring[key] = params[key] + } else { + body = body ?? {} + // @ts-expect-error + body[key] = params[key] + } } } @@ -224,7 +573,10 @@ export default class Connector { async list (this: That, params?: T.ConnectorListRequest, options?: TransportRequestOptionsWithMeta): Promise<TransportResult<T.ConnectorListResponse, unknown>> async list (this: That, params?: T.ConnectorListRequest, options?: TransportRequestOptions): Promise<T.ConnectorListResponse> async list (this: That, params?: T.ConnectorListRequest, options?: TransportRequestOptions): Promise<any> { - const acceptedPath: string[] = [] + const { + path: acceptedPath + } = this.acceptedParams['connector.list'] + const userQuery = params?.querystring const querystring: Record<string, any> = userQuery != null ? { ...userQuery } : {} @@ -264,8 +616,12 @@ export default class Connector { async post (this: That, params?: T.ConnectorPostRequest, options?: TransportRequestOptionsWithMeta): Promise<TransportResult<T.ConnectorPostResponse, unknown>> async post (this: That, params?: T.ConnectorPostRequest, options?: TransportRequestOptions): Promise<T.ConnectorPostResponse> async post (this: That, params?: T.ConnectorPostRequest, options?: TransportRequestOptions): Promise<any> { - const acceptedPath: string[] = [] - const acceptedBody: string[] = ['description', 'index_name', 'is_native', 'language', 'name', 'service_type'] + const { + path: acceptedPath, + body: acceptedBody, + query: acceptedQuery + } = this.acceptedParams['connector.post'] + const userQuery = params?.querystring const querystring: Record<string, any> = userQuery != null ? { ...userQuery } : {} @@ -288,8 +644,14 @@ export default class Connector { } else if (acceptedPath.includes(key)) { continue } else if (key !== 'body' && key !== 'querystring') { - // @ts-expect-error - querystring[key] = params[key] + if (acceptedQuery.includes(key) || commonQueryParams.includes(key)) { + // @ts-expect-error + querystring[key] = params[key] + } else { + body = body ?? {} + // @ts-expect-error + body[key] = params[key] + } } } @@ -309,8 +671,12 @@ export default class Connector { async put (this: That, params?: T.ConnectorPutRequest, options?: TransportRequestOptionsWithMeta): Promise<TransportResult<T.ConnectorPutResponse, unknown>> async put (this: That, params?: T.ConnectorPutRequest, options?: TransportRequestOptions): Promise<T.ConnectorPutResponse> async put (this: That, params?: T.ConnectorPutRequest, options?: TransportRequestOptions): Promise<any> { - const acceptedPath: string[] = ['connector_id'] - const acceptedBody: string[] = ['description', 'index_name', 'is_native', 'language', 'name', 'service_type'] + const { + path: acceptedPath, + body: acceptedBody, + query: acceptedQuery + } = this.acceptedParams['connector.put'] + const userQuery = params?.querystring const querystring: Record<string, any> = userQuery != null ? { ...userQuery } : {} @@ -333,8 +699,14 @@ export default class Connector { } else if (acceptedPath.includes(key)) { continue } else if (key !== 'body' && key !== 'querystring') { - // @ts-expect-error - querystring[key] = params[key] + if (acceptedQuery.includes(key) || commonQueryParams.includes(key)) { + // @ts-expect-error + querystring[key] = params[key] + } else { + body = body ?? {} + // @ts-expect-error + body[key] = params[key] + } } } @@ -363,7 +735,10 @@ export default class Connector { async secretDelete (this: That, params?: T.TODO, options?: TransportRequestOptionsWithMeta): Promise<TransportResult<T.TODO, unknown>> async secretDelete (this: That, params?: T.TODO, options?: TransportRequestOptions): Promise<T.TODO> async secretDelete (this: That, params?: T.TODO, options?: TransportRequestOptions): Promise<any> { - const acceptedPath: string[] = ['id'] + const { + path: acceptedPath + } = this.acceptedParams['connector.secret_delete'] + const userQuery = params?.querystring const querystring: Record<string, any> = userQuery != null ? { ...userQuery } : {} @@ -404,7 +779,10 @@ export default class Connector { async secretGet (this: That, params?: T.TODO, options?: TransportRequestOptionsWithMeta): Promise<TransportResult<T.TODO, unknown>> async secretGet (this: That, params?: T.TODO, options?: TransportRequestOptions): Promise<T.TODO> async secretGet (this: That, params?: T.TODO, options?: TransportRequestOptions): Promise<any> { - const acceptedPath: string[] = ['id'] + const { + path: acceptedPath + } = this.acceptedParams['connector.secret_get'] + const userQuery = params?.querystring const querystring: Record<string, any> = userQuery != null ? { ...userQuery } : {} @@ -445,7 +823,10 @@ export default class Connector { async secretPost (this: That, params?: T.TODO, options?: TransportRequestOptionsWithMeta): Promise<TransportResult<T.TODO, unknown>> async secretPost (this: That, params?: T.TODO, options?: TransportRequestOptions): Promise<T.TODO> async secretPost (this: That, params?: T.TODO, options?: TransportRequestOptions): Promise<any> { - const acceptedPath: string[] = [] + const { + path: acceptedPath + } = this.acceptedParams['connector.secret_post'] + const userQuery = params?.querystring const querystring: Record<string, any> = userQuery != null ? { ...userQuery } : {} @@ -483,7 +864,10 @@ export default class Connector { async secretPut (this: That, params?: T.TODO, options?: TransportRequestOptionsWithMeta): Promise<TransportResult<T.TODO, unknown>> async secretPut (this: That, params?: T.TODO, options?: TransportRequestOptions): Promise<T.TODO> async secretPut (this: That, params?: T.TODO, options?: TransportRequestOptions): Promise<any> { - const acceptedPath: string[] = ['id'] + const { + path: acceptedPath + } = this.acceptedParams['connector.secret_put'] + const userQuery = params?.querystring const querystring: Record<string, any> = userQuery != null ? { ...userQuery } : {} @@ -525,7 +909,10 @@ export default class Connector { async syncJobCancel (this: That, params: T.ConnectorSyncJobCancelRequest, options?: TransportRequestOptionsWithMeta): Promise<TransportResult<T.ConnectorSyncJobCancelResponse, unknown>> async syncJobCancel (this: That, params: T.ConnectorSyncJobCancelRequest, options?: TransportRequestOptions): Promise<T.ConnectorSyncJobCancelResponse> async syncJobCancel (this: That, params: T.ConnectorSyncJobCancelRequest, options?: TransportRequestOptions): Promise<any> { - const acceptedPath: string[] = ['connector_sync_job_id'] + const { + path: acceptedPath + } = this.acceptedParams['connector.sync_job_cancel'] + const userQuery = params?.querystring const querystring: Record<string, any> = userQuery != null ? { ...userQuery } : {} @@ -567,7 +954,10 @@ export default class Connector { async syncJobCheckIn (this: That, params: T.ConnectorSyncJobCheckInRequest, options?: TransportRequestOptionsWithMeta): Promise<TransportResult<T.ConnectorSyncJobCheckInResponse, unknown>> async syncJobCheckIn (this: That, params: T.ConnectorSyncJobCheckInRequest, options?: TransportRequestOptions): Promise<T.ConnectorSyncJobCheckInResponse> async syncJobCheckIn (this: That, params: T.ConnectorSyncJobCheckInRequest, options?: TransportRequestOptions): Promise<any> { - const acceptedPath: string[] = ['connector_sync_job_id'] + const { + path: acceptedPath + } = this.acceptedParams['connector.sync_job_check_in'] + const userQuery = params?.querystring const querystring: Record<string, any> = userQuery != null ? { ...userQuery } : {} @@ -609,8 +999,12 @@ export default class Connector { async syncJobClaim (this: That, params: T.ConnectorSyncJobClaimRequest, options?: TransportRequestOptionsWithMeta): Promise<TransportResult<T.ConnectorSyncJobClaimResponse, unknown>> async syncJobClaim (this: That, params: T.ConnectorSyncJobClaimRequest, options?: TransportRequestOptions): Promise<T.ConnectorSyncJobClaimResponse> async syncJobClaim (this: That, params: T.ConnectorSyncJobClaimRequest, options?: TransportRequestOptions): Promise<any> { - const acceptedPath: string[] = ['connector_sync_job_id'] - const acceptedBody: string[] = ['sync_cursor', 'worker_hostname'] + const { + path: acceptedPath, + body: acceptedBody, + query: acceptedQuery + } = this.acceptedParams['connector.sync_job_claim'] + const userQuery = params?.querystring const querystring: Record<string, any> = userQuery != null ? { ...userQuery } : {} @@ -632,8 +1026,14 @@ export default class Connector { } else if (acceptedPath.includes(key)) { continue } else if (key !== 'body' && key !== 'querystring') { - // @ts-expect-error - querystring[key] = params[key] + if (acceptedQuery.includes(key) || commonQueryParams.includes(key)) { + // @ts-expect-error + querystring[key] = params[key] + } else { + body = body ?? {} + // @ts-expect-error + body[key] = params[key] + } } } @@ -656,7 +1056,10 @@ export default class Connector { async syncJobDelete (this: That, params: T.ConnectorSyncJobDeleteRequest, options?: TransportRequestOptionsWithMeta): Promise<TransportResult<T.ConnectorSyncJobDeleteResponse, unknown>> async syncJobDelete (this: That, params: T.ConnectorSyncJobDeleteRequest, options?: TransportRequestOptions): Promise<T.ConnectorSyncJobDeleteResponse> async syncJobDelete (this: That, params: T.ConnectorSyncJobDeleteRequest, options?: TransportRequestOptions): Promise<any> { - const acceptedPath: string[] = ['connector_sync_job_id'] + const { + path: acceptedPath + } = this.acceptedParams['connector.sync_job_delete'] + const userQuery = params?.querystring const querystring: Record<string, any> = userQuery != null ? { ...userQuery } : {} @@ -698,8 +1101,12 @@ export default class Connector { async syncJobError (this: That, params: T.ConnectorSyncJobErrorRequest, options?: TransportRequestOptionsWithMeta): Promise<TransportResult<T.ConnectorSyncJobErrorResponse, unknown>> async syncJobError (this: That, params: T.ConnectorSyncJobErrorRequest, options?: TransportRequestOptions): Promise<T.ConnectorSyncJobErrorResponse> async syncJobError (this: That, params: T.ConnectorSyncJobErrorRequest, options?: TransportRequestOptions): Promise<any> { - const acceptedPath: string[] = ['connector_sync_job_id'] - const acceptedBody: string[] = ['error'] + const { + path: acceptedPath, + body: acceptedBody, + query: acceptedQuery + } = this.acceptedParams['connector.sync_job_error'] + const userQuery = params?.querystring const querystring: Record<string, any> = userQuery != null ? { ...userQuery } : {} @@ -721,8 +1128,14 @@ export default class Connector { } else if (acceptedPath.includes(key)) { continue } else if (key !== 'body' && key !== 'querystring') { - // @ts-expect-error - querystring[key] = params[key] + if (acceptedQuery.includes(key) || commonQueryParams.includes(key)) { + // @ts-expect-error + querystring[key] = params[key] + } else { + body = body ?? {} + // @ts-expect-error + body[key] = params[key] + } } } @@ -745,7 +1158,10 @@ export default class Connector { async syncJobGet (this: That, params: T.ConnectorSyncJobGetRequest, options?: TransportRequestOptionsWithMeta): Promise<TransportResult<T.ConnectorSyncJobGetResponse, unknown>> async syncJobGet (this: That, params: T.ConnectorSyncJobGetRequest, options?: TransportRequestOptions): Promise<T.ConnectorSyncJobGetResponse> async syncJobGet (this: That, params: T.ConnectorSyncJobGetRequest, options?: TransportRequestOptions): Promise<any> { - const acceptedPath: string[] = ['connector_sync_job_id'] + const { + path: acceptedPath + } = this.acceptedParams['connector.sync_job_get'] + const userQuery = params?.querystring const querystring: Record<string, any> = userQuery != null ? { ...userQuery } : {} @@ -787,7 +1203,10 @@ export default class Connector { async syncJobList (this: That, params?: T.ConnectorSyncJobListRequest, options?: TransportRequestOptionsWithMeta): Promise<TransportResult<T.ConnectorSyncJobListResponse, unknown>> async syncJobList (this: That, params?: T.ConnectorSyncJobListRequest, options?: TransportRequestOptions): Promise<T.ConnectorSyncJobListResponse> async syncJobList (this: That, params?: T.ConnectorSyncJobListRequest, options?: TransportRequestOptions): Promise<any> { - const acceptedPath: string[] = [] + const { + path: acceptedPath + } = this.acceptedParams['connector.sync_job_list'] + const userQuery = params?.querystring const querystring: Record<string, any> = userQuery != null ? { ...userQuery } : {} @@ -827,8 +1246,12 @@ export default class Connector { async syncJobPost (this: That, params: T.ConnectorSyncJobPostRequest, options?: TransportRequestOptionsWithMeta): Promise<TransportResult<T.ConnectorSyncJobPostResponse, unknown>> async syncJobPost (this: That, params: T.ConnectorSyncJobPostRequest, options?: TransportRequestOptions): Promise<T.ConnectorSyncJobPostResponse> async syncJobPost (this: That, params: T.ConnectorSyncJobPostRequest, options?: TransportRequestOptions): Promise<any> { - const acceptedPath: string[] = [] - const acceptedBody: string[] = ['id', 'job_type', 'trigger_method'] + const { + path: acceptedPath, + body: acceptedBody, + query: acceptedQuery + } = this.acceptedParams['connector.sync_job_post'] + const userQuery = params?.querystring const querystring: Record<string, any> = userQuery != null ? { ...userQuery } : {} @@ -850,8 +1273,14 @@ export default class Connector { } else if (acceptedPath.includes(key)) { continue } else if (key !== 'body' && key !== 'querystring') { - // @ts-expect-error - querystring[key] = params[key] + if (acceptedQuery.includes(key) || commonQueryParams.includes(key)) { + // @ts-expect-error + querystring[key] = params[key] + } else { + body = body ?? {} + // @ts-expect-error + body[key] = params[key] + } } } @@ -871,8 +1300,12 @@ export default class Connector { async syncJobUpdateStats (this: That, params: T.ConnectorSyncJobUpdateStatsRequest, options?: TransportRequestOptionsWithMeta): Promise<TransportResult<T.ConnectorSyncJobUpdateStatsResponse, unknown>> async syncJobUpdateStats (this: That, params: T.ConnectorSyncJobUpdateStatsRequest, options?: TransportRequestOptions): Promise<T.ConnectorSyncJobUpdateStatsResponse> async syncJobUpdateStats (this: That, params: T.ConnectorSyncJobUpdateStatsRequest, options?: TransportRequestOptions): Promise<any> { - const acceptedPath: string[] = ['connector_sync_job_id'] - const acceptedBody: string[] = ['deleted_document_count', 'indexed_document_count', 'indexed_document_volume', 'last_seen', 'metadata', 'total_document_count'] + const { + path: acceptedPath, + body: acceptedBody, + query: acceptedQuery + } = this.acceptedParams['connector.sync_job_update_stats'] + const userQuery = params?.querystring const querystring: Record<string, any> = userQuery != null ? { ...userQuery } : {} @@ -894,8 +1327,14 @@ export default class Connector { } else if (acceptedPath.includes(key)) { continue } else if (key !== 'body' && key !== 'querystring') { - // @ts-expect-error - querystring[key] = params[key] + if (acceptedQuery.includes(key) || commonQueryParams.includes(key)) { + // @ts-expect-error + querystring[key] = params[key] + } else { + body = body ?? {} + // @ts-expect-error + body[key] = params[key] + } } } @@ -918,7 +1357,10 @@ export default class Connector { async updateActiveFiltering (this: That, params: T.ConnectorUpdateActiveFilteringRequest, options?: TransportRequestOptionsWithMeta): Promise<TransportResult<T.ConnectorUpdateActiveFilteringResponse, unknown>> async updateActiveFiltering (this: That, params: T.ConnectorUpdateActiveFilteringRequest, options?: TransportRequestOptions): Promise<T.ConnectorUpdateActiveFilteringResponse> async updateActiveFiltering (this: That, params: T.ConnectorUpdateActiveFilteringRequest, options?: TransportRequestOptions): Promise<any> { - const acceptedPath: string[] = ['connector_id'] + const { + path: acceptedPath + } = this.acceptedParams['connector.update_active_filtering'] + const userQuery = params?.querystring const querystring: Record<string, any> = userQuery != null ? { ...userQuery } : {} @@ -960,8 +1402,12 @@ export default class Connector { async updateApiKeyId (this: That, params: T.ConnectorUpdateApiKeyIdRequest, options?: TransportRequestOptionsWithMeta): Promise<TransportResult<T.ConnectorUpdateApiKeyIdResponse, unknown>> async updateApiKeyId (this: That, params: T.ConnectorUpdateApiKeyIdRequest, options?: TransportRequestOptions): Promise<T.ConnectorUpdateApiKeyIdResponse> async updateApiKeyId (this: That, params: T.ConnectorUpdateApiKeyIdRequest, options?: TransportRequestOptions): Promise<any> { - const acceptedPath: string[] = ['connector_id'] - const acceptedBody: string[] = ['api_key_id', 'api_key_secret_id'] + const { + path: acceptedPath, + body: acceptedBody, + query: acceptedQuery + } = this.acceptedParams['connector.update_api_key_id'] + const userQuery = params?.querystring const querystring: Record<string, any> = userQuery != null ? { ...userQuery } : {} @@ -983,8 +1429,14 @@ export default class Connector { } else if (acceptedPath.includes(key)) { continue } else if (key !== 'body' && key !== 'querystring') { - // @ts-expect-error - querystring[key] = params[key] + if (acceptedQuery.includes(key) || commonQueryParams.includes(key)) { + // @ts-expect-error + querystring[key] = params[key] + } else { + body = body ?? {} + // @ts-expect-error + body[key] = params[key] + } } } @@ -1007,8 +1459,12 @@ export default class Connector { async updateConfiguration (this: That, params: T.ConnectorUpdateConfigurationRequest, options?: TransportRequestOptionsWithMeta): Promise<TransportResult<T.ConnectorUpdateConfigurationResponse, unknown>> async updateConfiguration (this: That, params: T.ConnectorUpdateConfigurationRequest, options?: TransportRequestOptions): Promise<T.ConnectorUpdateConfigurationResponse> async updateConfiguration (this: That, params: T.ConnectorUpdateConfigurationRequest, options?: TransportRequestOptions): Promise<any> { - const acceptedPath: string[] = ['connector_id'] - const acceptedBody: string[] = ['configuration', 'values'] + const { + path: acceptedPath, + body: acceptedBody, + query: acceptedQuery + } = this.acceptedParams['connector.update_configuration'] + const userQuery = params?.querystring const querystring: Record<string, any> = userQuery != null ? { ...userQuery } : {} @@ -1030,8 +1486,14 @@ export default class Connector { } else if (acceptedPath.includes(key)) { continue } else if (key !== 'body' && key !== 'querystring') { - // @ts-expect-error - querystring[key] = params[key] + if (acceptedQuery.includes(key) || commonQueryParams.includes(key)) { + // @ts-expect-error + querystring[key] = params[key] + } else { + body = body ?? {} + // @ts-expect-error + body[key] = params[key] + } } } @@ -1054,8 +1516,12 @@ export default class Connector { async updateError (this: That, params: T.ConnectorUpdateErrorRequest, options?: TransportRequestOptionsWithMeta): Promise<TransportResult<T.ConnectorUpdateErrorResponse, unknown>> async updateError (this: That, params: T.ConnectorUpdateErrorRequest, options?: TransportRequestOptions): Promise<T.ConnectorUpdateErrorResponse> async updateError (this: That, params: T.ConnectorUpdateErrorRequest, options?: TransportRequestOptions): Promise<any> { - const acceptedPath: string[] = ['connector_id'] - const acceptedBody: string[] = ['error'] + const { + path: acceptedPath, + body: acceptedBody, + query: acceptedQuery + } = this.acceptedParams['connector.update_error'] + const userQuery = params?.querystring const querystring: Record<string, any> = userQuery != null ? { ...userQuery } : {} @@ -1077,8 +1543,14 @@ export default class Connector { } else if (acceptedPath.includes(key)) { continue } else if (key !== 'body' && key !== 'querystring') { - // @ts-expect-error - querystring[key] = params[key] + if (acceptedQuery.includes(key) || commonQueryParams.includes(key)) { + // @ts-expect-error + querystring[key] = params[key] + } else { + body = body ?? {} + // @ts-expect-error + body[key] = params[key] + } } } @@ -1101,8 +1573,12 @@ export default class Connector { async updateFeatures (this: That, params: T.ConnectorUpdateFeaturesRequest, options?: TransportRequestOptionsWithMeta): Promise<TransportResult<T.ConnectorUpdateFeaturesResponse, unknown>> async updateFeatures (this: That, params: T.ConnectorUpdateFeaturesRequest, options?: TransportRequestOptions): Promise<T.ConnectorUpdateFeaturesResponse> async updateFeatures (this: That, params: T.ConnectorUpdateFeaturesRequest, options?: TransportRequestOptions): Promise<any> { - const acceptedPath: string[] = ['connector_id'] - const acceptedBody: string[] = ['features'] + const { + path: acceptedPath, + body: acceptedBody, + query: acceptedQuery + } = this.acceptedParams['connector.update_features'] + const userQuery = params?.querystring const querystring: Record<string, any> = userQuery != null ? { ...userQuery } : {} @@ -1124,8 +1600,14 @@ export default class Connector { } else if (acceptedPath.includes(key)) { continue } else if (key !== 'body' && key !== 'querystring') { - // @ts-expect-error - querystring[key] = params[key] + if (acceptedQuery.includes(key) || commonQueryParams.includes(key)) { + // @ts-expect-error + querystring[key] = params[key] + } else { + body = body ?? {} + // @ts-expect-error + body[key] = params[key] + } } } @@ -1148,8 +1630,12 @@ export default class Connector { async updateFiltering (this: That, params: T.ConnectorUpdateFilteringRequest, options?: TransportRequestOptionsWithMeta): Promise<TransportResult<T.ConnectorUpdateFilteringResponse, unknown>> async updateFiltering (this: That, params: T.ConnectorUpdateFilteringRequest, options?: TransportRequestOptions): Promise<T.ConnectorUpdateFilteringResponse> async updateFiltering (this: That, params: T.ConnectorUpdateFilteringRequest, options?: TransportRequestOptions): Promise<any> { - const acceptedPath: string[] = ['connector_id'] - const acceptedBody: string[] = ['filtering', 'rules', 'advanced_snippet'] + const { + path: acceptedPath, + body: acceptedBody, + query: acceptedQuery + } = this.acceptedParams['connector.update_filtering'] + const userQuery = params?.querystring const querystring: Record<string, any> = userQuery != null ? { ...userQuery } : {} @@ -1171,8 +1657,14 @@ export default class Connector { } else if (acceptedPath.includes(key)) { continue } else if (key !== 'body' && key !== 'querystring') { - // @ts-expect-error - querystring[key] = params[key] + if (acceptedQuery.includes(key) || commonQueryParams.includes(key)) { + // @ts-expect-error + querystring[key] = params[key] + } else { + body = body ?? {} + // @ts-expect-error + body[key] = params[key] + } } } @@ -1195,8 +1687,12 @@ export default class Connector { async updateFilteringValidation (this: That, params: T.ConnectorUpdateFilteringValidationRequest, options?: TransportRequestOptionsWithMeta): Promise<TransportResult<T.ConnectorUpdateFilteringValidationResponse, unknown>> async updateFilteringValidation (this: That, params: T.ConnectorUpdateFilteringValidationRequest, options?: TransportRequestOptions): Promise<T.ConnectorUpdateFilteringValidationResponse> async updateFilteringValidation (this: That, params: T.ConnectorUpdateFilteringValidationRequest, options?: TransportRequestOptions): Promise<any> { - const acceptedPath: string[] = ['connector_id'] - const acceptedBody: string[] = ['validation'] + const { + path: acceptedPath, + body: acceptedBody, + query: acceptedQuery + } = this.acceptedParams['connector.update_filtering_validation'] + const userQuery = params?.querystring const querystring: Record<string, any> = userQuery != null ? { ...userQuery } : {} @@ -1218,8 +1714,14 @@ export default class Connector { } else if (acceptedPath.includes(key)) { continue } else if (key !== 'body' && key !== 'querystring') { - // @ts-expect-error - querystring[key] = params[key] + if (acceptedQuery.includes(key) || commonQueryParams.includes(key)) { + // @ts-expect-error + querystring[key] = params[key] + } else { + body = body ?? {} + // @ts-expect-error + body[key] = params[key] + } } } @@ -1242,8 +1744,12 @@ export default class Connector { async updateIndexName (this: That, params: T.ConnectorUpdateIndexNameRequest, options?: TransportRequestOptionsWithMeta): Promise<TransportResult<T.ConnectorUpdateIndexNameResponse, unknown>> async updateIndexName (this: That, params: T.ConnectorUpdateIndexNameRequest, options?: TransportRequestOptions): Promise<T.ConnectorUpdateIndexNameResponse> async updateIndexName (this: That, params: T.ConnectorUpdateIndexNameRequest, options?: TransportRequestOptions): Promise<any> { - const acceptedPath: string[] = ['connector_id'] - const acceptedBody: string[] = ['index_name'] + const { + path: acceptedPath, + body: acceptedBody, + query: acceptedQuery + } = this.acceptedParams['connector.update_index_name'] + const userQuery = params?.querystring const querystring: Record<string, any> = userQuery != null ? { ...userQuery } : {} @@ -1265,8 +1771,14 @@ export default class Connector { } else if (acceptedPath.includes(key)) { continue } else if (key !== 'body' && key !== 'querystring') { - // @ts-expect-error - querystring[key] = params[key] + if (acceptedQuery.includes(key) || commonQueryParams.includes(key)) { + // @ts-expect-error + querystring[key] = params[key] + } else { + body = body ?? {} + // @ts-expect-error + body[key] = params[key] + } } } @@ -1289,8 +1801,12 @@ export default class Connector { async updateName (this: That, params: T.ConnectorUpdateNameRequest, options?: TransportRequestOptionsWithMeta): Promise<TransportResult<T.ConnectorUpdateNameResponse, unknown>> async updateName (this: That, params: T.ConnectorUpdateNameRequest, options?: TransportRequestOptions): Promise<T.ConnectorUpdateNameResponse> async updateName (this: That, params: T.ConnectorUpdateNameRequest, options?: TransportRequestOptions): Promise<any> { - const acceptedPath: string[] = ['connector_id'] - const acceptedBody: string[] = ['name', 'description'] + const { + path: acceptedPath, + body: acceptedBody, + query: acceptedQuery + } = this.acceptedParams['connector.update_name'] + const userQuery = params?.querystring const querystring: Record<string, any> = userQuery != null ? { ...userQuery } : {} @@ -1312,8 +1828,14 @@ export default class Connector { } else if (acceptedPath.includes(key)) { continue } else if (key !== 'body' && key !== 'querystring') { - // @ts-expect-error - querystring[key] = params[key] + if (acceptedQuery.includes(key) || commonQueryParams.includes(key)) { + // @ts-expect-error + querystring[key] = params[key] + } else { + body = body ?? {} + // @ts-expect-error + body[key] = params[key] + } } } @@ -1336,8 +1858,12 @@ export default class Connector { async updateNative (this: That, params: T.ConnectorUpdateNativeRequest, options?: TransportRequestOptionsWithMeta): Promise<TransportResult<T.ConnectorUpdateNativeResponse, unknown>> async updateNative (this: That, params: T.ConnectorUpdateNativeRequest, options?: TransportRequestOptions): Promise<T.ConnectorUpdateNativeResponse> async updateNative (this: That, params: T.ConnectorUpdateNativeRequest, options?: TransportRequestOptions): Promise<any> { - const acceptedPath: string[] = ['connector_id'] - const acceptedBody: string[] = ['is_native'] + const { + path: acceptedPath, + body: acceptedBody, + query: acceptedQuery + } = this.acceptedParams['connector.update_native'] + const userQuery = params?.querystring const querystring: Record<string, any> = userQuery != null ? { ...userQuery } : {} @@ -1359,8 +1885,14 @@ export default class Connector { } else if (acceptedPath.includes(key)) { continue } else if (key !== 'body' && key !== 'querystring') { - // @ts-expect-error - querystring[key] = params[key] + if (acceptedQuery.includes(key) || commonQueryParams.includes(key)) { + // @ts-expect-error + querystring[key] = params[key] + } else { + body = body ?? {} + // @ts-expect-error + body[key] = params[key] + } } } @@ -1383,8 +1915,12 @@ export default class Connector { async updatePipeline (this: That, params: T.ConnectorUpdatePipelineRequest, options?: TransportRequestOptionsWithMeta): Promise<TransportResult<T.ConnectorUpdatePipelineResponse, unknown>> async updatePipeline (this: That, params: T.ConnectorUpdatePipelineRequest, options?: TransportRequestOptions): Promise<T.ConnectorUpdatePipelineResponse> async updatePipeline (this: That, params: T.ConnectorUpdatePipelineRequest, options?: TransportRequestOptions): Promise<any> { - const acceptedPath: string[] = ['connector_id'] - const acceptedBody: string[] = ['pipeline'] + const { + path: acceptedPath, + body: acceptedBody, + query: acceptedQuery + } = this.acceptedParams['connector.update_pipeline'] + const userQuery = params?.querystring const querystring: Record<string, any> = userQuery != null ? { ...userQuery } : {} @@ -1406,8 +1942,14 @@ export default class Connector { } else if (acceptedPath.includes(key)) { continue } else if (key !== 'body' && key !== 'querystring') { - // @ts-expect-error - querystring[key] = params[key] + if (acceptedQuery.includes(key) || commonQueryParams.includes(key)) { + // @ts-expect-error + querystring[key] = params[key] + } else { + body = body ?? {} + // @ts-expect-error + body[key] = params[key] + } } } @@ -1430,8 +1972,12 @@ export default class Connector { async updateScheduling (this: That, params: T.ConnectorUpdateSchedulingRequest, options?: TransportRequestOptionsWithMeta): Promise<TransportResult<T.ConnectorUpdateSchedulingResponse, unknown>> async updateScheduling (this: That, params: T.ConnectorUpdateSchedulingRequest, options?: TransportRequestOptions): Promise<T.ConnectorUpdateSchedulingResponse> async updateScheduling (this: That, params: T.ConnectorUpdateSchedulingRequest, options?: TransportRequestOptions): Promise<any> { - const acceptedPath: string[] = ['connector_id'] - const acceptedBody: string[] = ['scheduling'] + const { + path: acceptedPath, + body: acceptedBody, + query: acceptedQuery + } = this.acceptedParams['connector.update_scheduling'] + const userQuery = params?.querystring const querystring: Record<string, any> = userQuery != null ? { ...userQuery } : {} @@ -1453,8 +1999,14 @@ export default class Connector { } else if (acceptedPath.includes(key)) { continue } else if (key !== 'body' && key !== 'querystring') { - // @ts-expect-error - querystring[key] = params[key] + if (acceptedQuery.includes(key) || commonQueryParams.includes(key)) { + // @ts-expect-error + querystring[key] = params[key] + } else { + body = body ?? {} + // @ts-expect-error + body[key] = params[key] + } } } @@ -1477,8 +2029,12 @@ export default class Connector { async updateServiceType (this: That, params: T.ConnectorUpdateServiceTypeRequest, options?: TransportRequestOptionsWithMeta): Promise<TransportResult<T.ConnectorUpdateServiceTypeResponse, unknown>> async updateServiceType (this: That, params: T.ConnectorUpdateServiceTypeRequest, options?: TransportRequestOptions): Promise<T.ConnectorUpdateServiceTypeResponse> async updateServiceType (this: That, params: T.ConnectorUpdateServiceTypeRequest, options?: TransportRequestOptions): Promise<any> { - const acceptedPath: string[] = ['connector_id'] - const acceptedBody: string[] = ['service_type'] + const { + path: acceptedPath, + body: acceptedBody, + query: acceptedQuery + } = this.acceptedParams['connector.update_service_type'] + const userQuery = params?.querystring const querystring: Record<string, any> = userQuery != null ? { ...userQuery } : {} @@ -1500,8 +2056,14 @@ export default class Connector { } else if (acceptedPath.includes(key)) { continue } else if (key !== 'body' && key !== 'querystring') { - // @ts-expect-error - querystring[key] = params[key] + if (acceptedQuery.includes(key) || commonQueryParams.includes(key)) { + // @ts-expect-error + querystring[key] = params[key] + } else { + body = body ?? {} + // @ts-expect-error + body[key] = params[key] + } } } @@ -1524,8 +2086,12 @@ export default class Connector { async updateStatus (this: That, params: T.ConnectorUpdateStatusRequest, options?: TransportRequestOptionsWithMeta): Promise<TransportResult<T.ConnectorUpdateStatusResponse, unknown>> async updateStatus (this: That, params: T.ConnectorUpdateStatusRequest, options?: TransportRequestOptions): Promise<T.ConnectorUpdateStatusResponse> async updateStatus (this: That, params: T.ConnectorUpdateStatusRequest, options?: TransportRequestOptions): Promise<any> { - const acceptedPath: string[] = ['connector_id'] - const acceptedBody: string[] = ['status'] + const { + path: acceptedPath, + body: acceptedBody, + query: acceptedQuery + } = this.acceptedParams['connector.update_status'] + const userQuery = params?.querystring const querystring: Record<string, any> = userQuery != null ? { ...userQuery } : {} @@ -1547,8 +2113,14 @@ export default class Connector { } else if (acceptedPath.includes(key)) { continue } else if (key !== 'body' && key !== 'querystring') { - // @ts-expect-error - querystring[key] = params[key] + if (acceptedQuery.includes(key) || commonQueryParams.includes(key)) { + // @ts-expect-error + querystring[key] = params[key] + } else { + body = body ?? {} + // @ts-expect-error + body[key] = params[key] + } } } diff --git a/src/api/api/count.ts b/src/api/api/count.ts index 6e060b369..f86aa7690 100644 --- a/src/api/api/count.ts +++ b/src/api/api/count.ts @@ -35,7 +35,39 @@ import { TransportResult } from '@elastic/transport' import * as T from '../types' -interface That { transport: Transport } + +interface That { + transport: Transport +} + +const commonQueryParams = ['error_trace', 'filter_path', 'human', 'pretty'] + +const acceptedParams: Record<string, { path: string[], body: string[], query: string[] }> = { + count: { + path: [ + 'index' + ], + body: [ + 'query' + ], + query: [ + 'allow_no_indices', + 'analyzer', + 'analyze_wildcard', + 'default_operator', + 'df', + 'expand_wildcards', + 'ignore_throttled', + 'ignore_unavailable', + 'lenient', + 'min_score', + 'preference', + 'routing', + 'terminate_after', + 'q' + ] + } +} /** * Count search results. Get the number of documents matching a query. The query can be provided either by using a simple query string as a parameter, or by defining Query DSL within the request body. The query is optional. When no query is provided, the API uses `match_all` to count all the documents. The count API supports multi-target syntax. You can run a single count API search across multiple data streams and indices. The operation is broadcast across all shards. For each shard ID group, a replica is chosen and the search is run against it. This means that replicas increase the scalability of the count. @@ -45,8 +77,12 @@ export default async function CountApi (this: That, params?: T.CountRequest, opt export default async function CountApi (this: That, params?: T.CountRequest, options?: TransportRequestOptionsWithMeta): Promise<TransportResult<T.CountResponse, unknown>> export default async function CountApi (this: That, params?: T.CountRequest, options?: TransportRequestOptions): Promise<T.CountResponse> export default async function CountApi (this: That, params?: T.CountRequest, options?: TransportRequestOptions): Promise<any> { - const acceptedPath: string[] = ['index'] - const acceptedBody: string[] = ['query'] + const { + path: acceptedPath, + body: acceptedBody, + query: acceptedQuery + } = acceptedParams.count + const userQuery = params?.querystring const querystring: Record<string, any> = userQuery != null ? { ...userQuery } : {} @@ -69,8 +105,14 @@ export default async function CountApi (this: That, params?: T.CountRequest, opt } else if (acceptedPath.includes(key)) { continue } else if (key !== 'body' && key !== 'querystring') { - // @ts-expect-error - querystring[key] = params[key] + if (acceptedQuery.includes(key) || commonQueryParams.includes(key)) { + // @ts-expect-error + querystring[key] = params[key] + } else { + body = body ?? {} + // @ts-expect-error + body[key] = params[key] + } } } diff --git a/src/api/api/create.ts b/src/api/api/create.ts index c8c663fa3..e43ee6b8e 100644 --- a/src/api/api/create.ts +++ b/src/api/api/create.ts @@ -35,7 +35,34 @@ import { TransportResult } from '@elastic/transport' import * as T from '../types' -interface That { transport: Transport } + +interface That { + transport: Transport +} + +const commonQueryParams = ['error_trace', 'filter_path', 'human', 'pretty'] + +const acceptedParams: Record<string, { path: string[], body: string[], query: string[] }> = { + create: { + path: [ + 'id', + 'index' + ], + body: [ + 'document' + ], + query: [ + 'include_source_on_error', + 'pipeline', + 'refresh', + 'routing', + 'timeout', + 'version', + 'version_type', + 'wait_for_active_shards' + ] + } +} /** * Create a new document in the index. You can index a new JSON document with the `/<target>/_doc/` or `/<target>/_create/<_id>` APIs Using `_create` guarantees that the document is indexed only if it does not already exist. It returns a 409 response when a document with a same ID already exists in the index. To update an existing document, you must use the `/<target>/_doc/` API. If the Elasticsearch security features are enabled, you must have the following index privileges for the target data stream, index, or index alias: * To add a document using the `PUT /<target>/_create/<_id>` or `POST /<target>/_create/<_id>` request formats, you must have the `create_doc`, `create`, `index`, or `write` index privilege. * To automatically create a data stream or index with this API request, you must have the `auto_configure`, `create_index`, or `manage` index privilege. Automatic data stream creation requires a matching index template with data stream enabled. **Automatically create data streams and indices** If the request's target doesn't exist and matches an index template with a `data_stream` definition, the index operation automatically creates the data stream. If the target doesn't exist and doesn't match a data stream template, the operation automatically creates the index and applies any matching index templates. NOTE: Elasticsearch includes several built-in index templates. To avoid naming collisions with these templates, refer to index pattern documentation. If no mapping exists, the index operation creates a dynamic mapping. By default, new fields and objects are automatically added to the mapping if needed. Automatic index creation is controlled by the `action.auto_create_index` setting. If it is `true`, any index can be created automatically. You can modify this setting to explicitly allow or block automatic creation of indices that match specified patterns or set it to `false` to turn off automatic index creation entirely. Specify a comma-separated list of patterns you want to allow or prefix each pattern with `+` or `-` to indicate whether it should be allowed or blocked. When a list is specified, the default behaviour is to disallow. NOTE: The `action.auto_create_index` setting affects the automatic creation of indices only. It does not affect the creation of data streams. **Routing** By default, shard placement — or routing — is controlled by using a hash of the document's ID value. For more explicit control, the value fed into the hash function used by the router can be directly specified on a per-operation basis using the `routing` parameter. When setting up explicit mapping, you can also use the `_routing` field to direct the index operation to extract the routing value from the document itself. This does come at the (very minimal) cost of an additional document parsing pass. If the `_routing` mapping is defined and set to be required, the index operation will fail if no routing value is provided or extracted. NOTE: Data streams do not support custom routing unless they were created with the `allow_custom_routing` setting enabled in the template. **Distributed** The index operation is directed to the primary shard based on its route and performed on the actual node containing this shard. After the primary shard completes the operation, if needed, the update is distributed to applicable replicas. **Active shards** To improve the resiliency of writes to the system, indexing operations can be configured to wait for a certain number of active shard copies before proceeding with the operation. If the requisite number of active shard copies are not available, then the write operation must wait and retry, until either the requisite shard copies have started or a timeout occurs. By default, write operations only wait for the primary shards to be active before proceeding (that is to say `wait_for_active_shards` is `1`). This default can be overridden in the index settings dynamically by setting `index.write.wait_for_active_shards`. To alter this behavior per operation, use the `wait_for_active_shards request` parameter. Valid values are all or any positive integer up to the total number of configured copies per shard in the index (which is `number_of_replicas`+1). Specifying a negative value or a number greater than the number of shard copies will throw an error. For example, suppose you have a cluster of three nodes, A, B, and C and you create an index index with the number of replicas set to 3 (resulting in 4 shard copies, one more copy than there are nodes). If you attempt an indexing operation, by default the operation will only ensure the primary copy of each shard is available before proceeding. This means that even if B and C went down and A hosted the primary shard copies, the indexing operation would still proceed with only one copy of the data. If `wait_for_active_shards` is set on the request to `3` (and all three nodes are up), the indexing operation will require 3 active shard copies before proceeding. This requirement should be met because there are 3 active nodes in the cluster, each one holding a copy of the shard. However, if you set `wait_for_active_shards` to `all` (or to `4`, which is the same in this situation), the indexing operation will not proceed as you do not have all 4 copies of each shard active in the index. The operation will timeout unless a new node is brought up in the cluster to host the fourth copy of the shard. It is important to note that this setting greatly reduces the chances of the write operation not writing to the requisite number of shard copies, but it does not completely eliminate the possibility, because this check occurs before the write operation starts. After the write operation is underway, it is still possible for replication to fail on any number of shard copies but still succeed on the primary. The `_shards` section of the API response reveals the number of shard copies on which replication succeeded and failed. @@ -45,8 +72,12 @@ export default async function CreateApi<TDocument = unknown> (this: That, params export default async function CreateApi<TDocument = unknown> (this: That, params: T.CreateRequest<TDocument>, options?: TransportRequestOptionsWithMeta): Promise<TransportResult<T.CreateResponse, unknown>> export default async function CreateApi<TDocument = unknown> (this: That, params: T.CreateRequest<TDocument>, options?: TransportRequestOptions): Promise<T.CreateResponse> export default async function CreateApi<TDocument = unknown> (this: That, params: T.CreateRequest<TDocument>, options?: TransportRequestOptions): Promise<any> { - const acceptedPath: string[] = ['id', 'index'] - const acceptedBody: string[] = ['document'] + const { + path: acceptedPath, + body: acceptedBody, + query: acceptedQuery + } = acceptedParams.create + const userQuery = params?.querystring const querystring: Record<string, any> = userQuery != null ? { ...userQuery } : {} @@ -58,8 +89,14 @@ export default async function CreateApi<TDocument = unknown> (this: That, params } else if (acceptedPath.includes(key)) { continue } else if (key !== 'body' && key !== 'querystring') { - // @ts-expect-error - querystring[key] = params[key] + if (acceptedQuery.includes(key) || commonQueryParams.includes(key)) { + // @ts-expect-error + querystring[key] = params[key] + } else { + body = body ?? {} + // @ts-expect-error + body[key] = params[key] + } } } diff --git a/src/api/api/dangling_indices.ts b/src/api/api/dangling_indices.ts index e8dc5399d..57ff08d00 100644 --- a/src/api/api/dangling_indices.ts +++ b/src/api/api/dangling_indices.ts @@ -35,12 +35,46 @@ import { TransportResult } from '@elastic/transport' import * as T from '../types' -interface That { transport: Transport } + +interface That { + transport: Transport + acceptedParams: Record<string, { path: string[], body: string[], query: string[] }> +} export default class DanglingIndices { transport: Transport + acceptedParams: Record<string, { path: string[], body: string[], query: string[] }> constructor (transport: Transport) { this.transport = transport + this.acceptedParams = { + 'dangling_indices.delete_dangling_index': { + path: [ + 'index_uuid' + ], + body: [], + query: [ + 'accept_data_loss', + 'master_timeout', + 'timeout' + ] + }, + 'dangling_indices.import_dangling_index': { + path: [ + 'index_uuid' + ], + body: [], + query: [ + 'accept_data_loss', + 'master_timeout', + 'timeout' + ] + }, + 'dangling_indices.list_dangling_indices': { + path: [], + body: [], + query: [] + } + } } /** @@ -51,7 +85,10 @@ export default class DanglingIndices { async deleteDanglingIndex (this: That, params: T.DanglingIndicesDeleteDanglingIndexRequest, options?: TransportRequestOptionsWithMeta): Promise<TransportResult<T.DanglingIndicesDeleteDanglingIndexResponse, unknown>> async deleteDanglingIndex (this: That, params: T.DanglingIndicesDeleteDanglingIndexRequest, options?: TransportRequestOptions): Promise<T.DanglingIndicesDeleteDanglingIndexResponse> async deleteDanglingIndex (this: That, params: T.DanglingIndicesDeleteDanglingIndexRequest, options?: TransportRequestOptions): Promise<any> { - const acceptedPath: string[] = ['index_uuid'] + const { + path: acceptedPath + } = this.acceptedParams['dangling_indices.delete_dangling_index'] + const userQuery = params?.querystring const querystring: Record<string, any> = userQuery != null ? { ...userQuery } : {} @@ -93,7 +130,10 @@ export default class DanglingIndices { async importDanglingIndex (this: That, params: T.DanglingIndicesImportDanglingIndexRequest, options?: TransportRequestOptionsWithMeta): Promise<TransportResult<T.DanglingIndicesImportDanglingIndexResponse, unknown>> async importDanglingIndex (this: That, params: T.DanglingIndicesImportDanglingIndexRequest, options?: TransportRequestOptions): Promise<T.DanglingIndicesImportDanglingIndexResponse> async importDanglingIndex (this: That, params: T.DanglingIndicesImportDanglingIndexRequest, options?: TransportRequestOptions): Promise<any> { - const acceptedPath: string[] = ['index_uuid'] + const { + path: acceptedPath + } = this.acceptedParams['dangling_indices.import_dangling_index'] + const userQuery = params?.querystring const querystring: Record<string, any> = userQuery != null ? { ...userQuery } : {} @@ -135,7 +175,10 @@ export default class DanglingIndices { async listDanglingIndices (this: That, params?: T.DanglingIndicesListDanglingIndicesRequest, options?: TransportRequestOptionsWithMeta): Promise<TransportResult<T.DanglingIndicesListDanglingIndicesResponse, unknown>> async listDanglingIndices (this: That, params?: T.DanglingIndicesListDanglingIndicesRequest, options?: TransportRequestOptions): Promise<T.DanglingIndicesListDanglingIndicesResponse> async listDanglingIndices (this: That, params?: T.DanglingIndicesListDanglingIndicesRequest, options?: TransportRequestOptions): Promise<any> { - const acceptedPath: string[] = [] + const { + path: acceptedPath + } = this.acceptedParams['dangling_indices.list_dangling_indices'] + const userQuery = params?.querystring const querystring: Record<string, any> = userQuery != null ? { ...userQuery } : {} diff --git a/src/api/api/delete.ts b/src/api/api/delete.ts index 63b4cf22b..69d7fd9bd 100644 --- a/src/api/api/delete.ts +++ b/src/api/api/delete.ts @@ -35,7 +35,30 @@ import { TransportResult } from '@elastic/transport' import * as T from '../types' -interface That { transport: Transport } + +interface That { + transport: Transport +} + +const acceptedParams: Record<string, { path: string[], body: string[], query: string[] }> = { + delete: { + path: [ + 'id', + 'index' + ], + body: [], + query: [ + 'if_primary_term', + 'if_seq_no', + 'refresh', + 'routing', + 'timeout', + 'version', + 'version_type', + 'wait_for_active_shards' + ] + } +} /** * Delete a document. Remove a JSON document from the specified index. NOTE: You cannot send deletion requests directly to a data stream. To delete a document in a data stream, you must target the backing index containing the document. **Optimistic concurrency control** Delete operations can be made conditional and only be performed if the last modification to the document was assigned the sequence number and primary term specified by the `if_seq_no` and `if_primary_term` parameters. If a mismatch is detected, the operation will result in a `VersionConflictException` and a status code of `409`. **Versioning** Each document indexed is versioned. When deleting a document, the version can be specified to make sure the relevant document you are trying to delete is actually being deleted and it has not changed in the meantime. Every write operation run on a document, deletes included, causes its version to be incremented. The version number of a deleted document remains available for a short time after deletion to allow for control of concurrent operations. The length of time for which a deleted document's version remains available is determined by the `index.gc_deletes` index setting. **Routing** If routing is used during indexing, the routing value also needs to be specified to delete a document. If the `_routing` mapping is set to `required` and no routing value is specified, the delete API throws a `RoutingMissingException` and rejects the request. For example: ``` DELETE /my-index-000001/_doc/1?routing=shard-1 ``` This request deletes the document with ID 1, but it is routed based on the user. The document is not deleted if the correct routing is not specified. **Distributed** The delete operation gets hashed into a specific shard ID. It then gets redirected into the primary shard within that ID group and replicated (if needed) to shard replicas within that ID group. @@ -45,7 +68,10 @@ export default async function DeleteApi (this: That, params: T.DeleteRequest, op export default async function DeleteApi (this: That, params: T.DeleteRequest, options?: TransportRequestOptionsWithMeta): Promise<TransportResult<T.DeleteResponse, unknown>> export default async function DeleteApi (this: That, params: T.DeleteRequest, options?: TransportRequestOptions): Promise<T.DeleteResponse> export default async function DeleteApi (this: That, params: T.DeleteRequest, options?: TransportRequestOptions): Promise<any> { - const acceptedPath: string[] = ['id', 'index'] + const { + path: acceptedPath + } = acceptedParams.delete + const userQuery = params?.querystring const querystring: Record<string, any> = userQuery != null ? { ...userQuery } : {} diff --git a/src/api/api/delete_by_query.ts b/src/api/api/delete_by_query.ts index f99e09670..6842ec280 100644 --- a/src/api/api/delete_by_query.ts +++ b/src/api/api/delete_by_query.ts @@ -35,7 +35,56 @@ import { TransportResult } from '@elastic/transport' import * as T from '../types' -interface That { transport: Transport } + +interface That { + transport: Transport +} + +const commonQueryParams = ['error_trace', 'filter_path', 'human', 'pretty'] + +const acceptedParams: Record<string, { path: string[], body: string[], query: string[] }> = { + delete_by_query: { + path: [ + 'index' + ], + body: [ + 'max_docs', + 'query', + 'slice' + ], + query: [ + 'allow_no_indices', + 'analyzer', + 'analyze_wildcard', + 'conflicts', + 'default_operator', + 'df', + 'expand_wildcards', + 'from', + 'ignore_unavailable', + 'lenient', + 'max_docs', + 'preference', + 'refresh', + 'request_cache', + 'requests_per_second', + 'routing', + 'q', + 'scroll', + 'scroll_size', + 'search_timeout', + 'search_type', + 'slices', + 'sort', + 'stats', + 'terminate_after', + 'timeout', + 'version', + 'wait_for_active_shards', + 'wait_for_completion' + ] + } +} /** * Delete documents. Deletes documents that match the specified query. If the Elasticsearch security features are enabled, you must have the following index privileges for the target data stream, index, or alias: * `read` * `delete` or `write` You can specify the query criteria in the request URI or the request body using the same syntax as the search API. When you submit a delete by query request, Elasticsearch gets a snapshot of the data stream or index when it begins processing the request and deletes matching documents using internal versioning. If a document changes between the time that the snapshot is taken and the delete operation is processed, it results in a version conflict and the delete operation fails. NOTE: Documents with a version equal to 0 cannot be deleted using delete by query because internal versioning does not support 0 as a valid version number. While processing a delete by query request, Elasticsearch performs multiple search requests sequentially to find all of the matching documents to delete. A bulk delete request is performed for each batch of matching documents. If a search or bulk request is rejected, the requests are retried up to 10 times, with exponential back off. If the maximum retry limit is reached, processing halts and all failed requests are returned in the response. Any delete requests that completed successfully still stick, they are not rolled back. You can opt to count version conflicts instead of halting and returning by setting `conflicts` to `proceed`. Note that if you opt to count version conflicts the operation could attempt to delete more documents from the source than `max_docs` until it has successfully deleted `max_docs documents`, or it has gone through every document in the source query. **Throttling delete requests** To control the rate at which delete by query issues batches of delete operations, you can set `requests_per_second` to any positive decimal number. This pads each batch with a wait time to throttle the rate. Set `requests_per_second` to `-1` to disable throttling. Throttling uses a wait time between batches so that the internal scroll requests can be given a timeout that takes the request padding into account. The padding time is the difference between the batch size divided by the `requests_per_second` and the time spent writing. By default the batch size is `1000`, so if `requests_per_second` is set to `500`: ``` target_time = 1000 / 500 per second = 2 seconds wait_time = target_time - write_time = 2 seconds - .5 seconds = 1.5 seconds ``` Since the batch is issued as a single `_bulk` request, large batch sizes cause Elasticsearch to create many requests and wait before starting the next set. This is "bursty" instead of "smooth". **Slicing** Delete by query supports sliced scroll to parallelize the delete process. This can improve efficiency and provide a convenient way to break the request down into smaller parts. Setting `slices` to `auto` lets Elasticsearch choose the number of slices to use. This setting will use one slice per shard, up to a certain limit. If there are multiple source data streams or indices, it will choose the number of slices based on the index or backing index with the smallest number of shards. Adding slices to the delete by query operation creates sub-requests which means it has some quirks: * You can see these requests in the tasks APIs. These sub-requests are "child" tasks of the task for the request with slices. * Fetching the status of the task for the request with slices only contains the status of completed slices. * These sub-requests are individually addressable for things like cancellation and rethrottling. * Rethrottling the request with `slices` will rethrottle the unfinished sub-request proportionally. * Canceling the request with `slices` will cancel each sub-request. * Due to the nature of `slices` each sub-request won't get a perfectly even portion of the documents. All documents will be addressed, but some slices may be larger than others. Expect larger slices to have a more even distribution. * Parameters like `requests_per_second` and `max_docs` on a request with `slices` are distributed proportionally to each sub-request. Combine that with the earlier point about distribution being uneven and you should conclude that using `max_docs` with `slices` might not result in exactly `max_docs` documents being deleted. * Each sub-request gets a slightly different snapshot of the source data stream or index though these are all taken at approximately the same time. If you're slicing manually or otherwise tuning automatic slicing, keep in mind that: * Query performance is most efficient when the number of slices is equal to the number of shards in the index or backing index. If that number is large (for example, 500), choose a lower number as too many `slices` hurts performance. Setting `slices` higher than the number of shards generally does not improve efficiency and adds overhead. * Delete performance scales linearly across available resources with the number of slices. Whether query or delete performance dominates the runtime depends on the documents being reindexed and cluster resources. **Cancel a delete by query operation** Any delete by query can be canceled using the task cancel API. For example: ``` POST _tasks/r1A2WoRbTwKZ516z6NEs5A:36619/_cancel ``` The task ID can be found by using the get tasks API. Cancellation should happen quickly but might take a few seconds. The get task status API will continue to list the delete by query task until this task checks that it has been cancelled and terminates itself. @@ -45,8 +94,12 @@ export default async function DeleteByQueryApi (this: That, params: T.DeleteByQu export default async function DeleteByQueryApi (this: That, params: T.DeleteByQueryRequest, options?: TransportRequestOptionsWithMeta): Promise<TransportResult<T.DeleteByQueryResponse, unknown>> export default async function DeleteByQueryApi (this: That, params: T.DeleteByQueryRequest, options?: TransportRequestOptions): Promise<T.DeleteByQueryResponse> export default async function DeleteByQueryApi (this: That, params: T.DeleteByQueryRequest, options?: TransportRequestOptions): Promise<any> { - const acceptedPath: string[] = ['index'] - const acceptedBody: string[] = ['max_docs', 'query', 'slice'] + const { + path: acceptedPath, + body: acceptedBody, + query: acceptedQuery + } = acceptedParams.delete_by_query + const userQuery = params?.querystring const querystring: Record<string, any> = userQuery != null ? { ...userQuery } : {} @@ -68,8 +121,14 @@ export default async function DeleteByQueryApi (this: That, params: T.DeleteByQu } else if (acceptedPath.includes(key)) { continue } else if (key !== 'body' && key !== 'querystring') { - // @ts-expect-error - querystring[key] = params[key] + if (acceptedQuery.includes(key) || commonQueryParams.includes(key)) { + // @ts-expect-error + querystring[key] = params[key] + } else { + body = body ?? {} + // @ts-expect-error + body[key] = params[key] + } } } diff --git a/src/api/api/delete_by_query_rethrottle.ts b/src/api/api/delete_by_query_rethrottle.ts index 4da430635..23b331b7a 100644 --- a/src/api/api/delete_by_query_rethrottle.ts +++ b/src/api/api/delete_by_query_rethrottle.ts @@ -35,7 +35,22 @@ import { TransportResult } from '@elastic/transport' import * as T from '../types' -interface That { transport: Transport } + +interface That { + transport: Transport +} + +const acceptedParams: Record<string, { path: string[], body: string[], query: string[] }> = { + delete_by_query_rethrottle: { + path: [ + 'task_id' + ], + body: [], + query: [ + 'requests_per_second' + ] + } +} /** * Throttle a delete by query operation. Change the number of requests per second for a particular delete by query operation. Rethrottling that speeds up the query takes effect immediately but rethrotting that slows down the query takes effect after completing the current batch to prevent scroll timeouts. @@ -45,7 +60,10 @@ export default async function DeleteByQueryRethrottleApi (this: That, params: T. export default async function DeleteByQueryRethrottleApi (this: That, params: T.DeleteByQueryRethrottleRequest, options?: TransportRequestOptionsWithMeta): Promise<TransportResult<T.DeleteByQueryRethrottleResponse, unknown>> export default async function DeleteByQueryRethrottleApi (this: That, params: T.DeleteByQueryRethrottleRequest, options?: TransportRequestOptions): Promise<T.DeleteByQueryRethrottleResponse> export default async function DeleteByQueryRethrottleApi (this: That, params: T.DeleteByQueryRethrottleRequest, options?: TransportRequestOptions): Promise<any> { - const acceptedPath: string[] = ['task_id'] + const { + path: acceptedPath + } = acceptedParams.delete_by_query_rethrottle + const userQuery = params?.querystring const querystring: Record<string, any> = userQuery != null ? { ...userQuery } : {} diff --git a/src/api/api/delete_script.ts b/src/api/api/delete_script.ts index e6519dffd..68949420a 100644 --- a/src/api/api/delete_script.ts +++ b/src/api/api/delete_script.ts @@ -35,7 +35,23 @@ import { TransportResult } from '@elastic/transport' import * as T from '../types' -interface That { transport: Transport } + +interface That { + transport: Transport +} + +const acceptedParams: Record<string, { path: string[], body: string[], query: string[] }> = { + delete_script: { + path: [ + 'id' + ], + body: [], + query: [ + 'master_timeout', + 'timeout' + ] + } +} /** * Delete a script or search template. Deletes a stored script or search template. @@ -45,7 +61,10 @@ export default async function DeleteScriptApi (this: That, params: T.DeleteScrip export default async function DeleteScriptApi (this: That, params: T.DeleteScriptRequest, options?: TransportRequestOptionsWithMeta): Promise<TransportResult<T.DeleteScriptResponse, unknown>> export default async function DeleteScriptApi (this: That, params: T.DeleteScriptRequest, options?: TransportRequestOptions): Promise<T.DeleteScriptResponse> export default async function DeleteScriptApi (this: That, params: T.DeleteScriptRequest, options?: TransportRequestOptions): Promise<any> { - const acceptedPath: string[] = ['id'] + const { + path: acceptedPath + } = acceptedParams.delete_script + const userQuery = params?.querystring const querystring: Record<string, any> = userQuery != null ? { ...userQuery } : {} diff --git a/src/api/api/enrich.ts b/src/api/api/enrich.ts index ea301cac5..2a1dff7fc 100644 --- a/src/api/api/enrich.ts +++ b/src/api/api/enrich.ts @@ -35,12 +35,69 @@ import { TransportResult } from '@elastic/transport' import * as T from '../types' -interface That { transport: Transport } + +interface That { + transport: Transport + acceptedParams: Record<string, { path: string[], body: string[], query: string[] }> +} + +const commonQueryParams = ['error_trace', 'filter_path', 'human', 'pretty'] export default class Enrich { transport: Transport + acceptedParams: Record<string, { path: string[], body: string[], query: string[] }> constructor (transport: Transport) { this.transport = transport + this.acceptedParams = { + 'enrich.delete_policy': { + path: [ + 'name' + ], + body: [], + query: [ + 'master_timeout' + ] + }, + 'enrich.execute_policy': { + path: [ + 'name' + ], + body: [], + query: [ + 'master_timeout', + 'wait_for_completion' + ] + }, + 'enrich.get_policy': { + path: [ + 'name' + ], + body: [], + query: [ + 'master_timeout' + ] + }, + 'enrich.put_policy': { + path: [ + 'name' + ], + body: [ + 'geo_match', + 'match', + 'range' + ], + query: [ + 'master_timeout' + ] + }, + 'enrich.stats': { + path: [], + body: [], + query: [ + 'master_timeout' + ] + } + } } /** @@ -51,7 +108,10 @@ export default class Enrich { async deletePolicy (this: That, params: T.EnrichDeletePolicyRequest, options?: TransportRequestOptionsWithMeta): Promise<TransportResult<T.EnrichDeletePolicyResponse, unknown>> async deletePolicy (this: That, params: T.EnrichDeletePolicyRequest, options?: TransportRequestOptions): Promise<T.EnrichDeletePolicyResponse> async deletePolicy (this: That, params: T.EnrichDeletePolicyRequest, options?: TransportRequestOptions): Promise<any> { - const acceptedPath: string[] = ['name'] + const { + path: acceptedPath + } = this.acceptedParams['enrich.delete_policy'] + const userQuery = params?.querystring const querystring: Record<string, any> = userQuery != null ? { ...userQuery } : {} @@ -93,7 +153,10 @@ export default class Enrich { async executePolicy (this: That, params: T.EnrichExecutePolicyRequest, options?: TransportRequestOptionsWithMeta): Promise<TransportResult<T.EnrichExecutePolicyResponse, unknown>> async executePolicy (this: That, params: T.EnrichExecutePolicyRequest, options?: TransportRequestOptions): Promise<T.EnrichExecutePolicyResponse> async executePolicy (this: That, params: T.EnrichExecutePolicyRequest, options?: TransportRequestOptions): Promise<any> { - const acceptedPath: string[] = ['name'] + const { + path: acceptedPath + } = this.acceptedParams['enrich.execute_policy'] + const userQuery = params?.querystring const querystring: Record<string, any> = userQuery != null ? { ...userQuery } : {} @@ -135,7 +198,10 @@ export default class Enrich { async getPolicy (this: That, params?: T.EnrichGetPolicyRequest, options?: TransportRequestOptionsWithMeta): Promise<TransportResult<T.EnrichGetPolicyResponse, unknown>> async getPolicy (this: That, params?: T.EnrichGetPolicyRequest, options?: TransportRequestOptions): Promise<T.EnrichGetPolicyResponse> async getPolicy (this: That, params?: T.EnrichGetPolicyRequest, options?: TransportRequestOptions): Promise<any> { - const acceptedPath: string[] = ['name'] + const { + path: acceptedPath + } = this.acceptedParams['enrich.get_policy'] + const userQuery = params?.querystring const querystring: Record<string, any> = userQuery != null ? { ...userQuery } : {} @@ -185,8 +251,12 @@ export default class Enrich { async putPolicy (this: That, params: T.EnrichPutPolicyRequest, options?: TransportRequestOptionsWithMeta): Promise<TransportResult<T.EnrichPutPolicyResponse, unknown>> async putPolicy (this: That, params: T.EnrichPutPolicyRequest, options?: TransportRequestOptions): Promise<T.EnrichPutPolicyResponse> async putPolicy (this: That, params: T.EnrichPutPolicyRequest, options?: TransportRequestOptions): Promise<any> { - const acceptedPath: string[] = ['name'] - const acceptedBody: string[] = ['geo_match', 'match', 'range'] + const { + path: acceptedPath, + body: acceptedBody, + query: acceptedQuery + } = this.acceptedParams['enrich.put_policy'] + const userQuery = params?.querystring const querystring: Record<string, any> = userQuery != null ? { ...userQuery } : {} @@ -208,8 +278,14 @@ export default class Enrich { } else if (acceptedPath.includes(key)) { continue } else if (key !== 'body' && key !== 'querystring') { - // @ts-expect-error - querystring[key] = params[key] + if (acceptedQuery.includes(key) || commonQueryParams.includes(key)) { + // @ts-expect-error + querystring[key] = params[key] + } else { + body = body ?? {} + // @ts-expect-error + body[key] = params[key] + } } } @@ -232,7 +308,10 @@ export default class Enrich { async stats (this: That, params?: T.EnrichStatsRequest, options?: TransportRequestOptionsWithMeta): Promise<TransportResult<T.EnrichStatsResponse, unknown>> async stats (this: That, params?: T.EnrichStatsRequest, options?: TransportRequestOptions): Promise<T.EnrichStatsResponse> async stats (this: That, params?: T.EnrichStatsRequest, options?: TransportRequestOptions): Promise<any> { - const acceptedPath: string[] = [] + const { + path: acceptedPath + } = this.acceptedParams['enrich.stats'] + const userQuery = params?.querystring const querystring: Record<string, any> = userQuery != null ? { ...userQuery } : {} diff --git a/src/api/api/eql.ts b/src/api/api/eql.ts index 9f490aca9..e645386a6 100644 --- a/src/api/api/eql.ts +++ b/src/api/api/eql.ts @@ -35,12 +35,79 @@ import { TransportResult } from '@elastic/transport' import * as T from '../types' -interface That { transport: Transport } + +interface That { + transport: Transport + acceptedParams: Record<string, { path: string[], body: string[], query: string[] }> +} + +const commonQueryParams = ['error_trace', 'filter_path', 'human', 'pretty'] export default class Eql { transport: Transport + acceptedParams: Record<string, { path: string[], body: string[], query: string[] }> constructor (transport: Transport) { this.transport = transport + this.acceptedParams = { + 'eql.delete': { + path: [ + 'id' + ], + body: [], + query: [] + }, + 'eql.get': { + path: [ + 'id' + ], + body: [], + query: [ + 'keep_alive', + 'wait_for_completion_timeout' + ] + }, + 'eql.get_status': { + path: [ + 'id' + ], + body: [], + query: [] + }, + 'eql.search': { + path: [ + 'index' + ], + body: [ + 'query', + 'case_sensitive', + 'event_category_field', + 'tiebreaker_field', + 'timestamp_field', + 'fetch_size', + 'filter', + 'keep_alive', + 'keep_on_completion', + 'wait_for_completion_timeout', + 'allow_partial_search_results', + 'allow_partial_sequence_results', + 'size', + 'fields', + 'result_position', + 'runtime_mappings', + 'max_samples_per_key' + ], + query: [ + 'allow_no_indices', + 'allow_partial_search_results', + 'allow_partial_sequence_results', + 'expand_wildcards', + 'ignore_unavailable', + 'keep_alive', + 'keep_on_completion', + 'wait_for_completion_timeout' + ] + } + } } /** @@ -51,7 +118,10 @@ export default class Eql { async delete (this: That, params: T.EqlDeleteRequest, options?: TransportRequestOptionsWithMeta): Promise<TransportResult<T.EqlDeleteResponse, unknown>> async delete (this: That, params: T.EqlDeleteRequest, options?: TransportRequestOptions): Promise<T.EqlDeleteResponse> async delete (this: That, params: T.EqlDeleteRequest, options?: TransportRequestOptions): Promise<any> { - const acceptedPath: string[] = ['id'] + const { + path: acceptedPath + } = this.acceptedParams['eql.delete'] + const userQuery = params?.querystring const querystring: Record<string, any> = userQuery != null ? { ...userQuery } : {} @@ -93,7 +163,10 @@ export default class Eql { async get<TEvent = unknown> (this: That, params: T.EqlGetRequest, options?: TransportRequestOptionsWithMeta): Promise<TransportResult<T.EqlGetResponse<TEvent>, unknown>> async get<TEvent = unknown> (this: That, params: T.EqlGetRequest, options?: TransportRequestOptions): Promise<T.EqlGetResponse<TEvent>> async get<TEvent = unknown> (this: That, params: T.EqlGetRequest, options?: TransportRequestOptions): Promise<any> { - const acceptedPath: string[] = ['id'] + const { + path: acceptedPath + } = this.acceptedParams['eql.get'] + const userQuery = params?.querystring const querystring: Record<string, any> = userQuery != null ? { ...userQuery } : {} @@ -135,7 +208,10 @@ export default class Eql { async getStatus (this: That, params: T.EqlGetStatusRequest, options?: TransportRequestOptionsWithMeta): Promise<TransportResult<T.EqlGetStatusResponse, unknown>> async getStatus (this: That, params: T.EqlGetStatusRequest, options?: TransportRequestOptions): Promise<T.EqlGetStatusResponse> async getStatus (this: That, params: T.EqlGetStatusRequest, options?: TransportRequestOptions): Promise<any> { - const acceptedPath: string[] = ['id'] + const { + path: acceptedPath + } = this.acceptedParams['eql.get_status'] + const userQuery = params?.querystring const querystring: Record<string, any> = userQuery != null ? { ...userQuery } : {} @@ -177,8 +253,12 @@ export default class Eql { async search<TEvent = unknown> (this: That, params: T.EqlSearchRequest, options?: TransportRequestOptionsWithMeta): Promise<TransportResult<T.EqlSearchResponse<TEvent>, unknown>> async search<TEvent = unknown> (this: That, params: T.EqlSearchRequest, options?: TransportRequestOptions): Promise<T.EqlSearchResponse<TEvent>> async search<TEvent = unknown> (this: That, params: T.EqlSearchRequest, options?: TransportRequestOptions): Promise<any> { - const acceptedPath: string[] = ['index'] - const acceptedBody: string[] = ['query', 'case_sensitive', 'event_category_field', 'tiebreaker_field', 'timestamp_field', 'fetch_size', 'filter', 'keep_alive', 'keep_on_completion', 'wait_for_completion_timeout', 'allow_partial_search_results', 'allow_partial_sequence_results', 'size', 'fields', 'result_position', 'runtime_mappings', 'max_samples_per_key'] + const { + path: acceptedPath, + body: acceptedBody, + query: acceptedQuery + } = this.acceptedParams['eql.search'] + const userQuery = params?.querystring const querystring: Record<string, any> = userQuery != null ? { ...userQuery } : {} @@ -200,8 +280,14 @@ export default class Eql { } else if (acceptedPath.includes(key)) { continue } else if (key !== 'body' && key !== 'querystring') { - // @ts-expect-error - querystring[key] = params[key] + if (acceptedQuery.includes(key) || commonQueryParams.includes(key)) { + // @ts-expect-error + querystring[key] = params[key] + } else { + body = body ?? {} + // @ts-expect-error + body[key] = params[key] + } } } diff --git a/src/api/api/esql.ts b/src/api/api/esql.ts index d76ed6962..d7bcfa0c1 100644 --- a/src/api/api/esql.ts +++ b/src/api/api/esql.ts @@ -35,12 +35,87 @@ import { TransportResult } from '@elastic/transport' import * as T from '../types' -interface That { transport: Transport } + +interface That { + transport: Transport + acceptedParams: Record<string, { path: string[], body: string[], query: string[] }> +} + +const commonQueryParams = ['error_trace', 'filter_path', 'human', 'pretty'] export default class Esql { transport: Transport + acceptedParams: Record<string, { path: string[], body: string[], query: string[] }> constructor (transport: Transport) { this.transport = transport + this.acceptedParams = { + 'esql.async_query': { + path: [], + body: [ + 'columnar', + 'filter', + 'locale', + 'params', + 'profile', + 'query', + 'tables', + 'include_ccs_metadata' + ], + query: [ + 'delimiter', + 'drop_null_columns', + 'format', + 'keep_alive', + 'keep_on_completion', + 'wait_for_completion_timeout' + ] + }, + 'esql.async_query_delete': { + path: [ + 'id' + ], + body: [], + query: [] + }, + 'esql.async_query_get': { + path: [ + 'id' + ], + body: [], + query: [ + 'drop_null_columns', + 'keep_alive', + 'wait_for_completion_timeout' + ] + }, + 'esql.async_query_stop': { + path: [ + 'id' + ], + body: [], + query: [ + 'drop_null_columns' + ] + }, + 'esql.query': { + path: [], + body: [ + 'columnar', + 'filter', + 'locale', + 'params', + 'profile', + 'query', + 'tables', + 'include_ccs_metadata' + ], + query: [ + 'format', + 'delimiter', + 'drop_null_columns' + ] + } + } } /** @@ -51,8 +126,12 @@ export default class Esql { async asyncQuery (this: That, params: T.EsqlAsyncQueryRequest, options?: TransportRequestOptionsWithMeta): Promise<TransportResult<T.EsqlAsyncQueryResponse, unknown>> async asyncQuery (this: That, params: T.EsqlAsyncQueryRequest, options?: TransportRequestOptions): Promise<T.EsqlAsyncQueryResponse> async asyncQuery (this: That, params: T.EsqlAsyncQueryRequest, options?: TransportRequestOptions): Promise<any> { - const acceptedPath: string[] = [] - const acceptedBody: string[] = ['columnar', 'filter', 'locale', 'params', 'profile', 'query', 'tables', 'include_ccs_metadata'] + const { + path: acceptedPath, + body: acceptedBody, + query: acceptedQuery + } = this.acceptedParams['esql.async_query'] + const userQuery = params?.querystring const querystring: Record<string, any> = userQuery != null ? { ...userQuery } : {} @@ -74,8 +153,14 @@ export default class Esql { } else if (acceptedPath.includes(key)) { continue } else if (key !== 'body' && key !== 'querystring') { - // @ts-expect-error - querystring[key] = params[key] + if (acceptedQuery.includes(key) || commonQueryParams.includes(key)) { + // @ts-expect-error + querystring[key] = params[key] + } else { + body = body ?? {} + // @ts-expect-error + body[key] = params[key] + } } } @@ -95,7 +180,10 @@ export default class Esql { async asyncQueryDelete (this: That, params: T.EsqlAsyncQueryDeleteRequest, options?: TransportRequestOptionsWithMeta): Promise<TransportResult<T.EsqlAsyncQueryDeleteResponse, unknown>> async asyncQueryDelete (this: That, params: T.EsqlAsyncQueryDeleteRequest, options?: TransportRequestOptions): Promise<T.EsqlAsyncQueryDeleteResponse> async asyncQueryDelete (this: That, params: T.EsqlAsyncQueryDeleteRequest, options?: TransportRequestOptions): Promise<any> { - const acceptedPath: string[] = ['id'] + const { + path: acceptedPath + } = this.acceptedParams['esql.async_query_delete'] + const userQuery = params?.querystring const querystring: Record<string, any> = userQuery != null ? { ...userQuery } : {} @@ -137,7 +225,10 @@ export default class Esql { async asyncQueryGet (this: That, params: T.EsqlAsyncQueryGetRequest, options?: TransportRequestOptionsWithMeta): Promise<TransportResult<T.EsqlAsyncQueryGetResponse, unknown>> async asyncQueryGet (this: That, params: T.EsqlAsyncQueryGetRequest, options?: TransportRequestOptions): Promise<T.EsqlAsyncQueryGetResponse> async asyncQueryGet (this: That, params: T.EsqlAsyncQueryGetRequest, options?: TransportRequestOptions): Promise<any> { - const acceptedPath: string[] = ['id'] + const { + path: acceptedPath + } = this.acceptedParams['esql.async_query_get'] + const userQuery = params?.querystring const querystring: Record<string, any> = userQuery != null ? { ...userQuery } : {} @@ -179,7 +270,10 @@ export default class Esql { async asyncQueryStop (this: That, params: T.EsqlAsyncQueryStopRequest, options?: TransportRequestOptionsWithMeta): Promise<TransportResult<T.EsqlAsyncQueryStopResponse, unknown>> async asyncQueryStop (this: That, params: T.EsqlAsyncQueryStopRequest, options?: TransportRequestOptions): Promise<T.EsqlAsyncQueryStopResponse> async asyncQueryStop (this: That, params: T.EsqlAsyncQueryStopRequest, options?: TransportRequestOptions): Promise<any> { - const acceptedPath: string[] = ['id'] + const { + path: acceptedPath + } = this.acceptedParams['esql.async_query_stop'] + const userQuery = params?.querystring const querystring: Record<string, any> = userQuery != null ? { ...userQuery } : {} @@ -221,8 +315,12 @@ export default class Esql { async query (this: That, params: T.EsqlQueryRequest, options?: TransportRequestOptionsWithMeta): Promise<TransportResult<T.EsqlQueryResponse, unknown>> async query (this: That, params: T.EsqlQueryRequest, options?: TransportRequestOptions): Promise<T.EsqlQueryResponse> async query (this: That, params: T.EsqlQueryRequest, options?: TransportRequestOptions): Promise<any> { - const acceptedPath: string[] = [] - const acceptedBody: string[] = ['columnar', 'filter', 'locale', 'params', 'profile', 'query', 'tables', 'include_ccs_metadata'] + const { + path: acceptedPath, + body: acceptedBody, + query: acceptedQuery + } = this.acceptedParams['esql.query'] + const userQuery = params?.querystring const querystring: Record<string, any> = userQuery != null ? { ...userQuery } : {} @@ -244,8 +342,14 @@ export default class Esql { } else if (acceptedPath.includes(key)) { continue } else if (key !== 'body' && key !== 'querystring') { - // @ts-expect-error - querystring[key] = params[key] + if (acceptedQuery.includes(key) || commonQueryParams.includes(key)) { + // @ts-expect-error + querystring[key] = params[key] + } else { + body = body ?? {} + // @ts-expect-error + body[key] = params[key] + } } } diff --git a/src/api/api/exists.ts b/src/api/api/exists.ts index 0c5f99bde..50bb2b07f 100644 --- a/src/api/api/exists.ts +++ b/src/api/api/exists.ts @@ -35,7 +35,32 @@ import { TransportResult } from '@elastic/transport' import * as T from '../types' -interface That { transport: Transport } + +interface That { + transport: Transport +} + +const acceptedParams: Record<string, { path: string[], body: string[], query: string[] }> = { + exists: { + path: [ + 'id', + 'index' + ], + body: [], + query: [ + 'preference', + 'realtime', + 'refresh', + 'routing', + '_source', + '_source_excludes', + '_source_includes', + 'stored_fields', + 'version', + 'version_type' + ] + } +} /** * Check a document. Verify that a document exists. For example, check to see if a document with the `_id` 0 exists: ``` HEAD my-index-000001/_doc/0 ``` If the document exists, the API returns a status code of `200 - OK`. If the document doesn’t exist, the API returns `404 - Not Found`. **Versioning support** You can use the `version` parameter to check the document only if its current version is equal to the specified one. Internally, Elasticsearch has marked the old document as deleted and added an entirely new document. The old version of the document doesn't disappear immediately, although you won't be able to access it. Elasticsearch cleans up deleted documents in the background as you continue to index more data. @@ -45,7 +70,10 @@ export default async function ExistsApi (this: That, params: T.ExistsRequest, op export default async function ExistsApi (this: That, params: T.ExistsRequest, options?: TransportRequestOptionsWithMeta): Promise<TransportResult<T.ExistsResponse, unknown>> export default async function ExistsApi (this: That, params: T.ExistsRequest, options?: TransportRequestOptions): Promise<T.ExistsResponse> export default async function ExistsApi (this: That, params: T.ExistsRequest, options?: TransportRequestOptions): Promise<any> { - const acceptedPath: string[] = ['id', 'index'] + const { + path: acceptedPath + } = acceptedParams.exists + const userQuery = params?.querystring const querystring: Record<string, any> = userQuery != null ? { ...userQuery } : {} diff --git a/src/api/api/exists_source.ts b/src/api/api/exists_source.ts index 750302a6f..44009ea87 100644 --- a/src/api/api/exists_source.ts +++ b/src/api/api/exists_source.ts @@ -35,7 +35,31 @@ import { TransportResult } from '@elastic/transport' import * as T from '../types' -interface That { transport: Transport } + +interface That { + transport: Transport +} + +const acceptedParams: Record<string, { path: string[], body: string[], query: string[] }> = { + exists_source: { + path: [ + 'id', + 'index' + ], + body: [], + query: [ + 'preference', + 'realtime', + 'refresh', + 'routing', + '_source', + '_source_excludes', + '_source_includes', + 'version', + 'version_type' + ] + } +} /** * Check for a document source. Check whether a document source exists in an index. For example: ``` HEAD my-index-000001/_source/1 ``` A document's source is not available if it is disabled in the mapping. @@ -45,7 +69,10 @@ export default async function ExistsSourceApi (this: That, params: T.ExistsSourc export default async function ExistsSourceApi (this: That, params: T.ExistsSourceRequest, options?: TransportRequestOptionsWithMeta): Promise<TransportResult<T.ExistsSourceResponse, unknown>> export default async function ExistsSourceApi (this: That, params: T.ExistsSourceRequest, options?: TransportRequestOptions): Promise<T.ExistsSourceResponse> export default async function ExistsSourceApi (this: That, params: T.ExistsSourceRequest, options?: TransportRequestOptions): Promise<any> { - const acceptedPath: string[] = ['id', 'index'] + const { + path: acceptedPath + } = acceptedParams.exists_source + const userQuery = params?.querystring const querystring: Record<string, any> = userQuery != null ? { ...userQuery } : {} diff --git a/src/api/api/explain.ts b/src/api/api/explain.ts index 16150530b..727c5dcbe 100644 --- a/src/api/api/explain.ts +++ b/src/api/api/explain.ts @@ -35,7 +35,38 @@ import { TransportResult } from '@elastic/transport' import * as T from '../types' -interface That { transport: Transport } + +interface That { + transport: Transport +} + +const commonQueryParams = ['error_trace', 'filter_path', 'human', 'pretty'] + +const acceptedParams: Record<string, { path: string[], body: string[], query: string[] }> = { + explain: { + path: [ + 'id', + 'index' + ], + body: [ + 'query' + ], + query: [ + 'analyzer', + 'analyze_wildcard', + 'default_operator', + 'df', + 'lenient', + 'preference', + 'routing', + '_source', + '_source_excludes', + '_source_includes', + 'stored_fields', + 'q' + ] + } +} /** * Explain a document match result. Get information about why a specific document matches, or doesn't match, a query. It computes a score explanation for a query and a specific document. @@ -45,8 +76,12 @@ export default async function ExplainApi<TDocument = unknown> (this: That, param export default async function ExplainApi<TDocument = unknown> (this: That, params: T.ExplainRequest, options?: TransportRequestOptionsWithMeta): Promise<TransportResult<T.ExplainResponse<TDocument>, unknown>> export default async function ExplainApi<TDocument = unknown> (this: That, params: T.ExplainRequest, options?: TransportRequestOptions): Promise<T.ExplainResponse<TDocument>> export default async function ExplainApi<TDocument = unknown> (this: That, params: T.ExplainRequest, options?: TransportRequestOptions): Promise<any> { - const acceptedPath: string[] = ['id', 'index'] - const acceptedBody: string[] = ['query'] + const { + path: acceptedPath, + body: acceptedBody, + query: acceptedQuery + } = acceptedParams.explain + const userQuery = params?.querystring const querystring: Record<string, any> = userQuery != null ? { ...userQuery } : {} @@ -68,8 +103,14 @@ export default async function ExplainApi<TDocument = unknown> (this: That, param } else if (acceptedPath.includes(key)) { continue } else if (key !== 'body' && key !== 'querystring') { - // @ts-expect-error - querystring[key] = params[key] + if (acceptedQuery.includes(key) || commonQueryParams.includes(key)) { + // @ts-expect-error + querystring[key] = params[key] + } else { + body = body ?? {} + // @ts-expect-error + body[key] = params[key] + } } } diff --git a/src/api/api/features.ts b/src/api/api/features.ts index 670d84cda..ee12f298a 100644 --- a/src/api/api/features.ts +++ b/src/api/api/features.ts @@ -35,12 +35,33 @@ import { TransportResult } from '@elastic/transport' import * as T from '../types' -interface That { transport: Transport } + +interface That { + transport: Transport + acceptedParams: Record<string, { path: string[], body: string[], query: string[] }> +} export default class Features { transport: Transport + acceptedParams: Record<string, { path: string[], body: string[], query: string[] }> constructor (transport: Transport) { this.transport = transport + this.acceptedParams = { + 'features.get_features': { + path: [], + body: [], + query: [ + 'master_timeout' + ] + }, + 'features.reset_features': { + path: [], + body: [], + query: [ + 'master_timeout' + ] + } + } } /** @@ -51,7 +72,10 @@ export default class Features { async getFeatures (this: That, params?: T.FeaturesGetFeaturesRequest, options?: TransportRequestOptionsWithMeta): Promise<TransportResult<T.FeaturesGetFeaturesResponse, unknown>> async getFeatures (this: That, params?: T.FeaturesGetFeaturesRequest, options?: TransportRequestOptions): Promise<T.FeaturesGetFeaturesResponse> async getFeatures (this: That, params?: T.FeaturesGetFeaturesRequest, options?: TransportRequestOptions): Promise<any> { - const acceptedPath: string[] = [] + const { + path: acceptedPath + } = this.acceptedParams['features.get_features'] + const userQuery = params?.querystring const querystring: Record<string, any> = userQuery != null ? { ...userQuery } : {} @@ -91,7 +115,10 @@ export default class Features { async resetFeatures (this: That, params?: T.FeaturesResetFeaturesRequest, options?: TransportRequestOptionsWithMeta): Promise<TransportResult<T.FeaturesResetFeaturesResponse, unknown>> async resetFeatures (this: That, params?: T.FeaturesResetFeaturesRequest, options?: TransportRequestOptions): Promise<T.FeaturesResetFeaturesResponse> async resetFeatures (this: That, params?: T.FeaturesResetFeaturesRequest, options?: TransportRequestOptions): Promise<any> { - const acceptedPath: string[] = [] + const { + path: acceptedPath + } = this.acceptedParams['features.reset_features'] + const userQuery = params?.querystring const querystring: Record<string, any> = userQuery != null ? { ...userQuery } : {} diff --git a/src/api/api/field_caps.ts b/src/api/api/field_caps.ts index de9d61a0e..f863e52a3 100644 --- a/src/api/api/field_caps.ts +++ b/src/api/api/field_caps.ts @@ -35,7 +35,35 @@ import { TransportResult } from '@elastic/transport' import * as T from '../types' -interface That { transport: Transport } + +interface That { + transport: Transport +} + +const commonQueryParams = ['error_trace', 'filter_path', 'human', 'pretty'] + +const acceptedParams: Record<string, { path: string[], body: string[], query: string[] }> = { + field_caps: { + path: [ + 'index' + ], + body: [ + 'fields', + 'index_filter', + 'runtime_mappings' + ], + query: [ + 'allow_no_indices', + 'expand_wildcards', + 'fields', + 'ignore_unavailable', + 'include_unmapped', + 'filters', + 'types', + 'include_empty_fields' + ] + } +} /** * Get the field capabilities. Get information about the capabilities of fields among multiple indices. For data streams, the API returns field capabilities among the stream’s backing indices. It returns runtime fields like any other field. For example, a runtime field with a type of keyword is returned the same as any other field that belongs to the `keyword` family. @@ -45,8 +73,12 @@ export default async function FieldCapsApi (this: That, params?: T.FieldCapsRequ export default async function FieldCapsApi (this: That, params?: T.FieldCapsRequest, options?: TransportRequestOptionsWithMeta): Promise<TransportResult<T.FieldCapsResponse, unknown>> export default async function FieldCapsApi (this: That, params?: T.FieldCapsRequest, options?: TransportRequestOptions): Promise<T.FieldCapsResponse> export default async function FieldCapsApi (this: That, params?: T.FieldCapsRequest, options?: TransportRequestOptions): Promise<any> { - const acceptedPath: string[] = ['index'] - const acceptedBody: string[] = ['fields', 'index_filter', 'runtime_mappings'] + const { + path: acceptedPath, + body: acceptedBody, + query: acceptedQuery + } = acceptedParams.field_caps + const userQuery = params?.querystring const querystring: Record<string, any> = userQuery != null ? { ...userQuery } : {} @@ -69,8 +101,14 @@ export default async function FieldCapsApi (this: That, params?: T.FieldCapsRequ } else if (acceptedPath.includes(key)) { continue } else if (key !== 'body' && key !== 'querystring') { - // @ts-expect-error - querystring[key] = params[key] + if (acceptedQuery.includes(key) || commonQueryParams.includes(key)) { + // @ts-expect-error + querystring[key] = params[key] + } else { + body = body ?? {} + // @ts-expect-error + body[key] = params[key] + } } } diff --git a/src/api/api/fleet.ts b/src/api/api/fleet.ts index 042fcbfd1..d14151237 100644 --- a/src/api/api/fleet.ts +++ b/src/api/api/fleet.ts @@ -35,12 +35,159 @@ import { TransportResult } from '@elastic/transport' import * as T from '../types' -interface That { transport: Transport } + +interface That { + transport: Transport + acceptedParams: Record<string, { path: string[], body: string[], query: string[] }> +} + +const commonQueryParams = ['error_trace', 'filter_path', 'human', 'pretty'] export default class Fleet { transport: Transport + acceptedParams: Record<string, { path: string[], body: string[], query: string[] }> constructor (transport: Transport) { this.transport = transport + this.acceptedParams = { + 'fleet.delete_secret': { + path: [ + 'id' + ], + body: [], + query: [] + }, + 'fleet.get_secret': { + path: [ + 'id' + ], + body: [], + query: [] + }, + 'fleet.global_checkpoints': { + path: [ + 'index' + ], + body: [], + query: [ + 'wait_for_advance', + 'wait_for_index', + 'checkpoints', + 'timeout' + ] + }, + 'fleet.msearch': { + path: [ + 'index' + ], + body: [ + 'searches' + ], + query: [ + 'allow_no_indices', + 'ccs_minimize_roundtrips', + 'expand_wildcards', + 'ignore_throttled', + 'ignore_unavailable', + 'max_concurrent_searches', + 'max_concurrent_shard_requests', + 'pre_filter_shard_size', + 'search_type', + 'rest_total_hits_as_int', + 'typed_keys', + 'wait_for_checkpoints', + 'allow_partial_search_results' + ] + }, + 'fleet.post_secret': { + path: [], + body: [], + query: [] + }, + 'fleet.search': { + path: [ + 'index' + ], + body: [ + 'aggregations', + 'aggs', + 'collapse', + 'explain', + 'ext', + 'from', + 'highlight', + 'track_total_hits', + 'indices_boost', + 'docvalue_fields', + 'min_score', + 'post_filter', + 'profile', + 'query', + 'rescore', + 'script_fields', + 'search_after', + 'size', + 'slice', + 'sort', + '_source', + 'fields', + 'suggest', + 'terminate_after', + 'timeout', + 'track_scores', + 'version', + 'seq_no_primary_term', + 'stored_fields', + 'pit', + 'runtime_mappings', + 'stats' + ], + query: [ + 'allow_no_indices', + 'analyzer', + 'analyze_wildcard', + 'batched_reduce_size', + 'ccs_minimize_roundtrips', + 'default_operator', + 'df', + 'docvalue_fields', + 'expand_wildcards', + 'explain', + 'ignore_throttled', + 'ignore_unavailable', + 'lenient', + 'max_concurrent_shard_requests', + 'preference', + 'pre_filter_shard_size', + 'request_cache', + 'routing', + 'scroll', + 'search_type', + 'stats', + 'stored_fields', + 'suggest_field', + 'suggest_mode', + 'suggest_size', + 'suggest_text', + 'terminate_after', + 'timeout', + 'track_total_hits', + 'track_scores', + 'typed_keys', + 'rest_total_hits_as_int', + 'version', + '_source', + '_source_excludes', + '_source_includes', + 'seq_no_primary_term', + 'q', + 'size', + 'from', + 'sort', + 'wait_for_checkpoints', + 'allow_partial_search_results' + ] + } + } } /** @@ -50,7 +197,10 @@ export default class Fleet { async deleteSecret (this: That, params?: T.TODO, options?: TransportRequestOptionsWithMeta): Promise<TransportResult<T.TODO, unknown>> async deleteSecret (this: That, params?: T.TODO, options?: TransportRequestOptions): Promise<T.TODO> async deleteSecret (this: That, params?: T.TODO, options?: TransportRequestOptions): Promise<any> { - const acceptedPath: string[] = ['id'] + const { + path: acceptedPath + } = this.acceptedParams['fleet.delete_secret'] + const userQuery = params?.querystring const querystring: Record<string, any> = userQuery != null ? { ...userQuery } : {} @@ -91,7 +241,10 @@ export default class Fleet { async getSecret (this: That, params?: T.TODO, options?: TransportRequestOptionsWithMeta): Promise<TransportResult<T.TODO, unknown>> async getSecret (this: That, params?: T.TODO, options?: TransportRequestOptions): Promise<T.TODO> async getSecret (this: That, params?: T.TODO, options?: TransportRequestOptions): Promise<any> { - const acceptedPath: string[] = ['id'] + const { + path: acceptedPath + } = this.acceptedParams['fleet.get_secret'] + const userQuery = params?.querystring const querystring: Record<string, any> = userQuery != null ? { ...userQuery } : {} @@ -133,7 +286,10 @@ export default class Fleet { async globalCheckpoints (this: That, params: T.FleetGlobalCheckpointsRequest, options?: TransportRequestOptionsWithMeta): Promise<TransportResult<T.FleetGlobalCheckpointsResponse, unknown>> async globalCheckpoints (this: That, params: T.FleetGlobalCheckpointsRequest, options?: TransportRequestOptions): Promise<T.FleetGlobalCheckpointsResponse> async globalCheckpoints (this: That, params: T.FleetGlobalCheckpointsRequest, options?: TransportRequestOptions): Promise<any> { - const acceptedPath: string[] = ['index'] + const { + path: acceptedPath + } = this.acceptedParams['fleet.global_checkpoints'] + const userQuery = params?.querystring const querystring: Record<string, any> = userQuery != null ? { ...userQuery } : {} @@ -175,8 +331,12 @@ export default class Fleet { async msearch<TDocument = unknown> (this: That, params: T.FleetMsearchRequest, options?: TransportRequestOptionsWithMeta): Promise<TransportResult<T.FleetMsearchResponse<TDocument>, unknown>> async msearch<TDocument = unknown> (this: That, params: T.FleetMsearchRequest, options?: TransportRequestOptions): Promise<T.FleetMsearchResponse<TDocument>> async msearch<TDocument = unknown> (this: That, params: T.FleetMsearchRequest, options?: TransportRequestOptions): Promise<any> { - const acceptedPath: string[] = ['index'] - const acceptedBody: string[] = ['searches'] + const { + path: acceptedPath, + body: acceptedBody, + query: acceptedQuery + } = this.acceptedParams['fleet.msearch'] + const userQuery = params?.querystring const querystring: Record<string, any> = userQuery != null ? { ...userQuery } : {} @@ -188,8 +348,14 @@ export default class Fleet { } else if (acceptedPath.includes(key)) { continue } else if (key !== 'body' && key !== 'querystring') { - // @ts-expect-error - querystring[key] = params[key] + if (acceptedQuery.includes(key) || commonQueryParams.includes(key)) { + // @ts-expect-error + querystring[key] = params[key] + } else { + body = body ?? {} + // @ts-expect-error + body[key] = params[key] + } } } @@ -218,7 +384,10 @@ export default class Fleet { async postSecret (this: That, params?: T.TODO, options?: TransportRequestOptionsWithMeta): Promise<TransportResult<T.TODO, unknown>> async postSecret (this: That, params?: T.TODO, options?: TransportRequestOptions): Promise<T.TODO> async postSecret (this: That, params?: T.TODO, options?: TransportRequestOptions): Promise<any> { - const acceptedPath: string[] = [] + const { + path: acceptedPath + } = this.acceptedParams['fleet.post_secret'] + const userQuery = params?.querystring const querystring: Record<string, any> = userQuery != null ? { ...userQuery } : {} @@ -257,8 +426,12 @@ export default class Fleet { async search<TDocument = unknown> (this: That, params: T.FleetSearchRequest, options?: TransportRequestOptionsWithMeta): Promise<TransportResult<T.FleetSearchResponse<TDocument>, unknown>> async search<TDocument = unknown> (this: That, params: T.FleetSearchRequest, options?: TransportRequestOptions): Promise<T.FleetSearchResponse<TDocument>> async search<TDocument = unknown> (this: That, params: T.FleetSearchRequest, options?: TransportRequestOptions): Promise<any> { - const acceptedPath: string[] = ['index'] - const acceptedBody: string[] = ['aggregations', 'aggs', 'collapse', 'explain', 'ext', 'from', 'highlight', 'track_total_hits', 'indices_boost', 'docvalue_fields', 'min_score', 'post_filter', 'profile', 'query', 'rescore', 'script_fields', 'search_after', 'size', 'slice', 'sort', '_source', 'fields', 'suggest', 'terminate_after', 'timeout', 'track_scores', 'version', 'seq_no_primary_term', 'stored_fields', 'pit', 'runtime_mappings', 'stats'] + const { + path: acceptedPath, + body: acceptedBody, + query: acceptedQuery + } = this.acceptedParams['fleet.search'] + const userQuery = params?.querystring const querystring: Record<string, any> = userQuery != null ? { ...userQuery } : {} @@ -280,8 +453,14 @@ export default class Fleet { } else if (acceptedPath.includes(key)) { continue } else if (key !== 'body' && key !== 'querystring') { - // @ts-expect-error - querystring[key] = params[key] + if (acceptedQuery.includes(key) || commonQueryParams.includes(key)) { + // @ts-expect-error + querystring[key] = params[key] + } else { + body = body ?? {} + // @ts-expect-error + body[key] = params[key] + } } } diff --git a/src/api/api/get.ts b/src/api/api/get.ts index 3cb82914a..cb55c656b 100644 --- a/src/api/api/get.ts +++ b/src/api/api/get.ts @@ -35,7 +35,33 @@ import { TransportResult } from '@elastic/transport' import * as T from '../types' -interface That { transport: Transport } + +interface That { + transport: Transport +} + +const acceptedParams: Record<string, { path: string[], body: string[], query: string[] }> = { + get: { + path: [ + 'id', + 'index' + ], + body: [], + query: [ + 'force_synthetic_source', + 'preference', + 'realtime', + 'refresh', + 'routing', + '_source', + '_source_excludes', + '_source_includes', + 'stored_fields', + 'version', + 'version_type' + ] + } +} /** * Get a document by its ID. Get a document and its source or stored fields from an index. By default, this API is realtime and is not affected by the refresh rate of the index (when data will become visible for search). In the case where stored fields are requested with the `stored_fields` parameter and the document has been updated but is not yet refreshed, the API will have to parse and analyze the source to extract the stored fields. To turn off realtime behavior, set the `realtime` parameter to false. **Source filtering** By default, the API returns the contents of the `_source` field unless you have used the `stored_fields` parameter or the `_source` field is turned off. You can turn off `_source` retrieval by using the `_source` parameter: ``` GET my-index-000001/_doc/0?_source=false ``` If you only need one or two fields from the `_source`, use the `_source_includes` or `_source_excludes` parameters to include or filter out particular fields. This can be helpful with large documents where partial retrieval can save on network overhead Both parameters take a comma separated list of fields or wildcard expressions. For example: ``` GET my-index-000001/_doc/0?_source_includes=*.id&_source_excludes=entities ``` If you only want to specify includes, you can use a shorter notation: ``` GET my-index-000001/_doc/0?_source=*.id ``` **Routing** If routing is used during indexing, the routing value also needs to be specified to retrieve a document. For example: ``` GET my-index-000001/_doc/2?routing=user1 ``` This request gets the document with ID 2, but it is routed based on the user. The document is not fetched if the correct routing is not specified. **Distributed** The GET operation is hashed into a specific shard ID. It is then redirected to one of the replicas within that shard ID and returns the result. The replicas are the primary shard and its replicas within that shard ID group. This means that the more replicas you have, the better your GET scaling will be. **Versioning support** You can use the `version` parameter to retrieve the document only if its current version is equal to the specified one. Internally, Elasticsearch has marked the old document as deleted and added an entirely new document. The old version of the document doesn't disappear immediately, although you won't be able to access it. Elasticsearch cleans up deleted documents in the background as you continue to index more data. @@ -45,7 +71,10 @@ export default async function GetApi<TDocument = unknown> (this: That, params: T export default async function GetApi<TDocument = unknown> (this: That, params: T.GetRequest, options?: TransportRequestOptionsWithMeta): Promise<TransportResult<T.GetResponse<TDocument>, unknown>> export default async function GetApi<TDocument = unknown> (this: That, params: T.GetRequest, options?: TransportRequestOptions): Promise<T.GetResponse<TDocument>> export default async function GetApi<TDocument = unknown> (this: That, params: T.GetRequest, options?: TransportRequestOptions): Promise<any> { - const acceptedPath: string[] = ['id', 'index'] + const { + path: acceptedPath + } = acceptedParams.get + const userQuery = params?.querystring const querystring: Record<string, any> = userQuery != null ? { ...userQuery } : {} diff --git a/src/api/api/get_script.ts b/src/api/api/get_script.ts index d079ba650..694f144a6 100644 --- a/src/api/api/get_script.ts +++ b/src/api/api/get_script.ts @@ -35,7 +35,22 @@ import { TransportResult } from '@elastic/transport' import * as T from '../types' -interface That { transport: Transport } + +interface That { + transport: Transport +} + +const acceptedParams: Record<string, { path: string[], body: string[], query: string[] }> = { + get_script: { + path: [ + 'id' + ], + body: [], + query: [ + 'master_timeout' + ] + } +} /** * Get a script or search template. Retrieves a stored script or search template. @@ -45,7 +60,10 @@ export default async function GetScriptApi (this: That, params: T.GetScriptReque export default async function GetScriptApi (this: That, params: T.GetScriptRequest, options?: TransportRequestOptionsWithMeta): Promise<TransportResult<T.GetScriptResponse, unknown>> export default async function GetScriptApi (this: That, params: T.GetScriptRequest, options?: TransportRequestOptions): Promise<T.GetScriptResponse> export default async function GetScriptApi (this: That, params: T.GetScriptRequest, options?: TransportRequestOptions): Promise<any> { - const acceptedPath: string[] = ['id'] + const { + path: acceptedPath + } = acceptedParams.get_script + const userQuery = params?.querystring const querystring: Record<string, any> = userQuery != null ? { ...userQuery } : {} diff --git a/src/api/api/get_script_context.ts b/src/api/api/get_script_context.ts index b263ed089..a33514bbf 100644 --- a/src/api/api/get_script_context.ts +++ b/src/api/api/get_script_context.ts @@ -35,7 +35,18 @@ import { TransportResult } from '@elastic/transport' import * as T from '../types' -interface That { transport: Transport } + +interface That { + transport: Transport +} + +const acceptedParams: Record<string, { path: string[], body: string[], query: string[] }> = { + get_script_context: { + path: [], + body: [], + query: [] + } +} /** * Get script contexts. Get a list of supported script contexts and their methods. @@ -45,7 +56,10 @@ export default async function GetScriptContextApi (this: That, params?: T.GetScr export default async function GetScriptContextApi (this: That, params?: T.GetScriptContextRequest, options?: TransportRequestOptionsWithMeta): Promise<TransportResult<T.GetScriptContextResponse, unknown>> export default async function GetScriptContextApi (this: That, params?: T.GetScriptContextRequest, options?: TransportRequestOptions): Promise<T.GetScriptContextResponse> export default async function GetScriptContextApi (this: That, params?: T.GetScriptContextRequest, options?: TransportRequestOptions): Promise<any> { - const acceptedPath: string[] = [] + const { + path: acceptedPath + } = acceptedParams.get_script_context + const userQuery = params?.querystring const querystring: Record<string, any> = userQuery != null ? { ...userQuery } : {} diff --git a/src/api/api/get_script_languages.ts b/src/api/api/get_script_languages.ts index 7b52735c4..f8e7f14f5 100644 --- a/src/api/api/get_script_languages.ts +++ b/src/api/api/get_script_languages.ts @@ -35,7 +35,18 @@ import { TransportResult } from '@elastic/transport' import * as T from '../types' -interface That { transport: Transport } + +interface That { + transport: Transport +} + +const acceptedParams: Record<string, { path: string[], body: string[], query: string[] }> = { + get_script_languages: { + path: [], + body: [], + query: [] + } +} /** * Get script languages. Get a list of available script types, languages, and contexts. @@ -45,7 +56,10 @@ export default async function GetScriptLanguagesApi (this: That, params?: T.GetS export default async function GetScriptLanguagesApi (this: That, params?: T.GetScriptLanguagesRequest, options?: TransportRequestOptionsWithMeta): Promise<TransportResult<T.GetScriptLanguagesResponse, unknown>> export default async function GetScriptLanguagesApi (this: That, params?: T.GetScriptLanguagesRequest, options?: TransportRequestOptions): Promise<T.GetScriptLanguagesResponse> export default async function GetScriptLanguagesApi (this: That, params?: T.GetScriptLanguagesRequest, options?: TransportRequestOptions): Promise<any> { - const acceptedPath: string[] = [] + const { + path: acceptedPath + } = acceptedParams.get_script_languages + const userQuery = params?.querystring const querystring: Record<string, any> = userQuery != null ? { ...userQuery } : {} diff --git a/src/api/api/get_source.ts b/src/api/api/get_source.ts index a4eef8c97..b9c7191b5 100644 --- a/src/api/api/get_source.ts +++ b/src/api/api/get_source.ts @@ -35,7 +35,32 @@ import { TransportResult } from '@elastic/transport' import * as T from '../types' -interface That { transport: Transport } + +interface That { + transport: Transport +} + +const acceptedParams: Record<string, { path: string[], body: string[], query: string[] }> = { + get_source: { + path: [ + 'id', + 'index' + ], + body: [], + query: [ + 'preference', + 'realtime', + 'refresh', + 'routing', + '_source', + '_source_excludes', + '_source_includes', + 'stored_fields', + 'version', + 'version_type' + ] + } +} /** * Get a document's source. Get the source of a document. For example: ``` GET my-index-000001/_source/1 ``` You can use the source filtering parameters to control which parts of the `_source` are returned: ``` GET my-index-000001/_source/1/?_source_includes=*.id&_source_excludes=entities ``` @@ -45,7 +70,10 @@ export default async function GetSourceApi<TDocument = unknown> (this: That, par export default async function GetSourceApi<TDocument = unknown> (this: That, params: T.GetSourceRequest, options?: TransportRequestOptionsWithMeta): Promise<TransportResult<T.GetSourceResponse<TDocument>, unknown>> export default async function GetSourceApi<TDocument = unknown> (this: That, params: T.GetSourceRequest, options?: TransportRequestOptions): Promise<T.GetSourceResponse<TDocument>> export default async function GetSourceApi<TDocument = unknown> (this: That, params: T.GetSourceRequest, options?: TransportRequestOptions): Promise<any> { - const acceptedPath: string[] = ['id', 'index'] + const { + path: acceptedPath + } = acceptedParams.get_source + const userQuery = params?.querystring const querystring: Record<string, any> = userQuery != null ? { ...userQuery } : {} diff --git a/src/api/api/graph.ts b/src/api/api/graph.ts index 33534fe4a..a509820dd 100644 --- a/src/api/api/graph.ts +++ b/src/api/api/graph.ts @@ -35,12 +35,36 @@ import { TransportResult } from '@elastic/transport' import * as T from '../types' -interface That { transport: Transport } + +interface That { + transport: Transport + acceptedParams: Record<string, { path: string[], body: string[], query: string[] }> +} + +const commonQueryParams = ['error_trace', 'filter_path', 'human', 'pretty'] export default class Graph { transport: Transport + acceptedParams: Record<string, { path: string[], body: string[], query: string[] }> constructor (transport: Transport) { this.transport = transport + this.acceptedParams = { + 'graph.explore': { + path: [ + 'index' + ], + body: [ + 'connections', + 'controls', + 'query', + 'vertices' + ], + query: [ + 'routing', + 'timeout' + ] + } + } } /** @@ -51,8 +75,12 @@ export default class Graph { async explore (this: That, params: T.GraphExploreRequest, options?: TransportRequestOptionsWithMeta): Promise<TransportResult<T.GraphExploreResponse, unknown>> async explore (this: That, params: T.GraphExploreRequest, options?: TransportRequestOptions): Promise<T.GraphExploreResponse> async explore (this: That, params: T.GraphExploreRequest, options?: TransportRequestOptions): Promise<any> { - const acceptedPath: string[] = ['index'] - const acceptedBody: string[] = ['connections', 'controls', 'query', 'vertices'] + const { + path: acceptedPath, + body: acceptedBody, + query: acceptedQuery + } = this.acceptedParams['graph.explore'] + const userQuery = params?.querystring const querystring: Record<string, any> = userQuery != null ? { ...userQuery } : {} @@ -74,8 +102,14 @@ export default class Graph { } else if (acceptedPath.includes(key)) { continue } else if (key !== 'body' && key !== 'querystring') { - // @ts-expect-error - querystring[key] = params[key] + if (acceptedQuery.includes(key) || commonQueryParams.includes(key)) { + // @ts-expect-error + querystring[key] = params[key] + } else { + body = body ?? {} + // @ts-expect-error + body[key] = params[key] + } } } diff --git a/src/api/api/health_report.ts b/src/api/api/health_report.ts index 51a48a265..8a7539b04 100644 --- a/src/api/api/health_report.ts +++ b/src/api/api/health_report.ts @@ -35,7 +35,24 @@ import { TransportResult } from '@elastic/transport' import * as T from '../types' -interface That { transport: Transport } + +interface That { + transport: Transport +} + +const acceptedParams: Record<string, { path: string[], body: string[], query: string[] }> = { + health_report: { + path: [ + 'feature' + ], + body: [], + query: [ + 'timeout', + 'verbose', + 'size' + ] + } +} /** * Get the cluster health. Get a report with the health status of an Elasticsearch cluster. The report contains a list of indicators that compose Elasticsearch functionality. Each indicator has a health status of: green, unknown, yellow or red. The indicator will provide an explanation and metadata describing the reason for its current health status. The cluster’s status is controlled by the worst indicator status. In the event that an indicator’s status is non-green, a list of impacts may be present in the indicator result which detail the functionalities that are negatively affected by the health issue. Each impact carries with it a severity level, an area of the system that is affected, and a simple description of the impact on the system. Some health indicators can determine the root cause of a health problem and prescribe a set of steps that can be performed in order to improve the health of the system. The root cause and remediation steps are encapsulated in a diagnosis. A diagnosis contains a cause detailing a root cause analysis, an action containing a brief description of the steps to take to fix the problem, the list of affected resources (if applicable), and a detailed step-by-step troubleshooting guide to fix the diagnosed problem. NOTE: The health indicators perform root cause analysis of non-green health statuses. This can be computationally expensive when called frequently. When setting up automated polling of the API for health status, set verbose to false to disable the more expensive analysis logic. @@ -45,7 +62,10 @@ export default async function HealthReportApi (this: That, params?: T.HealthRepo export default async function HealthReportApi (this: That, params?: T.HealthReportRequest, options?: TransportRequestOptionsWithMeta): Promise<TransportResult<T.HealthReportResponse, unknown>> export default async function HealthReportApi (this: That, params?: T.HealthReportRequest, options?: TransportRequestOptions): Promise<T.HealthReportResponse> export default async function HealthReportApi (this: That, params?: T.HealthReportRequest, options?: TransportRequestOptions): Promise<any> { - const acceptedPath: string[] = ['feature'] + const { + path: acceptedPath + } = acceptedParams.health_report + const userQuery = params?.querystring const querystring: Record<string, any> = userQuery != null ? { ...userQuery } : {} diff --git a/src/api/api/ilm.ts b/src/api/api/ilm.ts index 1c097071c..dd4537454 100644 --- a/src/api/api/ilm.ts +++ b/src/api/api/ilm.ts @@ -35,12 +35,120 @@ import { TransportResult } from '@elastic/transport' import * as T from '../types' -interface That { transport: Transport } + +interface That { + transport: Transport + acceptedParams: Record<string, { path: string[], body: string[], query: string[] }> +} + +const commonQueryParams = ['error_trace', 'filter_path', 'human', 'pretty'] export default class Ilm { transport: Transport + acceptedParams: Record<string, { path: string[], body: string[], query: string[] }> constructor (transport: Transport) { this.transport = transport + this.acceptedParams = { + 'ilm.delete_lifecycle': { + path: [ + 'name' + ], + body: [], + query: [ + 'master_timeout', + 'timeout' + ] + }, + 'ilm.explain_lifecycle': { + path: [ + 'index' + ], + body: [], + query: [ + 'only_errors', + 'only_managed', + 'master_timeout' + ] + }, + 'ilm.get_lifecycle': { + path: [ + 'name' + ], + body: [], + query: [ + 'master_timeout', + 'timeout' + ] + }, + 'ilm.get_status': { + path: [], + body: [], + query: [] + }, + 'ilm.migrate_to_data_tiers': { + path: [], + body: [ + 'legacy_template_to_delete', + 'node_attribute' + ], + query: [ + 'dry_run', + 'master_timeout' + ] + }, + 'ilm.move_to_step': { + path: [ + 'index' + ], + body: [ + 'current_step', + 'next_step' + ], + query: [] + }, + 'ilm.put_lifecycle': { + path: [ + 'name' + ], + body: [ + 'policy' + ], + query: [ + 'master_timeout', + 'timeout' + ] + }, + 'ilm.remove_policy': { + path: [ + 'index' + ], + body: [], + query: [] + }, + 'ilm.retry': { + path: [ + 'index' + ], + body: [], + query: [] + }, + 'ilm.start': { + path: [], + body: [], + query: [ + 'master_timeout', + 'timeout' + ] + }, + 'ilm.stop': { + path: [], + body: [], + query: [ + 'master_timeout', + 'timeout' + ] + } + } } /** @@ -51,7 +159,10 @@ export default class Ilm { async deleteLifecycle (this: That, params: T.IlmDeleteLifecycleRequest, options?: TransportRequestOptionsWithMeta): Promise<TransportResult<T.IlmDeleteLifecycleResponse, unknown>> async deleteLifecycle (this: That, params: T.IlmDeleteLifecycleRequest, options?: TransportRequestOptions): Promise<T.IlmDeleteLifecycleResponse> async deleteLifecycle (this: That, params: T.IlmDeleteLifecycleRequest, options?: TransportRequestOptions): Promise<any> { - const acceptedPath: string[] = ['name'] + const { + path: acceptedPath + } = this.acceptedParams['ilm.delete_lifecycle'] + const userQuery = params?.querystring const querystring: Record<string, any> = userQuery != null ? { ...userQuery } : {} @@ -93,7 +204,10 @@ export default class Ilm { async explainLifecycle (this: That, params: T.IlmExplainLifecycleRequest, options?: TransportRequestOptionsWithMeta): Promise<TransportResult<T.IlmExplainLifecycleResponse, unknown>> async explainLifecycle (this: That, params: T.IlmExplainLifecycleRequest, options?: TransportRequestOptions): Promise<T.IlmExplainLifecycleResponse> async explainLifecycle (this: That, params: T.IlmExplainLifecycleRequest, options?: TransportRequestOptions): Promise<any> { - const acceptedPath: string[] = ['index'] + const { + path: acceptedPath + } = this.acceptedParams['ilm.explain_lifecycle'] + const userQuery = params?.querystring const querystring: Record<string, any> = userQuery != null ? { ...userQuery } : {} @@ -135,7 +249,10 @@ export default class Ilm { async getLifecycle (this: That, params?: T.IlmGetLifecycleRequest, options?: TransportRequestOptionsWithMeta): Promise<TransportResult<T.IlmGetLifecycleResponse, unknown>> async getLifecycle (this: That, params?: T.IlmGetLifecycleRequest, options?: TransportRequestOptions): Promise<T.IlmGetLifecycleResponse> async getLifecycle (this: That, params?: T.IlmGetLifecycleRequest, options?: TransportRequestOptions): Promise<any> { - const acceptedPath: string[] = ['name'] + const { + path: acceptedPath + } = this.acceptedParams['ilm.get_lifecycle'] + const userQuery = params?.querystring const querystring: Record<string, any> = userQuery != null ? { ...userQuery } : {} @@ -185,7 +302,10 @@ export default class Ilm { async getStatus (this: That, params?: T.IlmGetStatusRequest, options?: TransportRequestOptionsWithMeta): Promise<TransportResult<T.IlmGetStatusResponse, unknown>> async getStatus (this: That, params?: T.IlmGetStatusRequest, options?: TransportRequestOptions): Promise<T.IlmGetStatusResponse> async getStatus (this: That, params?: T.IlmGetStatusRequest, options?: TransportRequestOptions): Promise<any> { - const acceptedPath: string[] = [] + const { + path: acceptedPath + } = this.acceptedParams['ilm.get_status'] + const userQuery = params?.querystring const querystring: Record<string, any> = userQuery != null ? { ...userQuery } : {} @@ -225,8 +345,12 @@ export default class Ilm { async migrateToDataTiers (this: That, params?: T.IlmMigrateToDataTiersRequest, options?: TransportRequestOptionsWithMeta): Promise<TransportResult<T.IlmMigrateToDataTiersResponse, unknown>> async migrateToDataTiers (this: That, params?: T.IlmMigrateToDataTiersRequest, options?: TransportRequestOptions): Promise<T.IlmMigrateToDataTiersResponse> async migrateToDataTiers (this: That, params?: T.IlmMigrateToDataTiersRequest, options?: TransportRequestOptions): Promise<any> { - const acceptedPath: string[] = [] - const acceptedBody: string[] = ['legacy_template_to_delete', 'node_attribute'] + const { + path: acceptedPath, + body: acceptedBody, + query: acceptedQuery + } = this.acceptedParams['ilm.migrate_to_data_tiers'] + const userQuery = params?.querystring const querystring: Record<string, any> = userQuery != null ? { ...userQuery } : {} @@ -249,8 +373,14 @@ export default class Ilm { } else if (acceptedPath.includes(key)) { continue } else if (key !== 'body' && key !== 'querystring') { - // @ts-expect-error - querystring[key] = params[key] + if (acceptedQuery.includes(key) || commonQueryParams.includes(key)) { + // @ts-expect-error + querystring[key] = params[key] + } else { + body = body ?? {} + // @ts-expect-error + body[key] = params[key] + } } } @@ -270,8 +400,12 @@ export default class Ilm { async moveToStep (this: That, params: T.IlmMoveToStepRequest, options?: TransportRequestOptionsWithMeta): Promise<TransportResult<T.IlmMoveToStepResponse, unknown>> async moveToStep (this: That, params: T.IlmMoveToStepRequest, options?: TransportRequestOptions): Promise<T.IlmMoveToStepResponse> async moveToStep (this: That, params: T.IlmMoveToStepRequest, options?: TransportRequestOptions): Promise<any> { - const acceptedPath: string[] = ['index'] - const acceptedBody: string[] = ['current_step', 'next_step'] + const { + path: acceptedPath, + body: acceptedBody, + query: acceptedQuery + } = this.acceptedParams['ilm.move_to_step'] + const userQuery = params?.querystring const querystring: Record<string, any> = userQuery != null ? { ...userQuery } : {} @@ -293,8 +427,14 @@ export default class Ilm { } else if (acceptedPath.includes(key)) { continue } else if (key !== 'body' && key !== 'querystring') { - // @ts-expect-error - querystring[key] = params[key] + if (acceptedQuery.includes(key) || commonQueryParams.includes(key)) { + // @ts-expect-error + querystring[key] = params[key] + } else { + body = body ?? {} + // @ts-expect-error + body[key] = params[key] + } } } @@ -317,8 +457,12 @@ export default class Ilm { async putLifecycle (this: That, params: T.IlmPutLifecycleRequest, options?: TransportRequestOptionsWithMeta): Promise<TransportResult<T.IlmPutLifecycleResponse, unknown>> async putLifecycle (this: That, params: T.IlmPutLifecycleRequest, options?: TransportRequestOptions): Promise<T.IlmPutLifecycleResponse> async putLifecycle (this: That, params: T.IlmPutLifecycleRequest, options?: TransportRequestOptions): Promise<any> { - const acceptedPath: string[] = ['name'] - const acceptedBody: string[] = ['policy'] + const { + path: acceptedPath, + body: acceptedBody, + query: acceptedQuery + } = this.acceptedParams['ilm.put_lifecycle'] + const userQuery = params?.querystring const querystring: Record<string, any> = userQuery != null ? { ...userQuery } : {} @@ -340,8 +484,14 @@ export default class Ilm { } else if (acceptedPath.includes(key)) { continue } else if (key !== 'body' && key !== 'querystring') { - // @ts-expect-error - querystring[key] = params[key] + if (acceptedQuery.includes(key) || commonQueryParams.includes(key)) { + // @ts-expect-error + querystring[key] = params[key] + } else { + body = body ?? {} + // @ts-expect-error + body[key] = params[key] + } } } @@ -364,7 +514,10 @@ export default class Ilm { async removePolicy (this: That, params: T.IlmRemovePolicyRequest, options?: TransportRequestOptionsWithMeta): Promise<TransportResult<T.IlmRemovePolicyResponse, unknown>> async removePolicy (this: That, params: T.IlmRemovePolicyRequest, options?: TransportRequestOptions): Promise<T.IlmRemovePolicyResponse> async removePolicy (this: That, params: T.IlmRemovePolicyRequest, options?: TransportRequestOptions): Promise<any> { - const acceptedPath: string[] = ['index'] + const { + path: acceptedPath + } = this.acceptedParams['ilm.remove_policy'] + const userQuery = params?.querystring const querystring: Record<string, any> = userQuery != null ? { ...userQuery } : {} @@ -406,7 +559,10 @@ export default class Ilm { async retry (this: That, params: T.IlmRetryRequest, options?: TransportRequestOptionsWithMeta): Promise<TransportResult<T.IlmRetryResponse, unknown>> async retry (this: That, params: T.IlmRetryRequest, options?: TransportRequestOptions): Promise<T.IlmRetryResponse> async retry (this: That, params: T.IlmRetryRequest, options?: TransportRequestOptions): Promise<any> { - const acceptedPath: string[] = ['index'] + const { + path: acceptedPath + } = this.acceptedParams['ilm.retry'] + const userQuery = params?.querystring const querystring: Record<string, any> = userQuery != null ? { ...userQuery } : {} @@ -448,7 +604,10 @@ export default class Ilm { async start (this: That, params?: T.IlmStartRequest, options?: TransportRequestOptionsWithMeta): Promise<TransportResult<T.IlmStartResponse, unknown>> async start (this: That, params?: T.IlmStartRequest, options?: TransportRequestOptions): Promise<T.IlmStartResponse> async start (this: That, params?: T.IlmStartRequest, options?: TransportRequestOptions): Promise<any> { - const acceptedPath: string[] = [] + const { + path: acceptedPath + } = this.acceptedParams['ilm.start'] + const userQuery = params?.querystring const querystring: Record<string, any> = userQuery != null ? { ...userQuery } : {} @@ -488,7 +647,10 @@ export default class Ilm { async stop (this: That, params?: T.IlmStopRequest, options?: TransportRequestOptionsWithMeta): Promise<TransportResult<T.IlmStopResponse, unknown>> async stop (this: That, params?: T.IlmStopRequest, options?: TransportRequestOptions): Promise<T.IlmStopResponse> async stop (this: That, params?: T.IlmStopRequest, options?: TransportRequestOptions): Promise<any> { - const acceptedPath: string[] = [] + const { + path: acceptedPath + } = this.acceptedParams['ilm.stop'] + const userQuery = params?.querystring const querystring: Record<string, any> = userQuery != null ? { ...userQuery } : {} diff --git a/src/api/api/index.ts b/src/api/api/index.ts index bcd3842eb..20adfbc81 100644 --- a/src/api/api/index.ts +++ b/src/api/api/index.ts @@ -35,7 +35,38 @@ import { TransportResult } from '@elastic/transport' import * as T from '../types' -interface That { transport: Transport } + +interface That { + transport: Transport +} + +const commonQueryParams = ['error_trace', 'filter_path', 'human', 'pretty'] + +const acceptedParams: Record<string, { path: string[], body: string[], query: string[] }> = { + index: { + path: [ + 'id', + 'index' + ], + body: [ + 'document' + ], + query: [ + 'if_primary_term', + 'if_seq_no', + 'include_source_on_error', + 'op_type', + 'pipeline', + 'refresh', + 'routing', + 'timeout', + 'version', + 'version_type', + 'wait_for_active_shards', + 'require_alias' + ] + } +} /** * Create or update a document in an index. Add a JSON document to the specified data stream or index and make it searchable. If the target is an index and the document already exists, the request updates the document and increments its version. NOTE: You cannot use this API to send update requests for existing documents in a data stream. If the Elasticsearch security features are enabled, you must have the following index privileges for the target data stream, index, or index alias: * To add or overwrite a document using the `PUT /<target>/_doc/<_id>` request format, you must have the `create`, `index`, or `write` index privilege. * To add a document using the `POST /<target>/_doc/` request format, you must have the `create_doc`, `create`, `index`, or `write` index privilege. * To automatically create a data stream or index with this API request, you must have the `auto_configure`, `create_index`, or `manage` index privilege. Automatic data stream creation requires a matching index template with data stream enabled. NOTE: Replica shards might not all be started when an indexing operation returns successfully. By default, only the primary is required. Set `wait_for_active_shards` to change this default behavior. **Automatically create data streams and indices** If the request's target doesn't exist and matches an index template with a `data_stream` definition, the index operation automatically creates the data stream. If the target doesn't exist and doesn't match a data stream template, the operation automatically creates the index and applies any matching index templates. NOTE: Elasticsearch includes several built-in index templates. To avoid naming collisions with these templates, refer to index pattern documentation. If no mapping exists, the index operation creates a dynamic mapping. By default, new fields and objects are automatically added to the mapping if needed. Automatic index creation is controlled by the `action.auto_create_index` setting. If it is `true`, any index can be created automatically. You can modify this setting to explicitly allow or block automatic creation of indices that match specified patterns or set it to `false` to turn off automatic index creation entirely. Specify a comma-separated list of patterns you want to allow or prefix each pattern with `+` or `-` to indicate whether it should be allowed or blocked. When a list is specified, the default behaviour is to disallow. NOTE: The `action.auto_create_index` setting affects the automatic creation of indices only. It does not affect the creation of data streams. **Optimistic concurrency control** Index operations can be made conditional and only be performed if the last modification to the document was assigned the sequence number and primary term specified by the `if_seq_no` and `if_primary_term` parameters. If a mismatch is detected, the operation will result in a `VersionConflictException` and a status code of `409`. **Routing** By default, shard placement — or routing — is controlled by using a hash of the document's ID value. For more explicit control, the value fed into the hash function used by the router can be directly specified on a per-operation basis using the `routing` parameter. When setting up explicit mapping, you can also use the `_routing` field to direct the index operation to extract the routing value from the document itself. This does come at the (very minimal) cost of an additional document parsing pass. If the `_routing` mapping is defined and set to be required, the index operation will fail if no routing value is provided or extracted. NOTE: Data streams do not support custom routing unless they were created with the `allow_custom_routing` setting enabled in the template. **Distributed** The index operation is directed to the primary shard based on its route and performed on the actual node containing this shard. After the primary shard completes the operation, if needed, the update is distributed to applicable replicas. **Active shards** To improve the resiliency of writes to the system, indexing operations can be configured to wait for a certain number of active shard copies before proceeding with the operation. If the requisite number of active shard copies are not available, then the write operation must wait and retry, until either the requisite shard copies have started or a timeout occurs. By default, write operations only wait for the primary shards to be active before proceeding (that is to say `wait_for_active_shards` is `1`). This default can be overridden in the index settings dynamically by setting `index.write.wait_for_active_shards`. To alter this behavior per operation, use the `wait_for_active_shards request` parameter. Valid values are all or any positive integer up to the total number of configured copies per shard in the index (which is `number_of_replicas`+1). Specifying a negative value or a number greater than the number of shard copies will throw an error. For example, suppose you have a cluster of three nodes, A, B, and C and you create an index index with the number of replicas set to 3 (resulting in 4 shard copies, one more copy than there are nodes). If you attempt an indexing operation, by default the operation will only ensure the primary copy of each shard is available before proceeding. This means that even if B and C went down and A hosted the primary shard copies, the indexing operation would still proceed with only one copy of the data. If `wait_for_active_shards` is set on the request to `3` (and all three nodes are up), the indexing operation will require 3 active shard copies before proceeding. This requirement should be met because there are 3 active nodes in the cluster, each one holding a copy of the shard. However, if you set `wait_for_active_shards` to `all` (or to `4`, which is the same in this situation), the indexing operation will not proceed as you do not have all 4 copies of each shard active in the index. The operation will timeout unless a new node is brought up in the cluster to host the fourth copy of the shard. It is important to note that this setting greatly reduces the chances of the write operation not writing to the requisite number of shard copies, but it does not completely eliminate the possibility, because this check occurs before the write operation starts. After the write operation is underway, it is still possible for replication to fail on any number of shard copies but still succeed on the primary. The `_shards` section of the API response reveals the number of shard copies on which replication succeeded and failed. **No operation (noop) updates** When updating a document by using this API, a new version of the document is always created even if the document hasn't changed. If this isn't acceptable use the `_update` API with `detect_noop` set to `true`. The `detect_noop` option isn't available on this API because it doesn’t fetch the old source and isn't able to compare it against the new source. There isn't a definitive rule for when noop updates aren't acceptable. It's a combination of lots of factors like how frequently your data source sends updates that are actually noops and how many queries per second Elasticsearch runs on the shard receiving the updates. **Versioning** Each indexed document is given a version number. By default, internal versioning is used that starts at 1 and increments with each update, deletes included. Optionally, the version number can be set to an external value (for example, if maintained in a database). To enable this functionality, `version_type` should be set to `external`. The value provided must be a numeric, long value greater than or equal to 0, and less than around `9.2e+18`. NOTE: Versioning is completely real time, and is not affected by the near real time aspects of search operations. If no version is provided, the operation runs without any version checks. When using the external version type, the system checks to see if the version number passed to the index request is greater than the version of the currently stored document. If true, the document will be indexed and the new version number used. If the value provided is less than or equal to the stored document's version number, a version conflict will occur and the index operation will fail. For example: ``` PUT my-index-000001/_doc/1?version=2&version_type=external { "user": { "id": "elkbee" } } In this example, the operation will succeed since the supplied version of 2 is higher than the current document version of 1. If the document was already updated and its version was set to 2 or higher, the indexing command will fail and result in a conflict (409 HTTP status code). A nice side effect is that there is no need to maintain strict ordering of async indexing operations run as a result of changes to a source database, as long as version numbers from the source database are used. Even the simple case of updating the Elasticsearch index using data from a database is simplified if external versioning is used, as only the latest version will be used if the index operations arrive out of order. @@ -45,8 +76,12 @@ export default async function IndexApi<TDocument = unknown> (this: That, params: export default async function IndexApi<TDocument = unknown> (this: That, params: T.IndexRequest<TDocument>, options?: TransportRequestOptionsWithMeta): Promise<TransportResult<T.IndexResponse, unknown>> export default async function IndexApi<TDocument = unknown> (this: That, params: T.IndexRequest<TDocument>, options?: TransportRequestOptions): Promise<T.IndexResponse> export default async function IndexApi<TDocument = unknown> (this: That, params: T.IndexRequest<TDocument>, options?: TransportRequestOptions): Promise<any> { - const acceptedPath: string[] = ['id', 'index'] - const acceptedBody: string[] = ['document'] + const { + path: acceptedPath, + body: acceptedBody, + query: acceptedQuery + } = acceptedParams.index + const userQuery = params?.querystring const querystring: Record<string, any> = userQuery != null ? { ...userQuery } : {} @@ -58,8 +93,14 @@ export default async function IndexApi<TDocument = unknown> (this: That, params: } else if (acceptedPath.includes(key)) { continue } else if (key !== 'body' && key !== 'querystring') { - // @ts-expect-error - querystring[key] = params[key] + if (acceptedQuery.includes(key) || commonQueryParams.includes(key)) { + // @ts-expect-error + querystring[key] = params[key] + } else { + body = body ?? {} + // @ts-expect-error + body[key] = params[key] + } } } diff --git a/src/api/api/indices.ts b/src/api/api/indices.ts index 8af3fb23d..85cf78aea 100644 --- a/src/api/api/indices.ts +++ b/src/api/api/indices.ts @@ -35,12 +35,834 @@ import { TransportResult } from '@elastic/transport' import * as T from '../types' -interface That { transport: Transport } + +interface That { + transport: Transport + acceptedParams: Record<string, { path: string[], body: string[], query: string[] }> +} + +const commonQueryParams = ['error_trace', 'filter_path', 'human', 'pretty'] export default class Indices { transport: Transport + acceptedParams: Record<string, { path: string[], body: string[], query: string[] }> constructor (transport: Transport) { this.transport = transport + this.acceptedParams = { + 'indices.add_block': { + path: [ + 'index', + 'block' + ], + body: [], + query: [ + 'allow_no_indices', + 'expand_wildcards', + 'ignore_unavailable', + 'master_timeout', + 'timeout' + ] + }, + 'indices.analyze': { + path: [ + 'index' + ], + body: [ + 'analyzer', + 'attributes', + 'char_filter', + 'explain', + 'field', + 'filter', + 'normalizer', + 'text', + 'tokenizer' + ], + query: [] + }, + 'indices.cancel_migrate_reindex': { + path: [ + 'index' + ], + body: [], + query: [] + }, + 'indices.clear_cache': { + path: [ + 'index' + ], + body: [], + query: [ + 'allow_no_indices', + 'expand_wildcards', + 'fielddata', + 'fields', + 'ignore_unavailable', + 'query', + 'request' + ] + }, + 'indices.clone': { + path: [ + 'index', + 'target' + ], + body: [ + 'aliases', + 'settings' + ], + query: [ + 'master_timeout', + 'timeout', + 'wait_for_active_shards' + ] + }, + 'indices.close': { + path: [ + 'index' + ], + body: [], + query: [ + 'allow_no_indices', + 'expand_wildcards', + 'ignore_unavailable', + 'master_timeout', + 'timeout', + 'wait_for_active_shards' + ] + }, + 'indices.create': { + path: [ + 'index' + ], + body: [ + 'aliases', + 'mappings', + 'settings' + ], + query: [ + 'master_timeout', + 'timeout', + 'wait_for_active_shards' + ] + }, + 'indices.create_data_stream': { + path: [ + 'name' + ], + body: [], + query: [ + 'master_timeout', + 'timeout' + ] + }, + 'indices.create_from': { + path: [ + 'source', + 'dest' + ], + body: [ + 'create_from' + ], + query: [] + }, + 'indices.data_streams_stats': { + path: [ + 'name' + ], + body: [], + query: [ + 'expand_wildcards' + ] + }, + 'indices.delete': { + path: [ + 'index' + ], + body: [], + query: [ + 'allow_no_indices', + 'expand_wildcards', + 'ignore_unavailable', + 'master_timeout', + 'timeout' + ] + }, + 'indices.delete_alias': { + path: [ + 'index', + 'name' + ], + body: [], + query: [ + 'master_timeout', + 'timeout' + ] + }, + 'indices.delete_data_lifecycle': { + path: [ + 'name' + ], + body: [], + query: [ + 'expand_wildcards', + 'master_timeout', + 'timeout' + ] + }, + 'indices.delete_data_stream': { + path: [ + 'name' + ], + body: [], + query: [ + 'master_timeout', + 'expand_wildcards' + ] + }, + 'indices.delete_index_template': { + path: [ + 'name' + ], + body: [], + query: [ + 'master_timeout', + 'timeout' + ] + }, + 'indices.delete_template': { + path: [ + 'name' + ], + body: [], + query: [ + 'master_timeout', + 'timeout' + ] + }, + 'indices.disk_usage': { + path: [ + 'index' + ], + body: [], + query: [ + 'allow_no_indices', + 'expand_wildcards', + 'flush', + 'ignore_unavailable', + 'run_expensive_tasks' + ] + }, + 'indices.downsample': { + path: [ + 'index', + 'target_index' + ], + body: [ + 'config' + ], + query: [] + }, + 'indices.exists': { + path: [ + 'index' + ], + body: [], + query: [ + 'allow_no_indices', + 'expand_wildcards', + 'flat_settings', + 'ignore_unavailable', + 'include_defaults', + 'local' + ] + }, + 'indices.exists_alias': { + path: [ + 'name', + 'index' + ], + body: [], + query: [ + 'allow_no_indices', + 'expand_wildcards', + 'ignore_unavailable', + 'master_timeout' + ] + }, + 'indices.exists_index_template': { + path: [ + 'name' + ], + body: [], + query: [ + 'master_timeout' + ] + }, + 'indices.exists_template': { + path: [ + 'name' + ], + body: [], + query: [ + 'flat_settings', + 'local', + 'master_timeout' + ] + }, + 'indices.explain_data_lifecycle': { + path: [ + 'index' + ], + body: [], + query: [ + 'include_defaults', + 'master_timeout' + ] + }, + 'indices.field_usage_stats': { + path: [ + 'index' + ], + body: [], + query: [ + 'allow_no_indices', + 'expand_wildcards', + 'ignore_unavailable', + 'fields', + 'wait_for_active_shards' + ] + }, + 'indices.flush': { + path: [ + 'index' + ], + body: [], + query: [ + 'allow_no_indices', + 'expand_wildcards', + 'force', + 'ignore_unavailable', + 'wait_if_ongoing' + ] + }, + 'indices.forcemerge': { + path: [ + 'index' + ], + body: [], + query: [ + 'allow_no_indices', + 'expand_wildcards', + 'flush', + 'ignore_unavailable', + 'max_num_segments', + 'only_expunge_deletes', + 'wait_for_completion' + ] + }, + 'indices.get': { + path: [ + 'index' + ], + body: [], + query: [ + 'allow_no_indices', + 'expand_wildcards', + 'flat_settings', + 'ignore_unavailable', + 'include_defaults', + 'local', + 'master_timeout', + 'features' + ] + }, + 'indices.get_alias': { + path: [ + 'name', + 'index' + ], + body: [], + query: [ + 'allow_no_indices', + 'expand_wildcards', + 'ignore_unavailable', + 'master_timeout' + ] + }, + 'indices.get_data_lifecycle': { + path: [ + 'name' + ], + body: [], + query: [ + 'expand_wildcards', + 'include_defaults', + 'master_timeout' + ] + }, + 'indices.get_data_lifecycle_stats': { + path: [], + body: [], + query: [] + }, + 'indices.get_data_stream': { + path: [ + 'name' + ], + body: [], + query: [ + 'expand_wildcards', + 'include_defaults', + 'master_timeout', + 'verbose' + ] + }, + 'indices.get_field_mapping': { + path: [ + 'fields', + 'index' + ], + body: [], + query: [ + 'allow_no_indices', + 'expand_wildcards', + 'ignore_unavailable', + 'include_defaults' + ] + }, + 'indices.get_index_template': { + path: [ + 'name' + ], + body: [], + query: [ + 'local', + 'flat_settings', + 'master_timeout', + 'include_defaults' + ] + }, + 'indices.get_mapping': { + path: [ + 'index' + ], + body: [], + query: [ + 'allow_no_indices', + 'expand_wildcards', + 'ignore_unavailable', + 'local', + 'master_timeout' + ] + }, + 'indices.get_migrate_reindex_status': { + path: [ + 'index' + ], + body: [], + query: [] + }, + 'indices.get_settings': { + path: [ + 'index', + 'name' + ], + body: [], + query: [ + 'allow_no_indices', + 'expand_wildcards', + 'flat_settings', + 'ignore_unavailable', + 'include_defaults', + 'local', + 'master_timeout' + ] + }, + 'indices.get_template': { + path: [ + 'name' + ], + body: [], + query: [ + 'flat_settings', + 'local', + 'master_timeout' + ] + }, + 'indices.migrate_reindex': { + path: [], + body: [ + 'reindex' + ], + query: [] + }, + 'indices.migrate_to_data_stream': { + path: [ + 'name' + ], + body: [], + query: [ + 'master_timeout', + 'timeout' + ] + }, + 'indices.modify_data_stream': { + path: [], + body: [ + 'actions' + ], + query: [] + }, + 'indices.open': { + path: [ + 'index' + ], + body: [], + query: [ + 'allow_no_indices', + 'expand_wildcards', + 'ignore_unavailable', + 'master_timeout', + 'timeout', + 'wait_for_active_shards' + ] + }, + 'indices.promote_data_stream': { + path: [ + 'name' + ], + body: [], + query: [ + 'master_timeout' + ] + }, + 'indices.put_alias': { + path: [ + 'index', + 'name' + ], + body: [ + 'filter', + 'index_routing', + 'is_write_index', + 'routing', + 'search_routing' + ], + query: [ + 'master_timeout', + 'timeout' + ] + }, + 'indices.put_data_lifecycle': { + path: [ + 'name' + ], + body: [ + 'data_retention', + 'downsampling', + 'enabled' + ], + query: [ + 'expand_wildcards', + 'master_timeout', + 'timeout' + ] + }, + 'indices.put_index_template': { + path: [ + 'name' + ], + body: [ + 'index_patterns', + 'composed_of', + 'template', + 'data_stream', + 'priority', + 'version', + '_meta', + 'allow_auto_create', + 'ignore_missing_component_templates', + 'deprecated' + ], + query: [ + 'create', + 'master_timeout', + 'cause' + ] + }, + 'indices.put_mapping': { + path: [ + 'index' + ], + body: [ + 'date_detection', + 'dynamic', + 'dynamic_date_formats', + 'dynamic_templates', + '_field_names', + '_meta', + 'numeric_detection', + 'properties', + '_routing', + '_source', + 'runtime' + ], + query: [ + 'allow_no_indices', + 'expand_wildcards', + 'ignore_unavailable', + 'master_timeout', + 'timeout', + 'write_index_only' + ] + }, + 'indices.put_settings': { + path: [ + 'index' + ], + body: [ + 'settings' + ], + query: [ + 'allow_no_indices', + 'expand_wildcards', + 'flat_settings', + 'ignore_unavailable', + 'master_timeout', + 'preserve_existing', + 'timeout' + ] + }, + 'indices.put_template': { + path: [ + 'name' + ], + body: [ + 'aliases', + 'index_patterns', + 'mappings', + 'order', + 'settings', + 'version' + ], + query: [ + 'create', + 'master_timeout', + 'order', + 'cause' + ] + }, + 'indices.recovery': { + path: [ + 'index' + ], + body: [], + query: [ + 'active_only', + 'detailed' + ] + }, + 'indices.refresh': { + path: [ + 'index' + ], + body: [], + query: [ + 'allow_no_indices', + 'expand_wildcards', + 'ignore_unavailable' + ] + }, + 'indices.reload_search_analyzers': { + path: [ + 'index' + ], + body: [], + query: [ + 'allow_no_indices', + 'expand_wildcards', + 'ignore_unavailable' + ] + }, + 'indices.resolve_cluster': { + path: [ + 'name' + ], + body: [], + query: [ + 'allow_no_indices', + 'expand_wildcards', + 'ignore_throttled', + 'ignore_unavailable', + 'timeout' + ] + }, + 'indices.resolve_index': { + path: [ + 'name' + ], + body: [], + query: [ + 'expand_wildcards', + 'ignore_unavailable', + 'allow_no_indices' + ] + }, + 'indices.rollover': { + path: [ + 'alias', + 'new_index' + ], + body: [ + 'aliases', + 'conditions', + 'mappings', + 'settings' + ], + query: [ + 'dry_run', + 'master_timeout', + 'timeout', + 'wait_for_active_shards' + ] + }, + 'indices.segments': { + path: [ + 'index' + ], + body: [], + query: [ + 'allow_no_indices', + 'expand_wildcards', + 'ignore_unavailable' + ] + }, + 'indices.shard_stores': { + path: [ + 'index' + ], + body: [], + query: [ + 'allow_no_indices', + 'expand_wildcards', + 'ignore_unavailable', + 'status' + ] + }, + 'indices.shrink': { + path: [ + 'index', + 'target' + ], + body: [ + 'aliases', + 'settings' + ], + query: [ + 'master_timeout', + 'timeout', + 'wait_for_active_shards' + ] + }, + 'indices.simulate_index_template': { + path: [ + 'name' + ], + body: [], + query: [ + 'master_timeout', + 'include_defaults' + ] + }, + 'indices.simulate_template': { + path: [ + 'name' + ], + body: [ + 'allow_auto_create', + 'index_patterns', + 'composed_of', + 'template', + 'data_stream', + 'priority', + 'version', + '_meta', + 'ignore_missing_component_templates', + 'deprecated' + ], + query: [ + 'create', + 'master_timeout', + 'include_defaults' + ] + }, + 'indices.split': { + path: [ + 'index', + 'target' + ], + body: [ + 'aliases', + 'settings' + ], + query: [ + 'master_timeout', + 'timeout', + 'wait_for_active_shards' + ] + }, + 'indices.stats': { + path: [ + 'metric', + 'index' + ], + body: [], + query: [ + 'completion_fields', + 'expand_wildcards', + 'fielddata_fields', + 'fields', + 'forbid_closed_indices', + 'groups', + 'include_segment_file_sizes', + 'include_unloaded_segments', + 'level' + ] + }, + 'indices.update_aliases': { + path: [], + body: [ + 'actions' + ], + query: [ + 'master_timeout', + 'timeout' + ] + }, + 'indices.validate_query': { + path: [ + 'index' + ], + body: [ + 'query' + ], + query: [ + 'allow_no_indices', + 'all_shards', + 'analyzer', + 'analyze_wildcard', + 'default_operator', + 'df', + 'expand_wildcards', + 'explain', + 'ignore_unavailable', + 'lenient', + 'rewrite', + 'q' + ] + } + } } /** @@ -51,7 +873,10 @@ export default class Indices { async addBlock (this: That, params: T.IndicesAddBlockRequest, options?: TransportRequestOptionsWithMeta): Promise<TransportResult<T.IndicesAddBlockResponse, unknown>> async addBlock (this: That, params: T.IndicesAddBlockRequest, options?: TransportRequestOptions): Promise<T.IndicesAddBlockResponse> async addBlock (this: That, params: T.IndicesAddBlockRequest, options?: TransportRequestOptions): Promise<any> { - const acceptedPath: string[] = ['index', 'block'] + const { + path: acceptedPath + } = this.acceptedParams['indices.add_block'] + const userQuery = params?.querystring const querystring: Record<string, any> = userQuery != null ? { ...userQuery } : {} @@ -94,8 +919,12 @@ export default class Indices { async analyze (this: That, params?: T.IndicesAnalyzeRequest, options?: TransportRequestOptionsWithMeta): Promise<TransportResult<T.IndicesAnalyzeResponse, unknown>> async analyze (this: That, params?: T.IndicesAnalyzeRequest, options?: TransportRequestOptions): Promise<T.IndicesAnalyzeResponse> async analyze (this: That, params?: T.IndicesAnalyzeRequest, options?: TransportRequestOptions): Promise<any> { - const acceptedPath: string[] = ['index'] - const acceptedBody: string[] = ['analyzer', 'attributes', 'char_filter', 'explain', 'field', 'filter', 'normalizer', 'text', 'tokenizer'] + const { + path: acceptedPath, + body: acceptedBody, + query: acceptedQuery + } = this.acceptedParams['indices.analyze'] + const userQuery = params?.querystring const querystring: Record<string, any> = userQuery != null ? { ...userQuery } : {} @@ -118,8 +947,14 @@ export default class Indices { } else if (acceptedPath.includes(key)) { continue } else if (key !== 'body' && key !== 'querystring') { - // @ts-expect-error - querystring[key] = params[key] + if (acceptedQuery.includes(key) || commonQueryParams.includes(key)) { + // @ts-expect-error + querystring[key] = params[key] + } else { + body = body ?? {} + // @ts-expect-error + body[key] = params[key] + } } } @@ -149,7 +984,10 @@ export default class Indices { async cancelMigrateReindex (this: That, params: T.IndicesCancelMigrateReindexRequest, options?: TransportRequestOptionsWithMeta): Promise<TransportResult<T.IndicesCancelMigrateReindexResponse, unknown>> async cancelMigrateReindex (this: That, params: T.IndicesCancelMigrateReindexRequest, options?: TransportRequestOptions): Promise<T.IndicesCancelMigrateReindexResponse> async cancelMigrateReindex (this: That, params: T.IndicesCancelMigrateReindexRequest, options?: TransportRequestOptions): Promise<any> { - const acceptedPath: string[] = ['index'] + const { + path: acceptedPath + } = this.acceptedParams['indices.cancel_migrate_reindex'] + const userQuery = params?.querystring const querystring: Record<string, any> = userQuery != null ? { ...userQuery } : {} @@ -191,7 +1029,10 @@ export default class Indices { async clearCache (this: That, params?: T.IndicesClearCacheRequest, options?: TransportRequestOptionsWithMeta): Promise<TransportResult<T.IndicesClearCacheResponse, unknown>> async clearCache (this: That, params?: T.IndicesClearCacheRequest, options?: TransportRequestOptions): Promise<T.IndicesClearCacheResponse> async clearCache (this: That, params?: T.IndicesClearCacheRequest, options?: TransportRequestOptions): Promise<any> { - const acceptedPath: string[] = ['index'] + const { + path: acceptedPath + } = this.acceptedParams['indices.clear_cache'] + const userQuery = params?.querystring const querystring: Record<string, any> = userQuery != null ? { ...userQuery } : {} @@ -241,8 +1082,12 @@ export default class Indices { async clone (this: That, params: T.IndicesCloneRequest, options?: TransportRequestOptionsWithMeta): Promise<TransportResult<T.IndicesCloneResponse, unknown>> async clone (this: That, params: T.IndicesCloneRequest, options?: TransportRequestOptions): Promise<T.IndicesCloneResponse> async clone (this: That, params: T.IndicesCloneRequest, options?: TransportRequestOptions): Promise<any> { - const acceptedPath: string[] = ['index', 'target'] - const acceptedBody: string[] = ['aliases', 'settings'] + const { + path: acceptedPath, + body: acceptedBody, + query: acceptedQuery + } = this.acceptedParams['indices.clone'] + const userQuery = params?.querystring const querystring: Record<string, any> = userQuery != null ? { ...userQuery } : {} @@ -264,8 +1109,14 @@ export default class Indices { } else if (acceptedPath.includes(key)) { continue } else if (key !== 'body' && key !== 'querystring') { - // @ts-expect-error - querystring[key] = params[key] + if (acceptedQuery.includes(key) || commonQueryParams.includes(key)) { + // @ts-expect-error + querystring[key] = params[key] + } else { + body = body ?? {} + // @ts-expect-error + body[key] = params[key] + } } } @@ -289,7 +1140,10 @@ export default class Indices { async close (this: That, params: T.IndicesCloseRequest, options?: TransportRequestOptionsWithMeta): Promise<TransportResult<T.IndicesCloseResponse, unknown>> async close (this: That, params: T.IndicesCloseRequest, options?: TransportRequestOptions): Promise<T.IndicesCloseResponse> async close (this: That, params: T.IndicesCloseRequest, options?: TransportRequestOptions): Promise<any> { - const acceptedPath: string[] = ['index'] + const { + path: acceptedPath + } = this.acceptedParams['indices.close'] + const userQuery = params?.querystring const querystring: Record<string, any> = userQuery != null ? { ...userQuery } : {} @@ -331,8 +1185,12 @@ export default class Indices { async create (this: That, params: T.IndicesCreateRequest, options?: TransportRequestOptionsWithMeta): Promise<TransportResult<T.IndicesCreateResponse, unknown>> async create (this: That, params: T.IndicesCreateRequest, options?: TransportRequestOptions): Promise<T.IndicesCreateResponse> async create (this: That, params: T.IndicesCreateRequest, options?: TransportRequestOptions): Promise<any> { - const acceptedPath: string[] = ['index'] - const acceptedBody: string[] = ['aliases', 'mappings', 'settings'] + const { + path: acceptedPath, + body: acceptedBody, + query: acceptedQuery + } = this.acceptedParams['indices.create'] + const userQuery = params?.querystring const querystring: Record<string, any> = userQuery != null ? { ...userQuery } : {} @@ -354,8 +1212,14 @@ export default class Indices { } else if (acceptedPath.includes(key)) { continue } else if (key !== 'body' && key !== 'querystring') { - // @ts-expect-error - querystring[key] = params[key] + if (acceptedQuery.includes(key) || commonQueryParams.includes(key)) { + // @ts-expect-error + querystring[key] = params[key] + } else { + body = body ?? {} + // @ts-expect-error + body[key] = params[key] + } } } @@ -378,7 +1242,10 @@ export default class Indices { async createDataStream (this: That, params: T.IndicesCreateDataStreamRequest, options?: TransportRequestOptionsWithMeta): Promise<TransportResult<T.IndicesCreateDataStreamResponse, unknown>> async createDataStream (this: That, params: T.IndicesCreateDataStreamRequest, options?: TransportRequestOptions): Promise<T.IndicesCreateDataStreamResponse> async createDataStream (this: That, params: T.IndicesCreateDataStreamRequest, options?: TransportRequestOptions): Promise<any> { - const acceptedPath: string[] = ['name'] + const { + path: acceptedPath + } = this.acceptedParams['indices.create_data_stream'] + const userQuery = params?.querystring const querystring: Record<string, any> = userQuery != null ? { ...userQuery } : {} @@ -420,8 +1287,12 @@ export default class Indices { async createFrom (this: That, params: T.IndicesCreateFromRequest, options?: TransportRequestOptionsWithMeta): Promise<TransportResult<T.IndicesCreateFromResponse, unknown>> async createFrom (this: That, params: T.IndicesCreateFromRequest, options?: TransportRequestOptions): Promise<T.IndicesCreateFromResponse> async createFrom (this: That, params: T.IndicesCreateFromRequest, options?: TransportRequestOptions): Promise<any> { - const acceptedPath: string[] = ['source', 'dest'] - const acceptedBody: string[] = ['create_from'] + const { + path: acceptedPath, + body: acceptedBody, + query: acceptedQuery + } = this.acceptedParams['indices.create_from'] + const userQuery = params?.querystring const querystring: Record<string, any> = userQuery != null ? { ...userQuery } : {} @@ -433,8 +1304,14 @@ export default class Indices { } else if (acceptedPath.includes(key)) { continue } else if (key !== 'body' && key !== 'querystring') { - // @ts-expect-error - querystring[key] = params[key] + if (acceptedQuery.includes(key) || commonQueryParams.includes(key)) { + // @ts-expect-error + querystring[key] = params[key] + } else { + body = body ?? {} + // @ts-expect-error + body[key] = params[key] + } } } @@ -458,7 +1335,10 @@ export default class Indices { async dataStreamsStats (this: That, params?: T.IndicesDataStreamsStatsRequest, options?: TransportRequestOptionsWithMeta): Promise<TransportResult<T.IndicesDataStreamsStatsResponse, unknown>> async dataStreamsStats (this: That, params?: T.IndicesDataStreamsStatsRequest, options?: TransportRequestOptions): Promise<T.IndicesDataStreamsStatsResponse> async dataStreamsStats (this: That, params?: T.IndicesDataStreamsStatsRequest, options?: TransportRequestOptions): Promise<any> { - const acceptedPath: string[] = ['name'] + const { + path: acceptedPath + } = this.acceptedParams['indices.data_streams_stats'] + const userQuery = params?.querystring const querystring: Record<string, any> = userQuery != null ? { ...userQuery } : {} @@ -508,7 +1388,10 @@ export default class Indices { async delete (this: That, params: T.IndicesDeleteRequest, options?: TransportRequestOptionsWithMeta): Promise<TransportResult<T.IndicesDeleteResponse, unknown>> async delete (this: That, params: T.IndicesDeleteRequest, options?: TransportRequestOptions): Promise<T.IndicesDeleteResponse> async delete (this: That, params: T.IndicesDeleteRequest, options?: TransportRequestOptions): Promise<any> { - const acceptedPath: string[] = ['index'] + const { + path: acceptedPath + } = this.acceptedParams['indices.delete'] + const userQuery = params?.querystring const querystring: Record<string, any> = userQuery != null ? { ...userQuery } : {} @@ -550,7 +1433,10 @@ export default class Indices { async deleteAlias (this: That, params: T.IndicesDeleteAliasRequest, options?: TransportRequestOptionsWithMeta): Promise<TransportResult<T.IndicesDeleteAliasResponse, unknown>> async deleteAlias (this: That, params: T.IndicesDeleteAliasRequest, options?: TransportRequestOptions): Promise<T.IndicesDeleteAliasResponse> async deleteAlias (this: That, params: T.IndicesDeleteAliasRequest, options?: TransportRequestOptions): Promise<any> { - const acceptedPath: string[] = ['index', 'name'] + const { + path: acceptedPath + } = this.acceptedParams['indices.delete_alias'] + const userQuery = params?.querystring const querystring: Record<string, any> = userQuery != null ? { ...userQuery } : {} @@ -600,7 +1486,10 @@ export default class Indices { async deleteDataLifecycle (this: That, params: T.IndicesDeleteDataLifecycleRequest, options?: TransportRequestOptionsWithMeta): Promise<TransportResult<T.IndicesDeleteDataLifecycleResponse, unknown>> async deleteDataLifecycle (this: That, params: T.IndicesDeleteDataLifecycleRequest, options?: TransportRequestOptions): Promise<T.IndicesDeleteDataLifecycleResponse> async deleteDataLifecycle (this: That, params: T.IndicesDeleteDataLifecycleRequest, options?: TransportRequestOptions): Promise<any> { - const acceptedPath: string[] = ['name'] + const { + path: acceptedPath + } = this.acceptedParams['indices.delete_data_lifecycle'] + const userQuery = params?.querystring const querystring: Record<string, any> = userQuery != null ? { ...userQuery } : {} @@ -642,7 +1531,10 @@ export default class Indices { async deleteDataStream (this: That, params: T.IndicesDeleteDataStreamRequest, options?: TransportRequestOptionsWithMeta): Promise<TransportResult<T.IndicesDeleteDataStreamResponse, unknown>> async deleteDataStream (this: That, params: T.IndicesDeleteDataStreamRequest, options?: TransportRequestOptions): Promise<T.IndicesDeleteDataStreamResponse> async deleteDataStream (this: That, params: T.IndicesDeleteDataStreamRequest, options?: TransportRequestOptions): Promise<any> { - const acceptedPath: string[] = ['name'] + const { + path: acceptedPath + } = this.acceptedParams['indices.delete_data_stream'] + const userQuery = params?.querystring const querystring: Record<string, any> = userQuery != null ? { ...userQuery } : {} @@ -684,7 +1576,10 @@ export default class Indices { async deleteIndexTemplate (this: That, params: T.IndicesDeleteIndexTemplateRequest, options?: TransportRequestOptionsWithMeta): Promise<TransportResult<T.IndicesDeleteIndexTemplateResponse, unknown>> async deleteIndexTemplate (this: That, params: T.IndicesDeleteIndexTemplateRequest, options?: TransportRequestOptions): Promise<T.IndicesDeleteIndexTemplateResponse> async deleteIndexTemplate (this: That, params: T.IndicesDeleteIndexTemplateRequest, options?: TransportRequestOptions): Promise<any> { - const acceptedPath: string[] = ['name'] + const { + path: acceptedPath + } = this.acceptedParams['indices.delete_index_template'] + const userQuery = params?.querystring const querystring: Record<string, any> = userQuery != null ? { ...userQuery } : {} @@ -726,7 +1621,10 @@ export default class Indices { async deleteTemplate (this: That, params: T.IndicesDeleteTemplateRequest, options?: TransportRequestOptionsWithMeta): Promise<TransportResult<T.IndicesDeleteTemplateResponse, unknown>> async deleteTemplate (this: That, params: T.IndicesDeleteTemplateRequest, options?: TransportRequestOptions): Promise<T.IndicesDeleteTemplateResponse> async deleteTemplate (this: That, params: T.IndicesDeleteTemplateRequest, options?: TransportRequestOptions): Promise<any> { - const acceptedPath: string[] = ['name'] + const { + path: acceptedPath + } = this.acceptedParams['indices.delete_template'] + const userQuery = params?.querystring const querystring: Record<string, any> = userQuery != null ? { ...userQuery } : {} @@ -768,7 +1666,10 @@ export default class Indices { async diskUsage (this: That, params: T.IndicesDiskUsageRequest, options?: TransportRequestOptionsWithMeta): Promise<TransportResult<T.IndicesDiskUsageResponse, unknown>> async diskUsage (this: That, params: T.IndicesDiskUsageRequest, options?: TransportRequestOptions): Promise<T.IndicesDiskUsageResponse> async diskUsage (this: That, params: T.IndicesDiskUsageRequest, options?: TransportRequestOptions): Promise<any> { - const acceptedPath: string[] = ['index'] + const { + path: acceptedPath + } = this.acceptedParams['indices.disk_usage'] + const userQuery = params?.querystring const querystring: Record<string, any> = userQuery != null ? { ...userQuery } : {} @@ -810,8 +1711,12 @@ export default class Indices { async downsample (this: That, params: T.IndicesDownsampleRequest, options?: TransportRequestOptionsWithMeta): Promise<TransportResult<T.IndicesDownsampleResponse, unknown>> async downsample (this: That, params: T.IndicesDownsampleRequest, options?: TransportRequestOptions): Promise<T.IndicesDownsampleResponse> async downsample (this: That, params: T.IndicesDownsampleRequest, options?: TransportRequestOptions): Promise<any> { - const acceptedPath: string[] = ['index', 'target_index'] - const acceptedBody: string[] = ['config'] + const { + path: acceptedPath, + body: acceptedBody, + query: acceptedQuery + } = this.acceptedParams['indices.downsample'] + const userQuery = params?.querystring const querystring: Record<string, any> = userQuery != null ? { ...userQuery } : {} @@ -823,8 +1728,14 @@ export default class Indices { } else if (acceptedPath.includes(key)) { continue } else if (key !== 'body' && key !== 'querystring') { - // @ts-expect-error - querystring[key] = params[key] + if (acceptedQuery.includes(key) || commonQueryParams.includes(key)) { + // @ts-expect-error + querystring[key] = params[key] + } else { + body = body ?? {} + // @ts-expect-error + body[key] = params[key] + } } } @@ -848,7 +1759,10 @@ export default class Indices { async exists (this: That, params: T.IndicesExistsRequest, options?: TransportRequestOptionsWithMeta): Promise<TransportResult<T.IndicesExistsResponse, unknown>> async exists (this: That, params: T.IndicesExistsRequest, options?: TransportRequestOptions): Promise<T.IndicesExistsResponse> async exists (this: That, params: T.IndicesExistsRequest, options?: TransportRequestOptions): Promise<any> { - const acceptedPath: string[] = ['index'] + const { + path: acceptedPath + } = this.acceptedParams['indices.exists'] + const userQuery = params?.querystring const querystring: Record<string, any> = userQuery != null ? { ...userQuery } : {} @@ -890,7 +1804,10 @@ export default class Indices { async existsAlias (this: That, params: T.IndicesExistsAliasRequest, options?: TransportRequestOptionsWithMeta): Promise<TransportResult<T.IndicesExistsAliasResponse, unknown>> async existsAlias (this: That, params: T.IndicesExistsAliasRequest, options?: TransportRequestOptions): Promise<T.IndicesExistsAliasResponse> async existsAlias (this: That, params: T.IndicesExistsAliasRequest, options?: TransportRequestOptions): Promise<any> { - const acceptedPath: string[] = ['name', 'index'] + const { + path: acceptedPath + } = this.acceptedParams['indices.exists_alias'] + const userQuery = params?.querystring const querystring: Record<string, any> = userQuery != null ? { ...userQuery } : {} @@ -940,7 +1857,10 @@ export default class Indices { async existsIndexTemplate (this: That, params: T.IndicesExistsIndexTemplateRequest, options?: TransportRequestOptionsWithMeta): Promise<TransportResult<T.IndicesExistsIndexTemplateResponse, unknown>> async existsIndexTemplate (this: That, params: T.IndicesExistsIndexTemplateRequest, options?: TransportRequestOptions): Promise<T.IndicesExistsIndexTemplateResponse> async existsIndexTemplate (this: That, params: T.IndicesExistsIndexTemplateRequest, options?: TransportRequestOptions): Promise<any> { - const acceptedPath: string[] = ['name'] + const { + path: acceptedPath + } = this.acceptedParams['indices.exists_index_template'] + const userQuery = params?.querystring const querystring: Record<string, any> = userQuery != null ? { ...userQuery } : {} @@ -982,7 +1902,10 @@ export default class Indices { async existsTemplate (this: That, params: T.IndicesExistsTemplateRequest, options?: TransportRequestOptionsWithMeta): Promise<TransportResult<T.IndicesExistsTemplateResponse, unknown>> async existsTemplate (this: That, params: T.IndicesExistsTemplateRequest, options?: TransportRequestOptions): Promise<T.IndicesExistsTemplateResponse> async existsTemplate (this: That, params: T.IndicesExistsTemplateRequest, options?: TransportRequestOptions): Promise<any> { - const acceptedPath: string[] = ['name'] + const { + path: acceptedPath + } = this.acceptedParams['indices.exists_template'] + const userQuery = params?.querystring const querystring: Record<string, any> = userQuery != null ? { ...userQuery } : {} @@ -1024,7 +1947,10 @@ export default class Indices { async explainDataLifecycle (this: That, params: T.IndicesExplainDataLifecycleRequest, options?: TransportRequestOptionsWithMeta): Promise<TransportResult<T.IndicesExplainDataLifecycleResponse, unknown>> async explainDataLifecycle (this: That, params: T.IndicesExplainDataLifecycleRequest, options?: TransportRequestOptions): Promise<T.IndicesExplainDataLifecycleResponse> async explainDataLifecycle (this: That, params: T.IndicesExplainDataLifecycleRequest, options?: TransportRequestOptions): Promise<any> { - const acceptedPath: string[] = ['index'] + const { + path: acceptedPath + } = this.acceptedParams['indices.explain_data_lifecycle'] + const userQuery = params?.querystring const querystring: Record<string, any> = userQuery != null ? { ...userQuery } : {} @@ -1066,7 +1992,10 @@ export default class Indices { async fieldUsageStats (this: That, params: T.IndicesFieldUsageStatsRequest, options?: TransportRequestOptionsWithMeta): Promise<TransportResult<T.IndicesFieldUsageStatsResponse, unknown>> async fieldUsageStats (this: That, params: T.IndicesFieldUsageStatsRequest, options?: TransportRequestOptions): Promise<T.IndicesFieldUsageStatsResponse> async fieldUsageStats (this: That, params: T.IndicesFieldUsageStatsRequest, options?: TransportRequestOptions): Promise<any> { - const acceptedPath: string[] = ['index'] + const { + path: acceptedPath + } = this.acceptedParams['indices.field_usage_stats'] + const userQuery = params?.querystring const querystring: Record<string, any> = userQuery != null ? { ...userQuery } : {} @@ -1108,7 +2037,10 @@ export default class Indices { async flush (this: That, params?: T.IndicesFlushRequest, options?: TransportRequestOptionsWithMeta): Promise<TransportResult<T.IndicesFlushResponse, unknown>> async flush (this: That, params?: T.IndicesFlushRequest, options?: TransportRequestOptions): Promise<T.IndicesFlushResponse> async flush (this: That, params?: T.IndicesFlushRequest, options?: TransportRequestOptions): Promise<any> { - const acceptedPath: string[] = ['index'] + const { + path: acceptedPath + } = this.acceptedParams['indices.flush'] + const userQuery = params?.querystring const querystring: Record<string, any> = userQuery != null ? { ...userQuery } : {} @@ -1158,7 +2090,10 @@ export default class Indices { async forcemerge (this: That, params?: T.IndicesForcemergeRequest, options?: TransportRequestOptionsWithMeta): Promise<TransportResult<T.IndicesForcemergeResponse, unknown>> async forcemerge (this: That, params?: T.IndicesForcemergeRequest, options?: TransportRequestOptions): Promise<T.IndicesForcemergeResponse> async forcemerge (this: That, params?: T.IndicesForcemergeRequest, options?: TransportRequestOptions): Promise<any> { - const acceptedPath: string[] = ['index'] + const { + path: acceptedPath + } = this.acceptedParams['indices.forcemerge'] + const userQuery = params?.querystring const querystring: Record<string, any> = userQuery != null ? { ...userQuery } : {} @@ -1208,7 +2143,10 @@ export default class Indices { async get (this: That, params: T.IndicesGetRequest, options?: TransportRequestOptionsWithMeta): Promise<TransportResult<T.IndicesGetResponse, unknown>> async get (this: That, params: T.IndicesGetRequest, options?: TransportRequestOptions): Promise<T.IndicesGetResponse> async get (this: That, params: T.IndicesGetRequest, options?: TransportRequestOptions): Promise<any> { - const acceptedPath: string[] = ['index'] + const { + path: acceptedPath + } = this.acceptedParams['indices.get'] + const userQuery = params?.querystring const querystring: Record<string, any> = userQuery != null ? { ...userQuery } : {} @@ -1250,7 +2188,10 @@ export default class Indices { async getAlias (this: That, params?: T.IndicesGetAliasRequest, options?: TransportRequestOptionsWithMeta): Promise<TransportResult<T.IndicesGetAliasResponse, unknown>> async getAlias (this: That, params?: T.IndicesGetAliasRequest, options?: TransportRequestOptions): Promise<T.IndicesGetAliasResponse> async getAlias (this: That, params?: T.IndicesGetAliasRequest, options?: TransportRequestOptions): Promise<any> { - const acceptedPath: string[] = ['name', 'index'] + const { + path: acceptedPath + } = this.acceptedParams['indices.get_alias'] + const userQuery = params?.querystring const querystring: Record<string, any> = userQuery != null ? { ...userQuery } : {} @@ -1307,7 +2248,10 @@ export default class Indices { async getDataLifecycle (this: That, params: T.IndicesGetDataLifecycleRequest, options?: TransportRequestOptionsWithMeta): Promise<TransportResult<T.IndicesGetDataLifecycleResponse, unknown>> async getDataLifecycle (this: That, params: T.IndicesGetDataLifecycleRequest, options?: TransportRequestOptions): Promise<T.IndicesGetDataLifecycleResponse> async getDataLifecycle (this: That, params: T.IndicesGetDataLifecycleRequest, options?: TransportRequestOptions): Promise<any> { - const acceptedPath: string[] = ['name'] + const { + path: acceptedPath + } = this.acceptedParams['indices.get_data_lifecycle'] + const userQuery = params?.querystring const querystring: Record<string, any> = userQuery != null ? { ...userQuery } : {} @@ -1349,7 +2293,10 @@ export default class Indices { async getDataLifecycleStats (this: That, params?: T.IndicesGetDataLifecycleStatsRequest, options?: TransportRequestOptionsWithMeta): Promise<TransportResult<T.IndicesGetDataLifecycleStatsResponse, unknown>> async getDataLifecycleStats (this: That, params?: T.IndicesGetDataLifecycleStatsRequest, options?: TransportRequestOptions): Promise<T.IndicesGetDataLifecycleStatsResponse> async getDataLifecycleStats (this: That, params?: T.IndicesGetDataLifecycleStatsRequest, options?: TransportRequestOptions): Promise<any> { - const acceptedPath: string[] = [] + const { + path: acceptedPath + } = this.acceptedParams['indices.get_data_lifecycle_stats'] + const userQuery = params?.querystring const querystring: Record<string, any> = userQuery != null ? { ...userQuery } : {} @@ -1389,7 +2336,10 @@ export default class Indices { async getDataStream (this: That, params?: T.IndicesGetDataStreamRequest, options?: TransportRequestOptionsWithMeta): Promise<TransportResult<T.IndicesGetDataStreamResponse, unknown>> async getDataStream (this: That, params?: T.IndicesGetDataStreamRequest, options?: TransportRequestOptions): Promise<T.IndicesGetDataStreamResponse> async getDataStream (this: That, params?: T.IndicesGetDataStreamRequest, options?: TransportRequestOptions): Promise<any> { - const acceptedPath: string[] = ['name'] + const { + path: acceptedPath + } = this.acceptedParams['indices.get_data_stream'] + const userQuery = params?.querystring const querystring: Record<string, any> = userQuery != null ? { ...userQuery } : {} @@ -1439,7 +2389,10 @@ export default class Indices { async getFieldMapping (this: That, params: T.IndicesGetFieldMappingRequest, options?: TransportRequestOptionsWithMeta): Promise<TransportResult<T.IndicesGetFieldMappingResponse, unknown>> async getFieldMapping (this: That, params: T.IndicesGetFieldMappingRequest, options?: TransportRequestOptions): Promise<T.IndicesGetFieldMappingResponse> async getFieldMapping (this: That, params: T.IndicesGetFieldMappingRequest, options?: TransportRequestOptions): Promise<any> { - const acceptedPath: string[] = ['fields', 'index'] + const { + path: acceptedPath + } = this.acceptedParams['indices.get_field_mapping'] + const userQuery = params?.querystring const querystring: Record<string, any> = userQuery != null ? { ...userQuery } : {} @@ -1489,7 +2442,10 @@ export default class Indices { async getIndexTemplate (this: That, params?: T.IndicesGetIndexTemplateRequest, options?: TransportRequestOptionsWithMeta): Promise<TransportResult<T.IndicesGetIndexTemplateResponse, unknown>> async getIndexTemplate (this: That, params?: T.IndicesGetIndexTemplateRequest, options?: TransportRequestOptions): Promise<T.IndicesGetIndexTemplateResponse> async getIndexTemplate (this: That, params?: T.IndicesGetIndexTemplateRequest, options?: TransportRequestOptions): Promise<any> { - const acceptedPath: string[] = ['name'] + const { + path: acceptedPath + } = this.acceptedParams['indices.get_index_template'] + const userQuery = params?.querystring const querystring: Record<string, any> = userQuery != null ? { ...userQuery } : {} @@ -1539,7 +2495,10 @@ export default class Indices { async getMapping (this: That, params?: T.IndicesGetMappingRequest, options?: TransportRequestOptionsWithMeta): Promise<TransportResult<T.IndicesGetMappingResponse, unknown>> async getMapping (this: That, params?: T.IndicesGetMappingRequest, options?: TransportRequestOptions): Promise<T.IndicesGetMappingResponse> async getMapping (this: That, params?: T.IndicesGetMappingRequest, options?: TransportRequestOptions): Promise<any> { - const acceptedPath: string[] = ['index'] + const { + path: acceptedPath + } = this.acceptedParams['indices.get_mapping'] + const userQuery = params?.querystring const querystring: Record<string, any> = userQuery != null ? { ...userQuery } : {} @@ -1589,7 +2548,10 @@ export default class Indices { async getMigrateReindexStatus (this: That, params: T.IndicesGetMigrateReindexStatusRequest, options?: TransportRequestOptionsWithMeta): Promise<TransportResult<T.IndicesGetMigrateReindexStatusResponse, unknown>> async getMigrateReindexStatus (this: That, params: T.IndicesGetMigrateReindexStatusRequest, options?: TransportRequestOptions): Promise<T.IndicesGetMigrateReindexStatusResponse> async getMigrateReindexStatus (this: That, params: T.IndicesGetMigrateReindexStatusRequest, options?: TransportRequestOptions): Promise<any> { - const acceptedPath: string[] = ['index'] + const { + path: acceptedPath + } = this.acceptedParams['indices.get_migrate_reindex_status'] + const userQuery = params?.querystring const querystring: Record<string, any> = userQuery != null ? { ...userQuery } : {} @@ -1631,7 +2593,10 @@ export default class Indices { async getSettings (this: That, params?: T.IndicesGetSettingsRequest, options?: TransportRequestOptionsWithMeta): Promise<TransportResult<T.IndicesGetSettingsResponse, unknown>> async getSettings (this: That, params?: T.IndicesGetSettingsRequest, options?: TransportRequestOptions): Promise<T.IndicesGetSettingsResponse> async getSettings (this: That, params?: T.IndicesGetSettingsRequest, options?: TransportRequestOptions): Promise<any> { - const acceptedPath: string[] = ['index', 'name'] + const { + path: acceptedPath + } = this.acceptedParams['indices.get_settings'] + const userQuery = params?.querystring const querystring: Record<string, any> = userQuery != null ? { ...userQuery } : {} @@ -1688,7 +2653,10 @@ export default class Indices { async getTemplate (this: That, params?: T.IndicesGetTemplateRequest, options?: TransportRequestOptionsWithMeta): Promise<TransportResult<T.IndicesGetTemplateResponse, unknown>> async getTemplate (this: That, params?: T.IndicesGetTemplateRequest, options?: TransportRequestOptions): Promise<T.IndicesGetTemplateResponse> async getTemplate (this: That, params?: T.IndicesGetTemplateRequest, options?: TransportRequestOptions): Promise<any> { - const acceptedPath: string[] = ['name'] + const { + path: acceptedPath + } = this.acceptedParams['indices.get_template'] + const userQuery = params?.querystring const querystring: Record<string, any> = userQuery != null ? { ...userQuery } : {} @@ -1738,8 +2706,12 @@ export default class Indices { async migrateReindex (this: That, params: T.IndicesMigrateReindexRequest, options?: TransportRequestOptionsWithMeta): Promise<TransportResult<T.IndicesMigrateReindexResponse, unknown>> async migrateReindex (this: That, params: T.IndicesMigrateReindexRequest, options?: TransportRequestOptions): Promise<T.IndicesMigrateReindexResponse> async migrateReindex (this: That, params: T.IndicesMigrateReindexRequest, options?: TransportRequestOptions): Promise<any> { - const acceptedPath: string[] = [] - const acceptedBody: string[] = ['reindex'] + const { + path: acceptedPath, + body: acceptedBody, + query: acceptedQuery + } = this.acceptedParams['indices.migrate_reindex'] + const userQuery = params?.querystring const querystring: Record<string, any> = userQuery != null ? { ...userQuery } : {} @@ -1751,8 +2723,14 @@ export default class Indices { } else if (acceptedPath.includes(key)) { continue } else if (key !== 'body' && key !== 'querystring') { - // @ts-expect-error - querystring[key] = params[key] + if (acceptedQuery.includes(key) || commonQueryParams.includes(key)) { + // @ts-expect-error + querystring[key] = params[key] + } else { + body = body ?? {} + // @ts-expect-error + body[key] = params[key] + } } } @@ -1772,7 +2750,10 @@ export default class Indices { async migrateToDataStream (this: That, params: T.IndicesMigrateToDataStreamRequest, options?: TransportRequestOptionsWithMeta): Promise<TransportResult<T.IndicesMigrateToDataStreamResponse, unknown>> async migrateToDataStream (this: That, params: T.IndicesMigrateToDataStreamRequest, options?: TransportRequestOptions): Promise<T.IndicesMigrateToDataStreamResponse> async migrateToDataStream (this: That, params: T.IndicesMigrateToDataStreamRequest, options?: TransportRequestOptions): Promise<any> { - const acceptedPath: string[] = ['name'] + const { + path: acceptedPath + } = this.acceptedParams['indices.migrate_to_data_stream'] + const userQuery = params?.querystring const querystring: Record<string, any> = userQuery != null ? { ...userQuery } : {} @@ -1814,8 +2795,12 @@ export default class Indices { async modifyDataStream (this: That, params: T.IndicesModifyDataStreamRequest, options?: TransportRequestOptionsWithMeta): Promise<TransportResult<T.IndicesModifyDataStreamResponse, unknown>> async modifyDataStream (this: That, params: T.IndicesModifyDataStreamRequest, options?: TransportRequestOptions): Promise<T.IndicesModifyDataStreamResponse> async modifyDataStream (this: That, params: T.IndicesModifyDataStreamRequest, options?: TransportRequestOptions): Promise<any> { - const acceptedPath: string[] = [] - const acceptedBody: string[] = ['actions'] + const { + path: acceptedPath, + body: acceptedBody, + query: acceptedQuery + } = this.acceptedParams['indices.modify_data_stream'] + const userQuery = params?.querystring const querystring: Record<string, any> = userQuery != null ? { ...userQuery } : {} @@ -1837,8 +2822,14 @@ export default class Indices { } else if (acceptedPath.includes(key)) { continue } else if (key !== 'body' && key !== 'querystring') { - // @ts-expect-error - querystring[key] = params[key] + if (acceptedQuery.includes(key) || commonQueryParams.includes(key)) { + // @ts-expect-error + querystring[key] = params[key] + } else { + body = body ?? {} + // @ts-expect-error + body[key] = params[key] + } } } @@ -1858,7 +2849,10 @@ export default class Indices { async open (this: That, params: T.IndicesOpenRequest, options?: TransportRequestOptionsWithMeta): Promise<TransportResult<T.IndicesOpenResponse, unknown>> async open (this: That, params: T.IndicesOpenRequest, options?: TransportRequestOptions): Promise<T.IndicesOpenResponse> async open (this: That, params: T.IndicesOpenRequest, options?: TransportRequestOptions): Promise<any> { - const acceptedPath: string[] = ['index'] + const { + path: acceptedPath + } = this.acceptedParams['indices.open'] + const userQuery = params?.querystring const querystring: Record<string, any> = userQuery != null ? { ...userQuery } : {} @@ -1900,7 +2894,10 @@ export default class Indices { async promoteDataStream (this: That, params: T.IndicesPromoteDataStreamRequest, options?: TransportRequestOptionsWithMeta): Promise<TransportResult<T.IndicesPromoteDataStreamResponse, unknown>> async promoteDataStream (this: That, params: T.IndicesPromoteDataStreamRequest, options?: TransportRequestOptions): Promise<T.IndicesPromoteDataStreamResponse> async promoteDataStream (this: That, params: T.IndicesPromoteDataStreamRequest, options?: TransportRequestOptions): Promise<any> { - const acceptedPath: string[] = ['name'] + const { + path: acceptedPath + } = this.acceptedParams['indices.promote_data_stream'] + const userQuery = params?.querystring const querystring: Record<string, any> = userQuery != null ? { ...userQuery } : {} @@ -1942,8 +2939,12 @@ export default class Indices { async putAlias (this: That, params: T.IndicesPutAliasRequest, options?: TransportRequestOptionsWithMeta): Promise<TransportResult<T.IndicesPutAliasResponse, unknown>> async putAlias (this: That, params: T.IndicesPutAliasRequest, options?: TransportRequestOptions): Promise<T.IndicesPutAliasResponse> async putAlias (this: That, params: T.IndicesPutAliasRequest, options?: TransportRequestOptions): Promise<any> { - const acceptedPath: string[] = ['index', 'name'] - const acceptedBody: string[] = ['filter', 'index_routing', 'is_write_index', 'routing', 'search_routing'] + const { + path: acceptedPath, + body: acceptedBody, + query: acceptedQuery + } = this.acceptedParams['indices.put_alias'] + const userQuery = params?.querystring const querystring: Record<string, any> = userQuery != null ? { ...userQuery } : {} @@ -1965,8 +2966,14 @@ export default class Indices { } else if (acceptedPath.includes(key)) { continue } else if (key !== 'body' && key !== 'querystring') { - // @ts-expect-error - querystring[key] = params[key] + if (acceptedQuery.includes(key) || commonQueryParams.includes(key)) { + // @ts-expect-error + querystring[key] = params[key] + } else { + body = body ?? {} + // @ts-expect-error + body[key] = params[key] + } } } @@ -1997,8 +3004,12 @@ export default class Indices { async putDataLifecycle (this: That, params: T.IndicesPutDataLifecycleRequest, options?: TransportRequestOptionsWithMeta): Promise<TransportResult<T.IndicesPutDataLifecycleResponse, unknown>> async putDataLifecycle (this: That, params: T.IndicesPutDataLifecycleRequest, options?: TransportRequestOptions): Promise<T.IndicesPutDataLifecycleResponse> async putDataLifecycle (this: That, params: T.IndicesPutDataLifecycleRequest, options?: TransportRequestOptions): Promise<any> { - const acceptedPath: string[] = ['name'] - const acceptedBody: string[] = ['data_retention', 'downsampling', 'enabled'] + const { + path: acceptedPath, + body: acceptedBody, + query: acceptedQuery + } = this.acceptedParams['indices.put_data_lifecycle'] + const userQuery = params?.querystring const querystring: Record<string, any> = userQuery != null ? { ...userQuery } : {} @@ -2020,8 +3031,14 @@ export default class Indices { } else if (acceptedPath.includes(key)) { continue } else if (key !== 'body' && key !== 'querystring') { - // @ts-expect-error - querystring[key] = params[key] + if (acceptedQuery.includes(key) || commonQueryParams.includes(key)) { + // @ts-expect-error + querystring[key] = params[key] + } else { + body = body ?? {} + // @ts-expect-error + body[key] = params[key] + } } } @@ -2044,8 +3061,12 @@ export default class Indices { async putIndexTemplate (this: That, params: T.IndicesPutIndexTemplateRequest, options?: TransportRequestOptionsWithMeta): Promise<TransportResult<T.IndicesPutIndexTemplateResponse, unknown>> async putIndexTemplate (this: That, params: T.IndicesPutIndexTemplateRequest, options?: TransportRequestOptions): Promise<T.IndicesPutIndexTemplateResponse> async putIndexTemplate (this: That, params: T.IndicesPutIndexTemplateRequest, options?: TransportRequestOptions): Promise<any> { - const acceptedPath: string[] = ['name'] - const acceptedBody: string[] = ['index_patterns', 'composed_of', 'template', 'data_stream', 'priority', 'version', '_meta', 'allow_auto_create', 'ignore_missing_component_templates', 'deprecated'] + const { + path: acceptedPath, + body: acceptedBody, + query: acceptedQuery + } = this.acceptedParams['indices.put_index_template'] + const userQuery = params?.querystring const querystring: Record<string, any> = userQuery != null ? { ...userQuery } : {} @@ -2067,8 +3088,14 @@ export default class Indices { } else if (acceptedPath.includes(key)) { continue } else if (key !== 'body' && key !== 'querystring') { - // @ts-expect-error - querystring[key] = params[key] + if (acceptedQuery.includes(key) || commonQueryParams.includes(key)) { + // @ts-expect-error + querystring[key] = params[key] + } else { + body = body ?? {} + // @ts-expect-error + body[key] = params[key] + } } } @@ -2091,8 +3118,12 @@ export default class Indices { async putMapping (this: That, params: T.IndicesPutMappingRequest, options?: TransportRequestOptionsWithMeta): Promise<TransportResult<T.IndicesPutMappingResponse, unknown>> async putMapping (this: That, params: T.IndicesPutMappingRequest, options?: TransportRequestOptions): Promise<T.IndicesPutMappingResponse> async putMapping (this: That, params: T.IndicesPutMappingRequest, options?: TransportRequestOptions): Promise<any> { - const acceptedPath: string[] = ['index'] - const acceptedBody: string[] = ['date_detection', 'dynamic', 'dynamic_date_formats', 'dynamic_templates', '_field_names', '_meta', 'numeric_detection', 'properties', '_routing', '_source', 'runtime'] + const { + path: acceptedPath, + body: acceptedBody, + query: acceptedQuery + } = this.acceptedParams['indices.put_mapping'] + const userQuery = params?.querystring const querystring: Record<string, any> = userQuery != null ? { ...userQuery } : {} @@ -2114,8 +3145,14 @@ export default class Indices { } else if (acceptedPath.includes(key)) { continue } else if (key !== 'body' && key !== 'querystring') { - // @ts-expect-error - querystring[key] = params[key] + if (acceptedQuery.includes(key) || commonQueryParams.includes(key)) { + // @ts-expect-error + querystring[key] = params[key] + } else { + body = body ?? {} + // @ts-expect-error + body[key] = params[key] + } } } @@ -2138,8 +3175,12 @@ export default class Indices { async putSettings (this: That, params: T.IndicesPutSettingsRequest, options?: TransportRequestOptionsWithMeta): Promise<TransportResult<T.IndicesPutSettingsResponse, unknown>> async putSettings (this: That, params: T.IndicesPutSettingsRequest, options?: TransportRequestOptions): Promise<T.IndicesPutSettingsResponse> async putSettings (this: That, params: T.IndicesPutSettingsRequest, options?: TransportRequestOptions): Promise<any> { - const acceptedPath: string[] = ['index'] - const acceptedBody: string[] = ['settings'] + const { + path: acceptedPath, + body: acceptedBody, + query: acceptedQuery + } = this.acceptedParams['indices.put_settings'] + const userQuery = params?.querystring const querystring: Record<string, any> = userQuery != null ? { ...userQuery } : {} @@ -2151,8 +3192,14 @@ export default class Indices { } else if (acceptedPath.includes(key)) { continue } else if (key !== 'body' && key !== 'querystring') { - // @ts-expect-error - querystring[key] = params[key] + if (acceptedQuery.includes(key) || commonQueryParams.includes(key)) { + // @ts-expect-error + querystring[key] = params[key] + } else { + body = body ?? {} + // @ts-expect-error + body[key] = params[key] + } } } @@ -2182,8 +3229,12 @@ export default class Indices { async putTemplate (this: That, params: T.IndicesPutTemplateRequest, options?: TransportRequestOptionsWithMeta): Promise<TransportResult<T.IndicesPutTemplateResponse, unknown>> async putTemplate (this: That, params: T.IndicesPutTemplateRequest, options?: TransportRequestOptions): Promise<T.IndicesPutTemplateResponse> async putTemplate (this: That, params: T.IndicesPutTemplateRequest, options?: TransportRequestOptions): Promise<any> { - const acceptedPath: string[] = ['name'] - const acceptedBody: string[] = ['aliases', 'index_patterns', 'mappings', 'order', 'settings', 'version'] + const { + path: acceptedPath, + body: acceptedBody, + query: acceptedQuery + } = this.acceptedParams['indices.put_template'] + const userQuery = params?.querystring const querystring: Record<string, any> = userQuery != null ? { ...userQuery } : {} @@ -2205,8 +3256,14 @@ export default class Indices { } else if (acceptedPath.includes(key)) { continue } else if (key !== 'body' && key !== 'querystring') { - // @ts-expect-error - querystring[key] = params[key] + if (acceptedQuery.includes(key) || commonQueryParams.includes(key)) { + // @ts-expect-error + querystring[key] = params[key] + } else { + body = body ?? {} + // @ts-expect-error + body[key] = params[key] + } } } @@ -2229,7 +3286,10 @@ export default class Indices { async recovery (this: That, params?: T.IndicesRecoveryRequest, options?: TransportRequestOptionsWithMeta): Promise<TransportResult<T.IndicesRecoveryResponse, unknown>> async recovery (this: That, params?: T.IndicesRecoveryRequest, options?: TransportRequestOptions): Promise<T.IndicesRecoveryResponse> async recovery (this: That, params?: T.IndicesRecoveryRequest, options?: TransportRequestOptions): Promise<any> { - const acceptedPath: string[] = ['index'] + const { + path: acceptedPath + } = this.acceptedParams['indices.recovery'] + const userQuery = params?.querystring const querystring: Record<string, any> = userQuery != null ? { ...userQuery } : {} @@ -2279,7 +3339,10 @@ export default class Indices { async refresh (this: That, params?: T.IndicesRefreshRequest, options?: TransportRequestOptionsWithMeta): Promise<TransportResult<T.IndicesRefreshResponse, unknown>> async refresh (this: That, params?: T.IndicesRefreshRequest, options?: TransportRequestOptions): Promise<T.IndicesRefreshResponse> async refresh (this: That, params?: T.IndicesRefreshRequest, options?: TransportRequestOptions): Promise<any> { - const acceptedPath: string[] = ['index'] + const { + path: acceptedPath + } = this.acceptedParams['indices.refresh'] + const userQuery = params?.querystring const querystring: Record<string, any> = userQuery != null ? { ...userQuery } : {} @@ -2329,7 +3392,10 @@ export default class Indices { async reloadSearchAnalyzers (this: That, params: T.IndicesReloadSearchAnalyzersRequest, options?: TransportRequestOptionsWithMeta): Promise<TransportResult<T.IndicesReloadSearchAnalyzersResponse, unknown>> async reloadSearchAnalyzers (this: That, params: T.IndicesReloadSearchAnalyzersRequest, options?: TransportRequestOptions): Promise<T.IndicesReloadSearchAnalyzersResponse> async reloadSearchAnalyzers (this: That, params: T.IndicesReloadSearchAnalyzersRequest, options?: TransportRequestOptions): Promise<any> { - const acceptedPath: string[] = ['index'] + const { + path: acceptedPath + } = this.acceptedParams['indices.reload_search_analyzers'] + const userQuery = params?.querystring const querystring: Record<string, any> = userQuery != null ? { ...userQuery } : {} @@ -2371,7 +3437,10 @@ export default class Indices { async resolveCluster (this: That, params?: T.IndicesResolveClusterRequest, options?: TransportRequestOptionsWithMeta): Promise<TransportResult<T.IndicesResolveClusterResponse, unknown>> async resolveCluster (this: That, params?: T.IndicesResolveClusterRequest, options?: TransportRequestOptions): Promise<T.IndicesResolveClusterResponse> async resolveCluster (this: That, params?: T.IndicesResolveClusterRequest, options?: TransportRequestOptions): Promise<any> { - const acceptedPath: string[] = ['name'] + const { + path: acceptedPath + } = this.acceptedParams['indices.resolve_cluster'] + const userQuery = params?.querystring const querystring: Record<string, any> = userQuery != null ? { ...userQuery } : {} @@ -2421,7 +3490,10 @@ export default class Indices { async resolveIndex (this: That, params: T.IndicesResolveIndexRequest, options?: TransportRequestOptionsWithMeta): Promise<TransportResult<T.IndicesResolveIndexResponse, unknown>> async resolveIndex (this: That, params: T.IndicesResolveIndexRequest, options?: TransportRequestOptions): Promise<T.IndicesResolveIndexResponse> async resolveIndex (this: That, params: T.IndicesResolveIndexRequest, options?: TransportRequestOptions): Promise<any> { - const acceptedPath: string[] = ['name'] + const { + path: acceptedPath + } = this.acceptedParams['indices.resolve_index'] + const userQuery = params?.querystring const querystring: Record<string, any> = userQuery != null ? { ...userQuery } : {} @@ -2463,8 +3535,12 @@ export default class Indices { async rollover (this: That, params: T.IndicesRolloverRequest, options?: TransportRequestOptionsWithMeta): Promise<TransportResult<T.IndicesRolloverResponse, unknown>> async rollover (this: That, params: T.IndicesRolloverRequest, options?: TransportRequestOptions): Promise<T.IndicesRolloverResponse> async rollover (this: That, params: T.IndicesRolloverRequest, options?: TransportRequestOptions): Promise<any> { - const acceptedPath: string[] = ['alias', 'new_index'] - const acceptedBody: string[] = ['aliases', 'conditions', 'mappings', 'settings'] + const { + path: acceptedPath, + body: acceptedBody, + query: acceptedQuery + } = this.acceptedParams['indices.rollover'] + const userQuery = params?.querystring const querystring: Record<string, any> = userQuery != null ? { ...userQuery } : {} @@ -2486,8 +3562,14 @@ export default class Indices { } else if (acceptedPath.includes(key)) { continue } else if (key !== 'body' && key !== 'querystring') { - // @ts-expect-error - querystring[key] = params[key] + if (acceptedQuery.includes(key) || commonQueryParams.includes(key)) { + // @ts-expect-error + querystring[key] = params[key] + } else { + body = body ?? {} + // @ts-expect-error + body[key] = params[key] + } } } @@ -2518,7 +3600,10 @@ export default class Indices { async segments (this: That, params?: T.IndicesSegmentsRequest, options?: TransportRequestOptionsWithMeta): Promise<TransportResult<T.IndicesSegmentsResponse, unknown>> async segments (this: That, params?: T.IndicesSegmentsRequest, options?: TransportRequestOptions): Promise<T.IndicesSegmentsResponse> async segments (this: That, params?: T.IndicesSegmentsRequest, options?: TransportRequestOptions): Promise<any> { - const acceptedPath: string[] = ['index'] + const { + path: acceptedPath + } = this.acceptedParams['indices.segments'] + const userQuery = params?.querystring const querystring: Record<string, any> = userQuery != null ? { ...userQuery } : {} @@ -2568,7 +3653,10 @@ export default class Indices { async shardStores (this: That, params?: T.IndicesShardStoresRequest, options?: TransportRequestOptionsWithMeta): Promise<TransportResult<T.IndicesShardStoresResponse, unknown>> async shardStores (this: That, params?: T.IndicesShardStoresRequest, options?: TransportRequestOptions): Promise<T.IndicesShardStoresResponse> async shardStores (this: That, params?: T.IndicesShardStoresRequest, options?: TransportRequestOptions): Promise<any> { - const acceptedPath: string[] = ['index'] + const { + path: acceptedPath + } = this.acceptedParams['indices.shard_stores'] + const userQuery = params?.querystring const querystring: Record<string, any> = userQuery != null ? { ...userQuery } : {} @@ -2618,8 +3706,12 @@ export default class Indices { async shrink (this: That, params: T.IndicesShrinkRequest, options?: TransportRequestOptionsWithMeta): Promise<TransportResult<T.IndicesShrinkResponse, unknown>> async shrink (this: That, params: T.IndicesShrinkRequest, options?: TransportRequestOptions): Promise<T.IndicesShrinkResponse> async shrink (this: That, params: T.IndicesShrinkRequest, options?: TransportRequestOptions): Promise<any> { - const acceptedPath: string[] = ['index', 'target'] - const acceptedBody: string[] = ['aliases', 'settings'] + const { + path: acceptedPath, + body: acceptedBody, + query: acceptedQuery + } = this.acceptedParams['indices.shrink'] + const userQuery = params?.querystring const querystring: Record<string, any> = userQuery != null ? { ...userQuery } : {} @@ -2641,8 +3733,14 @@ export default class Indices { } else if (acceptedPath.includes(key)) { continue } else if (key !== 'body' && key !== 'querystring') { - // @ts-expect-error - querystring[key] = params[key] + if (acceptedQuery.includes(key) || commonQueryParams.includes(key)) { + // @ts-expect-error + querystring[key] = params[key] + } else { + body = body ?? {} + // @ts-expect-error + body[key] = params[key] + } } } @@ -2666,7 +3764,10 @@ export default class Indices { async simulateIndexTemplate (this: That, params: T.IndicesSimulateIndexTemplateRequest, options?: TransportRequestOptionsWithMeta): Promise<TransportResult<T.IndicesSimulateIndexTemplateResponse, unknown>> async simulateIndexTemplate (this: That, params: T.IndicesSimulateIndexTemplateRequest, options?: TransportRequestOptions): Promise<T.IndicesSimulateIndexTemplateResponse> async simulateIndexTemplate (this: That, params: T.IndicesSimulateIndexTemplateRequest, options?: TransportRequestOptions): Promise<any> { - const acceptedPath: string[] = ['name'] + const { + path: acceptedPath + } = this.acceptedParams['indices.simulate_index_template'] + const userQuery = params?.querystring const querystring: Record<string, any> = userQuery != null ? { ...userQuery } : {} @@ -2708,8 +3809,12 @@ export default class Indices { async simulateTemplate (this: That, params?: T.IndicesSimulateTemplateRequest, options?: TransportRequestOptionsWithMeta): Promise<TransportResult<T.IndicesSimulateTemplateResponse, unknown>> async simulateTemplate (this: That, params?: T.IndicesSimulateTemplateRequest, options?: TransportRequestOptions): Promise<T.IndicesSimulateTemplateResponse> async simulateTemplate (this: That, params?: T.IndicesSimulateTemplateRequest, options?: TransportRequestOptions): Promise<any> { - const acceptedPath: string[] = ['name'] - const acceptedBody: string[] = ['allow_auto_create', 'index_patterns', 'composed_of', 'template', 'data_stream', 'priority', 'version', '_meta', 'ignore_missing_component_templates', 'deprecated'] + const { + path: acceptedPath, + body: acceptedBody, + query: acceptedQuery + } = this.acceptedParams['indices.simulate_template'] + const userQuery = params?.querystring const querystring: Record<string, any> = userQuery != null ? { ...userQuery } : {} @@ -2732,8 +3837,14 @@ export default class Indices { } else if (acceptedPath.includes(key)) { continue } else if (key !== 'body' && key !== 'querystring') { - // @ts-expect-error - querystring[key] = params[key] + if (acceptedQuery.includes(key) || commonQueryParams.includes(key)) { + // @ts-expect-error + querystring[key] = params[key] + } else { + body = body ?? {} + // @ts-expect-error + body[key] = params[key] + } } } @@ -2763,8 +3874,12 @@ export default class Indices { async split (this: That, params: T.IndicesSplitRequest, options?: TransportRequestOptionsWithMeta): Promise<TransportResult<T.IndicesSplitResponse, unknown>> async split (this: That, params: T.IndicesSplitRequest, options?: TransportRequestOptions): Promise<T.IndicesSplitResponse> async split (this: That, params: T.IndicesSplitRequest, options?: TransportRequestOptions): Promise<any> { - const acceptedPath: string[] = ['index', 'target'] - const acceptedBody: string[] = ['aliases', 'settings'] + const { + path: acceptedPath, + body: acceptedBody, + query: acceptedQuery + } = this.acceptedParams['indices.split'] + const userQuery = params?.querystring const querystring: Record<string, any> = userQuery != null ? { ...userQuery } : {} @@ -2786,8 +3901,14 @@ export default class Indices { } else if (acceptedPath.includes(key)) { continue } else if (key !== 'body' && key !== 'querystring') { - // @ts-expect-error - querystring[key] = params[key] + if (acceptedQuery.includes(key) || commonQueryParams.includes(key)) { + // @ts-expect-error + querystring[key] = params[key] + } else { + body = body ?? {} + // @ts-expect-error + body[key] = params[key] + } } } @@ -2811,7 +3932,10 @@ export default class Indices { async stats (this: That, params?: T.IndicesStatsRequest, options?: TransportRequestOptionsWithMeta): Promise<TransportResult<T.IndicesStatsResponse, unknown>> async stats (this: That, params?: T.IndicesStatsRequest, options?: TransportRequestOptions): Promise<T.IndicesStatsResponse> async stats (this: That, params?: T.IndicesStatsRequest, options?: TransportRequestOptions): Promise<any> { - const acceptedPath: string[] = ['metric', 'index'] + const { + path: acceptedPath + } = this.acceptedParams['indices.stats'] + const userQuery = params?.querystring const querystring: Record<string, any> = userQuery != null ? { ...userQuery } : {} @@ -2868,8 +3992,12 @@ export default class Indices { async updateAliases (this: That, params?: T.IndicesUpdateAliasesRequest, options?: TransportRequestOptionsWithMeta): Promise<TransportResult<T.IndicesUpdateAliasesResponse, unknown>> async updateAliases (this: That, params?: T.IndicesUpdateAliasesRequest, options?: TransportRequestOptions): Promise<T.IndicesUpdateAliasesResponse> async updateAliases (this: That, params?: T.IndicesUpdateAliasesRequest, options?: TransportRequestOptions): Promise<any> { - const acceptedPath: string[] = [] - const acceptedBody: string[] = ['actions'] + const { + path: acceptedPath, + body: acceptedBody, + query: acceptedQuery + } = this.acceptedParams['indices.update_aliases'] + const userQuery = params?.querystring const querystring: Record<string, any> = userQuery != null ? { ...userQuery } : {} @@ -2892,8 +4020,14 @@ export default class Indices { } else if (acceptedPath.includes(key)) { continue } else if (key !== 'body' && key !== 'querystring') { - // @ts-expect-error - querystring[key] = params[key] + if (acceptedQuery.includes(key) || commonQueryParams.includes(key)) { + // @ts-expect-error + querystring[key] = params[key] + } else { + body = body ?? {} + // @ts-expect-error + body[key] = params[key] + } } } @@ -2913,8 +4047,12 @@ export default class Indices { async validateQuery (this: That, params?: T.IndicesValidateQueryRequest, options?: TransportRequestOptionsWithMeta): Promise<TransportResult<T.IndicesValidateQueryResponse, unknown>> async validateQuery (this: That, params?: T.IndicesValidateQueryRequest, options?: TransportRequestOptions): Promise<T.IndicesValidateQueryResponse> async validateQuery (this: That, params?: T.IndicesValidateQueryRequest, options?: TransportRequestOptions): Promise<any> { - const acceptedPath: string[] = ['index'] - const acceptedBody: string[] = ['query'] + const { + path: acceptedPath, + body: acceptedBody, + query: acceptedQuery + } = this.acceptedParams['indices.validate_query'] + const userQuery = params?.querystring const querystring: Record<string, any> = userQuery != null ? { ...userQuery } : {} @@ -2937,8 +4075,14 @@ export default class Indices { } else if (acceptedPath.includes(key)) { continue } else if (key !== 'body' && key !== 'querystring') { - // @ts-expect-error - querystring[key] = params[key] + if (acceptedQuery.includes(key) || commonQueryParams.includes(key)) { + // @ts-expect-error + querystring[key] = params[key] + } else { + body = body ?? {} + // @ts-expect-error + body[key] = params[key] + } } } diff --git a/src/api/api/inference.ts b/src/api/api/inference.ts index b7c9fb55a..6b3309021 100644 --- a/src/api/api/inference.ts +++ b/src/api/api/inference.ts @@ -35,12 +35,103 @@ import { TransportResult } from '@elastic/transport' import * as T from '../types' -interface That { transport: Transport } + +interface That { + transport: Transport + acceptedParams: Record<string, { path: string[], body: string[], query: string[] }> +} + +const commonQueryParams = ['error_trace', 'filter_path', 'human', 'pretty'] export default class Inference { transport: Transport + acceptedParams: Record<string, { path: string[], body: string[], query: string[] }> constructor (transport: Transport) { this.transport = transport + this.acceptedParams = { + 'inference.delete': { + path: [ + 'task_type', + 'inference_id' + ], + body: [], + query: [ + 'dry_run', + 'force' + ] + }, + 'inference.get': { + path: [ + 'task_type', + 'inference_id' + ], + body: [], + query: [] + }, + 'inference.inference': { + path: [ + 'task_type', + 'inference_id' + ], + body: [ + 'query', + 'input', + 'task_settings' + ], + query: [ + 'timeout' + ] + }, + 'inference.put': { + path: [ + 'task_type', + 'inference_id' + ], + body: [ + 'inference_config' + ], + query: [] + }, + 'inference.stream_inference': { + path: [ + 'inference_id', + 'task_type' + ], + body: [ + 'input' + ], + query: [] + }, + 'inference.unified_inference': { + path: [ + 'task_type', + 'inference_id' + ], + body: [ + 'messages', + 'model', + 'max_completion_tokens', + 'stop', + 'temperature', + 'tool_choice', + 'tools', + 'top_p' + ], + query: [ + 'timeout' + ] + }, + 'inference.update': { + path: [ + 'inference_id', + 'task_type' + ], + body: [ + 'inference_config' + ], + query: [] + } + } } /** @@ -51,7 +142,10 @@ export default class Inference { async delete (this: That, params: T.InferenceDeleteRequest, options?: TransportRequestOptionsWithMeta): Promise<TransportResult<T.InferenceDeleteResponse, unknown>> async delete (this: That, params: T.InferenceDeleteRequest, options?: TransportRequestOptions): Promise<T.InferenceDeleteResponse> async delete (this: That, params: T.InferenceDeleteRequest, options?: TransportRequestOptions): Promise<any> { - const acceptedPath: string[] = ['task_type', 'inference_id'] + const { + path: acceptedPath + } = this.acceptedParams['inference.delete'] + const userQuery = params?.querystring const querystring: Record<string, any> = userQuery != null ? { ...userQuery } : {} @@ -101,7 +195,10 @@ export default class Inference { async get (this: That, params?: T.InferenceGetRequest, options?: TransportRequestOptionsWithMeta): Promise<TransportResult<T.InferenceGetResponse, unknown>> async get (this: That, params?: T.InferenceGetRequest, options?: TransportRequestOptions): Promise<T.InferenceGetResponse> async get (this: That, params?: T.InferenceGetRequest, options?: TransportRequestOptions): Promise<any> { - const acceptedPath: string[] = ['task_type', 'inference_id'] + const { + path: acceptedPath + } = this.acceptedParams['inference.get'] + const userQuery = params?.querystring const querystring: Record<string, any> = userQuery != null ? { ...userQuery } : {} @@ -155,8 +252,12 @@ export default class Inference { async inference (this: That, params: T.InferenceInferenceRequest, options?: TransportRequestOptionsWithMeta): Promise<TransportResult<T.InferenceInferenceResponse, unknown>> async inference (this: That, params: T.InferenceInferenceRequest, options?: TransportRequestOptions): Promise<T.InferenceInferenceResponse> async inference (this: That, params: T.InferenceInferenceRequest, options?: TransportRequestOptions): Promise<any> { - const acceptedPath: string[] = ['task_type', 'inference_id'] - const acceptedBody: string[] = ['query', 'input', 'task_settings'] + const { + path: acceptedPath, + body: acceptedBody, + query: acceptedQuery + } = this.acceptedParams['inference.inference'] + const userQuery = params?.querystring const querystring: Record<string, any> = userQuery != null ? { ...userQuery } : {} @@ -178,8 +279,14 @@ export default class Inference { } else if (acceptedPath.includes(key)) { continue } else if (key !== 'body' && key !== 'querystring') { - // @ts-expect-error - querystring[key] = params[key] + if (acceptedQuery.includes(key) || commonQueryParams.includes(key)) { + // @ts-expect-error + querystring[key] = params[key] + } else { + body = body ?? {} + // @ts-expect-error + body[key] = params[key] + } } } @@ -210,8 +317,12 @@ export default class Inference { async put (this: That, params: T.InferencePutRequest, options?: TransportRequestOptionsWithMeta): Promise<TransportResult<T.InferencePutResponse, unknown>> async put (this: That, params: T.InferencePutRequest, options?: TransportRequestOptions): Promise<T.InferencePutResponse> async put (this: That, params: T.InferencePutRequest, options?: TransportRequestOptions): Promise<any> { - const acceptedPath: string[] = ['task_type', 'inference_id'] - const acceptedBody: string[] = ['inference_config'] + const { + path: acceptedPath, + body: acceptedBody, + query: acceptedQuery + } = this.acceptedParams['inference.put'] + const userQuery = params?.querystring const querystring: Record<string, any> = userQuery != null ? { ...userQuery } : {} @@ -223,8 +334,14 @@ export default class Inference { } else if (acceptedPath.includes(key)) { continue } else if (key !== 'body' && key !== 'querystring') { - // @ts-expect-error - querystring[key] = params[key] + if (acceptedQuery.includes(key) || commonQueryParams.includes(key)) { + // @ts-expect-error + querystring[key] = params[key] + } else { + body = body ?? {} + // @ts-expect-error + body[key] = params[key] + } } } @@ -255,8 +372,12 @@ export default class Inference { async streamInference (this: That, params: T.InferenceStreamInferenceRequest, options?: TransportRequestOptionsWithMeta): Promise<TransportResult<T.InferenceStreamInferenceResponse, unknown>> async streamInference (this: That, params: T.InferenceStreamInferenceRequest, options?: TransportRequestOptions): Promise<T.InferenceStreamInferenceResponse> async streamInference (this: That, params: T.InferenceStreamInferenceRequest, options?: TransportRequestOptions): Promise<any> { - const acceptedPath: string[] = ['inference_id', 'task_type'] - const acceptedBody: string[] = ['input'] + const { + path: acceptedPath, + body: acceptedBody, + query: acceptedQuery + } = this.acceptedParams['inference.stream_inference'] + const userQuery = params?.querystring const querystring: Record<string, any> = userQuery != null ? { ...userQuery } : {} @@ -278,8 +399,14 @@ export default class Inference { } else if (acceptedPath.includes(key)) { continue } else if (key !== 'body' && key !== 'querystring') { - // @ts-expect-error - querystring[key] = params[key] + if (acceptedQuery.includes(key) || commonQueryParams.includes(key)) { + // @ts-expect-error + querystring[key] = params[key] + } else { + body = body ?? {} + // @ts-expect-error + body[key] = params[key] + } } } @@ -310,8 +437,12 @@ export default class Inference { async unifiedInference (this: That, params: T.InferenceUnifiedInferenceRequest, options?: TransportRequestOptionsWithMeta): Promise<TransportResult<T.InferenceUnifiedInferenceResponse, unknown>> async unifiedInference (this: That, params: T.InferenceUnifiedInferenceRequest, options?: TransportRequestOptions): Promise<T.InferenceUnifiedInferenceResponse> async unifiedInference (this: That, params: T.InferenceUnifiedInferenceRequest, options?: TransportRequestOptions): Promise<any> { - const acceptedPath: string[] = ['task_type', 'inference_id'] - const acceptedBody: string[] = ['messages', 'model', 'max_completion_tokens', 'stop', 'temperature', 'tool_choice', 'tools', 'top_p'] + const { + path: acceptedPath, + body: acceptedBody, + query: acceptedQuery + } = this.acceptedParams['inference.unified_inference'] + const userQuery = params?.querystring const querystring: Record<string, any> = userQuery != null ? { ...userQuery } : {} @@ -333,8 +464,14 @@ export default class Inference { } else if (acceptedPath.includes(key)) { continue } else if (key !== 'body' && key !== 'querystring') { - // @ts-expect-error - querystring[key] = params[key] + if (acceptedQuery.includes(key) || commonQueryParams.includes(key)) { + // @ts-expect-error + querystring[key] = params[key] + } else { + body = body ?? {} + // @ts-expect-error + body[key] = params[key] + } } } @@ -365,8 +502,12 @@ export default class Inference { async update (this: That, params: T.InferenceUpdateRequest, options?: TransportRequestOptionsWithMeta): Promise<TransportResult<T.InferenceUpdateResponse, unknown>> async update (this: That, params: T.InferenceUpdateRequest, options?: TransportRequestOptions): Promise<T.InferenceUpdateResponse> async update (this: That, params: T.InferenceUpdateRequest, options?: TransportRequestOptions): Promise<any> { - const acceptedPath: string[] = ['inference_id', 'task_type'] - const acceptedBody: string[] = ['inference_config'] + const { + path: acceptedPath, + body: acceptedBody, + query: acceptedQuery + } = this.acceptedParams['inference.update'] + const userQuery = params?.querystring const querystring: Record<string, any> = userQuery != null ? { ...userQuery } : {} @@ -378,8 +519,14 @@ export default class Inference { } else if (acceptedPath.includes(key)) { continue } else if (key !== 'body' && key !== 'querystring') { - // @ts-expect-error - querystring[key] = params[key] + if (acceptedQuery.includes(key) || commonQueryParams.includes(key)) { + // @ts-expect-error + querystring[key] = params[key] + } else { + body = body ?? {} + // @ts-expect-error + body[key] = params[key] + } } } diff --git a/src/api/api/info.ts b/src/api/api/info.ts index 1681fe6f3..ebbdb0fac 100644 --- a/src/api/api/info.ts +++ b/src/api/api/info.ts @@ -35,7 +35,18 @@ import { TransportResult } from '@elastic/transport' import * as T from '../types' -interface That { transport: Transport } + +interface That { + transport: Transport +} + +const acceptedParams: Record<string, { path: string[], body: string[], query: string[] }> = { + info: { + path: [], + body: [], + query: [] + } +} /** * Get cluster info. Get basic build, version, and cluster information. @@ -45,7 +56,10 @@ export default async function InfoApi (this: That, params?: T.InfoRequest, optio export default async function InfoApi (this: That, params?: T.InfoRequest, options?: TransportRequestOptionsWithMeta): Promise<TransportResult<T.InfoResponse, unknown>> export default async function InfoApi (this: That, params?: T.InfoRequest, options?: TransportRequestOptions): Promise<T.InfoResponse> export default async function InfoApi (this: That, params?: T.InfoRequest, options?: TransportRequestOptions): Promise<any> { - const acceptedPath: string[] = [] + const { + path: acceptedPath + } = acceptedParams.info + const userQuery = params?.querystring const querystring: Record<string, any> = userQuery != null ? { ...userQuery } : {} diff --git a/src/api/api/ingest.ts b/src/api/api/ingest.ts index 51ad39aff..502b4c0cf 100644 --- a/src/api/api/ingest.ts +++ b/src/api/api/ingest.ts @@ -35,12 +35,142 @@ import { TransportResult } from '@elastic/transport' import * as T from '../types' -interface That { transport: Transport } + +interface That { + transport: Transport + acceptedParams: Record<string, { path: string[], body: string[], query: string[] }> +} + +const commonQueryParams = ['error_trace', 'filter_path', 'human', 'pretty'] export default class Ingest { transport: Transport + acceptedParams: Record<string, { path: string[], body: string[], query: string[] }> constructor (transport: Transport) { this.transport = transport + this.acceptedParams = { + 'ingest.delete_geoip_database': { + path: [ + 'id' + ], + body: [], + query: [ + 'master_timeout', + 'timeout' + ] + }, + 'ingest.delete_ip_location_database': { + path: [ + 'id' + ], + body: [], + query: [ + 'master_timeout', + 'timeout' + ] + }, + 'ingest.delete_pipeline': { + path: [ + 'id' + ], + body: [], + query: [ + 'master_timeout', + 'timeout' + ] + }, + 'ingest.geo_ip_stats': { + path: [], + body: [], + query: [] + }, + 'ingest.get_geoip_database': { + path: [ + 'id' + ], + body: [], + query: [] + }, + 'ingest.get_ip_location_database': { + path: [ + 'id' + ], + body: [], + query: [ + 'master_timeout' + ] + }, + 'ingest.get_pipeline': { + path: [ + 'id' + ], + body: [], + query: [ + 'master_timeout', + 'summary' + ] + }, + 'ingest.processor_grok': { + path: [], + body: [], + query: [] + }, + 'ingest.put_geoip_database': { + path: [ + 'id' + ], + body: [ + 'name', + 'maxmind' + ], + query: [ + 'master_timeout', + 'timeout' + ] + }, + 'ingest.put_ip_location_database': { + path: [ + 'id' + ], + body: [ + 'configuration' + ], + query: [ + 'master_timeout', + 'timeout' + ] + }, + 'ingest.put_pipeline': { + path: [ + 'id' + ], + body: [ + '_meta', + 'description', + 'on_failure', + 'processors', + 'version', + 'deprecated' + ], + query: [ + 'master_timeout', + 'timeout', + 'if_version' + ] + }, + 'ingest.simulate': { + path: [ + 'id' + ], + body: [ + 'docs', + 'pipeline' + ], + query: [ + 'verbose' + ] + } + } } /** @@ -51,7 +181,10 @@ export default class Ingest { async deleteGeoipDatabase (this: That, params: T.IngestDeleteGeoipDatabaseRequest, options?: TransportRequestOptionsWithMeta): Promise<TransportResult<T.IngestDeleteGeoipDatabaseResponse, unknown>> async deleteGeoipDatabase (this: That, params: T.IngestDeleteGeoipDatabaseRequest, options?: TransportRequestOptions): Promise<T.IngestDeleteGeoipDatabaseResponse> async deleteGeoipDatabase (this: That, params: T.IngestDeleteGeoipDatabaseRequest, options?: TransportRequestOptions): Promise<any> { - const acceptedPath: string[] = ['id'] + const { + path: acceptedPath + } = this.acceptedParams['ingest.delete_geoip_database'] + const userQuery = params?.querystring const querystring: Record<string, any> = userQuery != null ? { ...userQuery } : {} @@ -93,7 +226,10 @@ export default class Ingest { async deleteIpLocationDatabase (this: That, params: T.IngestDeleteIpLocationDatabaseRequest, options?: TransportRequestOptionsWithMeta): Promise<TransportResult<T.IngestDeleteIpLocationDatabaseResponse, unknown>> async deleteIpLocationDatabase (this: That, params: T.IngestDeleteIpLocationDatabaseRequest, options?: TransportRequestOptions): Promise<T.IngestDeleteIpLocationDatabaseResponse> async deleteIpLocationDatabase (this: That, params: T.IngestDeleteIpLocationDatabaseRequest, options?: TransportRequestOptions): Promise<any> { - const acceptedPath: string[] = ['id'] + const { + path: acceptedPath + } = this.acceptedParams['ingest.delete_ip_location_database'] + const userQuery = params?.querystring const querystring: Record<string, any> = userQuery != null ? { ...userQuery } : {} @@ -135,7 +271,10 @@ export default class Ingest { async deletePipeline (this: That, params: T.IngestDeletePipelineRequest, options?: TransportRequestOptionsWithMeta): Promise<TransportResult<T.IngestDeletePipelineResponse, unknown>> async deletePipeline (this: That, params: T.IngestDeletePipelineRequest, options?: TransportRequestOptions): Promise<T.IngestDeletePipelineResponse> async deletePipeline (this: That, params: T.IngestDeletePipelineRequest, options?: TransportRequestOptions): Promise<any> { - const acceptedPath: string[] = ['id'] + const { + path: acceptedPath + } = this.acceptedParams['ingest.delete_pipeline'] + const userQuery = params?.querystring const querystring: Record<string, any> = userQuery != null ? { ...userQuery } : {} @@ -177,7 +316,10 @@ export default class Ingest { async geoIpStats (this: That, params?: T.IngestGeoIpStatsRequest, options?: TransportRequestOptionsWithMeta): Promise<TransportResult<T.IngestGeoIpStatsResponse, unknown>> async geoIpStats (this: That, params?: T.IngestGeoIpStatsRequest, options?: TransportRequestOptions): Promise<T.IngestGeoIpStatsResponse> async geoIpStats (this: That, params?: T.IngestGeoIpStatsRequest, options?: TransportRequestOptions): Promise<any> { - const acceptedPath: string[] = [] + const { + path: acceptedPath + } = this.acceptedParams['ingest.geo_ip_stats'] + const userQuery = params?.querystring const querystring: Record<string, any> = userQuery != null ? { ...userQuery } : {} @@ -217,7 +359,10 @@ export default class Ingest { async getGeoipDatabase (this: That, params?: T.IngestGetGeoipDatabaseRequest, options?: TransportRequestOptionsWithMeta): Promise<TransportResult<T.IngestGetGeoipDatabaseResponse, unknown>> async getGeoipDatabase (this: That, params?: T.IngestGetGeoipDatabaseRequest, options?: TransportRequestOptions): Promise<T.IngestGetGeoipDatabaseResponse> async getGeoipDatabase (this: That, params?: T.IngestGetGeoipDatabaseRequest, options?: TransportRequestOptions): Promise<any> { - const acceptedPath: string[] = ['id'] + const { + path: acceptedPath + } = this.acceptedParams['ingest.get_geoip_database'] + const userQuery = params?.querystring const querystring: Record<string, any> = userQuery != null ? { ...userQuery } : {} @@ -267,7 +412,10 @@ export default class Ingest { async getIpLocationDatabase (this: That, params?: T.IngestGetIpLocationDatabaseRequest, options?: TransportRequestOptionsWithMeta): Promise<TransportResult<T.IngestGetIpLocationDatabaseResponse, unknown>> async getIpLocationDatabase (this: That, params?: T.IngestGetIpLocationDatabaseRequest, options?: TransportRequestOptions): Promise<T.IngestGetIpLocationDatabaseResponse> async getIpLocationDatabase (this: That, params?: T.IngestGetIpLocationDatabaseRequest, options?: TransportRequestOptions): Promise<any> { - const acceptedPath: string[] = ['id'] + const { + path: acceptedPath + } = this.acceptedParams['ingest.get_ip_location_database'] + const userQuery = params?.querystring const querystring: Record<string, any> = userQuery != null ? { ...userQuery } : {} @@ -317,7 +465,10 @@ export default class Ingest { async getPipeline (this: That, params?: T.IngestGetPipelineRequest, options?: TransportRequestOptionsWithMeta): Promise<TransportResult<T.IngestGetPipelineResponse, unknown>> async getPipeline (this: That, params?: T.IngestGetPipelineRequest, options?: TransportRequestOptions): Promise<T.IngestGetPipelineResponse> async getPipeline (this: That, params?: T.IngestGetPipelineRequest, options?: TransportRequestOptions): Promise<any> { - const acceptedPath: string[] = ['id'] + const { + path: acceptedPath + } = this.acceptedParams['ingest.get_pipeline'] + const userQuery = params?.querystring const querystring: Record<string, any> = userQuery != null ? { ...userQuery } : {} @@ -367,7 +518,10 @@ export default class Ingest { async processorGrok (this: That, params?: T.IngestProcessorGrokRequest, options?: TransportRequestOptionsWithMeta): Promise<TransportResult<T.IngestProcessorGrokResponse, unknown>> async processorGrok (this: That, params?: T.IngestProcessorGrokRequest, options?: TransportRequestOptions): Promise<T.IngestProcessorGrokResponse> async processorGrok (this: That, params?: T.IngestProcessorGrokRequest, options?: TransportRequestOptions): Promise<any> { - const acceptedPath: string[] = [] + const { + path: acceptedPath + } = this.acceptedParams['ingest.processor_grok'] + const userQuery = params?.querystring const querystring: Record<string, any> = userQuery != null ? { ...userQuery } : {} @@ -407,8 +561,12 @@ export default class Ingest { async putGeoipDatabase (this: That, params: T.IngestPutGeoipDatabaseRequest, options?: TransportRequestOptionsWithMeta): Promise<TransportResult<T.IngestPutGeoipDatabaseResponse, unknown>> async putGeoipDatabase (this: That, params: T.IngestPutGeoipDatabaseRequest, options?: TransportRequestOptions): Promise<T.IngestPutGeoipDatabaseResponse> async putGeoipDatabase (this: That, params: T.IngestPutGeoipDatabaseRequest, options?: TransportRequestOptions): Promise<any> { - const acceptedPath: string[] = ['id'] - const acceptedBody: string[] = ['name', 'maxmind'] + const { + path: acceptedPath, + body: acceptedBody, + query: acceptedQuery + } = this.acceptedParams['ingest.put_geoip_database'] + const userQuery = params?.querystring const querystring: Record<string, any> = userQuery != null ? { ...userQuery } : {} @@ -430,8 +588,14 @@ export default class Ingest { } else if (acceptedPath.includes(key)) { continue } else if (key !== 'body' && key !== 'querystring') { - // @ts-expect-error - querystring[key] = params[key] + if (acceptedQuery.includes(key) || commonQueryParams.includes(key)) { + // @ts-expect-error + querystring[key] = params[key] + } else { + body = body ?? {} + // @ts-expect-error + body[key] = params[key] + } } } @@ -454,8 +618,12 @@ export default class Ingest { async putIpLocationDatabase (this: That, params: T.IngestPutIpLocationDatabaseRequest, options?: TransportRequestOptionsWithMeta): Promise<TransportResult<T.IngestPutIpLocationDatabaseResponse, unknown>> async putIpLocationDatabase (this: That, params: T.IngestPutIpLocationDatabaseRequest, options?: TransportRequestOptions): Promise<T.IngestPutIpLocationDatabaseResponse> async putIpLocationDatabase (this: That, params: T.IngestPutIpLocationDatabaseRequest, options?: TransportRequestOptions): Promise<any> { - const acceptedPath: string[] = ['id'] - const acceptedBody: string[] = ['configuration'] + const { + path: acceptedPath, + body: acceptedBody, + query: acceptedQuery + } = this.acceptedParams['ingest.put_ip_location_database'] + const userQuery = params?.querystring const querystring: Record<string, any> = userQuery != null ? { ...userQuery } : {} @@ -467,8 +635,14 @@ export default class Ingest { } else if (acceptedPath.includes(key)) { continue } else if (key !== 'body' && key !== 'querystring') { - // @ts-expect-error - querystring[key] = params[key] + if (acceptedQuery.includes(key) || commonQueryParams.includes(key)) { + // @ts-expect-error + querystring[key] = params[key] + } else { + body = body ?? {} + // @ts-expect-error + body[key] = params[key] + } } } @@ -491,8 +665,12 @@ export default class Ingest { async putPipeline (this: That, params: T.IngestPutPipelineRequest, options?: TransportRequestOptionsWithMeta): Promise<TransportResult<T.IngestPutPipelineResponse, unknown>> async putPipeline (this: That, params: T.IngestPutPipelineRequest, options?: TransportRequestOptions): Promise<T.IngestPutPipelineResponse> async putPipeline (this: That, params: T.IngestPutPipelineRequest, options?: TransportRequestOptions): Promise<any> { - const acceptedPath: string[] = ['id'] - const acceptedBody: string[] = ['_meta', 'description', 'on_failure', 'processors', 'version', 'deprecated'] + const { + path: acceptedPath, + body: acceptedBody, + query: acceptedQuery + } = this.acceptedParams['ingest.put_pipeline'] + const userQuery = params?.querystring const querystring: Record<string, any> = userQuery != null ? { ...userQuery } : {} @@ -514,8 +692,14 @@ export default class Ingest { } else if (acceptedPath.includes(key)) { continue } else if (key !== 'body' && key !== 'querystring') { - // @ts-expect-error - querystring[key] = params[key] + if (acceptedQuery.includes(key) || commonQueryParams.includes(key)) { + // @ts-expect-error + querystring[key] = params[key] + } else { + body = body ?? {} + // @ts-expect-error + body[key] = params[key] + } } } @@ -538,8 +722,12 @@ export default class Ingest { async simulate (this: That, params: T.IngestSimulateRequest, options?: TransportRequestOptionsWithMeta): Promise<TransportResult<T.IngestSimulateResponse, unknown>> async simulate (this: That, params: T.IngestSimulateRequest, options?: TransportRequestOptions): Promise<T.IngestSimulateResponse> async simulate (this: That, params: T.IngestSimulateRequest, options?: TransportRequestOptions): Promise<any> { - const acceptedPath: string[] = ['id'] - const acceptedBody: string[] = ['docs', 'pipeline'] + const { + path: acceptedPath, + body: acceptedBody, + query: acceptedQuery + } = this.acceptedParams['ingest.simulate'] + const userQuery = params?.querystring const querystring: Record<string, any> = userQuery != null ? { ...userQuery } : {} @@ -561,8 +749,14 @@ export default class Ingest { } else if (acceptedPath.includes(key)) { continue } else if (key !== 'body' && key !== 'querystring') { - // @ts-expect-error - querystring[key] = params[key] + if (acceptedQuery.includes(key) || commonQueryParams.includes(key)) { + // @ts-expect-error + querystring[key] = params[key] + } else { + body = body ?? {} + // @ts-expect-error + body[key] = params[key] + } } } diff --git a/src/api/api/knn_search.ts b/src/api/api/knn_search.ts index d1a319461..a24519479 100644 --- a/src/api/api/knn_search.ts +++ b/src/api/api/knn_search.ts @@ -35,7 +35,31 @@ import { TransportResult } from '@elastic/transport' import * as T from '../types' -interface That { transport: Transport } + +interface That { + transport: Transport +} + +const commonQueryParams = ['error_trace', 'filter_path', 'human', 'pretty'] + +const acceptedParams: Record<string, { path: string[], body: string[], query: string[] }> = { + knn_search: { + path: [ + 'index' + ], + body: [ + '_source', + 'docvalue_fields', + 'stored_fields', + 'fields', + 'filter', + 'knn' + ], + query: [ + 'routing' + ] + } +} /** * Run a knn search. NOTE: The kNN search API has been replaced by the `knn` option in the search API. Perform a k-nearest neighbor (kNN) search on a dense_vector field and return the matching documents. Given a query vector, the API finds the k closest vectors and returns those documents as search hits. Elasticsearch uses the HNSW algorithm to support efficient kNN search. Like most kNN algorithms, HNSW is an approximate method that sacrifices result accuracy for improved search speed. This means the results returned are not always the true k closest neighbors. The kNN search API supports restricting the search using a filter. The search will return the top k documents that also match the filter query. A kNN search response has the exact same structure as a search API response. However, certain sections have a meaning specific to kNN search: * The document `_score` is determined by the similarity between the query and document vector. * The `hits.total` object contains the total number of nearest neighbor candidates considered, which is `num_candidates * num_shards`. The `hits.total.relation` will always be `eq`, indicating an exact value. @@ -45,8 +69,12 @@ export default async function KnnSearchApi<TDocument = unknown> (this: That, par export default async function KnnSearchApi<TDocument = unknown> (this: That, params: T.KnnSearchRequest, options?: TransportRequestOptionsWithMeta): Promise<TransportResult<T.KnnSearchResponse<TDocument>, unknown>> export default async function KnnSearchApi<TDocument = unknown> (this: That, params: T.KnnSearchRequest, options?: TransportRequestOptions): Promise<T.KnnSearchResponse<TDocument>> export default async function KnnSearchApi<TDocument = unknown> (this: That, params: T.KnnSearchRequest, options?: TransportRequestOptions): Promise<any> { - const acceptedPath: string[] = ['index'] - const acceptedBody: string[] = ['_source', 'docvalue_fields', 'stored_fields', 'fields', 'filter', 'knn'] + const { + path: acceptedPath, + body: acceptedBody, + query: acceptedQuery + } = acceptedParams.knn_search + const userQuery = params?.querystring const querystring: Record<string, any> = userQuery != null ? { ...userQuery } : {} @@ -68,8 +96,14 @@ export default async function KnnSearchApi<TDocument = unknown> (this: That, par } else if (acceptedPath.includes(key)) { continue } else if (key !== 'body' && key !== 'querystring') { - // @ts-expect-error - querystring[key] = params[key] + if (acceptedQuery.includes(key) || commonQueryParams.includes(key)) { + // @ts-expect-error + querystring[key] = params[key] + } else { + body = body ?? {} + // @ts-expect-error + body[key] = params[key] + } } } diff --git a/src/api/api/license.ts b/src/api/api/license.ts index b80733dd9..15655585a 100644 --- a/src/api/api/license.ts +++ b/src/api/api/license.ts @@ -35,12 +35,77 @@ import { TransportResult } from '@elastic/transport' import * as T from '../types' -interface That { transport: Transport } + +interface That { + transport: Transport + acceptedParams: Record<string, { path: string[], body: string[], query: string[] }> +} + +const commonQueryParams = ['error_trace', 'filter_path', 'human', 'pretty'] export default class License { transport: Transport + acceptedParams: Record<string, { path: string[], body: string[], query: string[] }> constructor (transport: Transport) { this.transport = transport + this.acceptedParams = { + 'license.delete': { + path: [], + body: [], + query: [ + 'master_timeout', + 'timeout' + ] + }, + 'license.get': { + path: [], + body: [], + query: [ + 'accept_enterprise', + 'local' + ] + }, + 'license.get_basic_status': { + path: [], + body: [], + query: [] + }, + 'license.get_trial_status': { + path: [], + body: [], + query: [] + }, + 'license.post': { + path: [], + body: [ + 'license', + 'licenses' + ], + query: [ + 'acknowledge', + 'master_timeout', + 'timeout' + ] + }, + 'license.post_start_basic': { + path: [], + body: [], + query: [ + 'acknowledge', + 'master_timeout', + 'timeout' + ] + }, + 'license.post_start_trial': { + path: [], + body: [], + query: [ + 'acknowledge', + 'type_query_string', + 'master_timeout' + ] + } + } } /** @@ -51,7 +116,10 @@ export default class License { async delete (this: That, params?: T.LicenseDeleteRequest, options?: TransportRequestOptionsWithMeta): Promise<TransportResult<T.LicenseDeleteResponse, unknown>> async delete (this: That, params?: T.LicenseDeleteRequest, options?: TransportRequestOptions): Promise<T.LicenseDeleteResponse> async delete (this: That, params?: T.LicenseDeleteRequest, options?: TransportRequestOptions): Promise<any> { - const acceptedPath: string[] = [] + const { + path: acceptedPath + } = this.acceptedParams['license.delete'] + const userQuery = params?.querystring const querystring: Record<string, any> = userQuery != null ? { ...userQuery } : {} @@ -91,7 +159,10 @@ export default class License { async get (this: That, params?: T.LicenseGetRequest, options?: TransportRequestOptionsWithMeta): Promise<TransportResult<T.LicenseGetResponse, unknown>> async get (this: That, params?: T.LicenseGetRequest, options?: TransportRequestOptions): Promise<T.LicenseGetResponse> async get (this: That, params?: T.LicenseGetRequest, options?: TransportRequestOptions): Promise<any> { - const acceptedPath: string[] = [] + const { + path: acceptedPath + } = this.acceptedParams['license.get'] + const userQuery = params?.querystring const querystring: Record<string, any> = userQuery != null ? { ...userQuery } : {} @@ -131,7 +202,10 @@ export default class License { async getBasicStatus (this: That, params?: T.LicenseGetBasicStatusRequest, options?: TransportRequestOptionsWithMeta): Promise<TransportResult<T.LicenseGetBasicStatusResponse, unknown>> async getBasicStatus (this: That, params?: T.LicenseGetBasicStatusRequest, options?: TransportRequestOptions): Promise<T.LicenseGetBasicStatusResponse> async getBasicStatus (this: That, params?: T.LicenseGetBasicStatusRequest, options?: TransportRequestOptions): Promise<any> { - const acceptedPath: string[] = [] + const { + path: acceptedPath + } = this.acceptedParams['license.get_basic_status'] + const userQuery = params?.querystring const querystring: Record<string, any> = userQuery != null ? { ...userQuery } : {} @@ -171,7 +245,10 @@ export default class License { async getTrialStatus (this: That, params?: T.LicenseGetTrialStatusRequest, options?: TransportRequestOptionsWithMeta): Promise<TransportResult<T.LicenseGetTrialStatusResponse, unknown>> async getTrialStatus (this: That, params?: T.LicenseGetTrialStatusRequest, options?: TransportRequestOptions): Promise<T.LicenseGetTrialStatusResponse> async getTrialStatus (this: That, params?: T.LicenseGetTrialStatusRequest, options?: TransportRequestOptions): Promise<any> { - const acceptedPath: string[] = [] + const { + path: acceptedPath + } = this.acceptedParams['license.get_trial_status'] + const userQuery = params?.querystring const querystring: Record<string, any> = userQuery != null ? { ...userQuery } : {} @@ -211,8 +288,12 @@ export default class License { async post (this: That, params?: T.LicensePostRequest, options?: TransportRequestOptionsWithMeta): Promise<TransportResult<T.LicensePostResponse, unknown>> async post (this: That, params?: T.LicensePostRequest, options?: TransportRequestOptions): Promise<T.LicensePostResponse> async post (this: That, params?: T.LicensePostRequest, options?: TransportRequestOptions): Promise<any> { - const acceptedPath: string[] = [] - const acceptedBody: string[] = ['license', 'licenses'] + const { + path: acceptedPath, + body: acceptedBody, + query: acceptedQuery + } = this.acceptedParams['license.post'] + const userQuery = params?.querystring const querystring: Record<string, any> = userQuery != null ? { ...userQuery } : {} @@ -235,8 +316,14 @@ export default class License { } else if (acceptedPath.includes(key)) { continue } else if (key !== 'body' && key !== 'querystring') { - // @ts-expect-error - querystring[key] = params[key] + if (acceptedQuery.includes(key) || commonQueryParams.includes(key)) { + // @ts-expect-error + querystring[key] = params[key] + } else { + body = body ?? {} + // @ts-expect-error + body[key] = params[key] + } } } @@ -256,7 +343,10 @@ export default class License { async postStartBasic (this: That, params?: T.LicensePostStartBasicRequest, options?: TransportRequestOptionsWithMeta): Promise<TransportResult<T.LicensePostStartBasicResponse, unknown>> async postStartBasic (this: That, params?: T.LicensePostStartBasicRequest, options?: TransportRequestOptions): Promise<T.LicensePostStartBasicResponse> async postStartBasic (this: That, params?: T.LicensePostStartBasicRequest, options?: TransportRequestOptions): Promise<any> { - const acceptedPath: string[] = [] + const { + path: acceptedPath + } = this.acceptedParams['license.post_start_basic'] + const userQuery = params?.querystring const querystring: Record<string, any> = userQuery != null ? { ...userQuery } : {} @@ -296,7 +386,10 @@ export default class License { async postStartTrial (this: That, params?: T.LicensePostStartTrialRequest, options?: TransportRequestOptionsWithMeta): Promise<TransportResult<T.LicensePostStartTrialResponse, unknown>> async postStartTrial (this: That, params?: T.LicensePostStartTrialRequest, options?: TransportRequestOptions): Promise<T.LicensePostStartTrialResponse> async postStartTrial (this: That, params?: T.LicensePostStartTrialRequest, options?: TransportRequestOptions): Promise<any> { - const acceptedPath: string[] = [] + const { + path: acceptedPath + } = this.acceptedParams['license.post_start_trial'] + const userQuery = params?.querystring const querystring: Record<string, any> = userQuery != null ? { ...userQuery } : {} diff --git a/src/api/api/logstash.ts b/src/api/api/logstash.ts index df33e03ac..3434c0429 100644 --- a/src/api/api/logstash.ts +++ b/src/api/api/logstash.ts @@ -35,12 +35,44 @@ import { TransportResult } from '@elastic/transport' import * as T from '../types' -interface That { transport: Transport } + +interface That { + transport: Transport + acceptedParams: Record<string, { path: string[], body: string[], query: string[] }> +} + +const commonQueryParams = ['error_trace', 'filter_path', 'human', 'pretty'] export default class Logstash { transport: Transport + acceptedParams: Record<string, { path: string[], body: string[], query: string[] }> constructor (transport: Transport) { this.transport = transport + this.acceptedParams = { + 'logstash.delete_pipeline': { + path: [ + 'id' + ], + body: [], + query: [] + }, + 'logstash.get_pipeline': { + path: [ + 'id' + ], + body: [], + query: [] + }, + 'logstash.put_pipeline': { + path: [ + 'id' + ], + body: [ + 'pipeline' + ], + query: [] + } + } } /** @@ -51,7 +83,10 @@ export default class Logstash { async deletePipeline (this: That, params: T.LogstashDeletePipelineRequest, options?: TransportRequestOptionsWithMeta): Promise<TransportResult<T.LogstashDeletePipelineResponse, unknown>> async deletePipeline (this: That, params: T.LogstashDeletePipelineRequest, options?: TransportRequestOptions): Promise<T.LogstashDeletePipelineResponse> async deletePipeline (this: That, params: T.LogstashDeletePipelineRequest, options?: TransportRequestOptions): Promise<any> { - const acceptedPath: string[] = ['id'] + const { + path: acceptedPath + } = this.acceptedParams['logstash.delete_pipeline'] + const userQuery = params?.querystring const querystring: Record<string, any> = userQuery != null ? { ...userQuery } : {} @@ -93,7 +128,10 @@ export default class Logstash { async getPipeline (this: That, params?: T.LogstashGetPipelineRequest, options?: TransportRequestOptionsWithMeta): Promise<TransportResult<T.LogstashGetPipelineResponse, unknown>> async getPipeline (this: That, params?: T.LogstashGetPipelineRequest, options?: TransportRequestOptions): Promise<T.LogstashGetPipelineResponse> async getPipeline (this: That, params?: T.LogstashGetPipelineRequest, options?: TransportRequestOptions): Promise<any> { - const acceptedPath: string[] = ['id'] + const { + path: acceptedPath + } = this.acceptedParams['logstash.get_pipeline'] + const userQuery = params?.querystring const querystring: Record<string, any> = userQuery != null ? { ...userQuery } : {} @@ -143,8 +181,12 @@ export default class Logstash { async putPipeline (this: That, params: T.LogstashPutPipelineRequest, options?: TransportRequestOptionsWithMeta): Promise<TransportResult<T.LogstashPutPipelineResponse, unknown>> async putPipeline (this: That, params: T.LogstashPutPipelineRequest, options?: TransportRequestOptions): Promise<T.LogstashPutPipelineResponse> async putPipeline (this: That, params: T.LogstashPutPipelineRequest, options?: TransportRequestOptions): Promise<any> { - const acceptedPath: string[] = ['id'] - const acceptedBody: string[] = ['pipeline'] + const { + path: acceptedPath, + body: acceptedBody, + query: acceptedQuery + } = this.acceptedParams['logstash.put_pipeline'] + const userQuery = params?.querystring const querystring: Record<string, any> = userQuery != null ? { ...userQuery } : {} @@ -156,8 +198,14 @@ export default class Logstash { } else if (acceptedPath.includes(key)) { continue } else if (key !== 'body' && key !== 'querystring') { - // @ts-expect-error - querystring[key] = params[key] + if (acceptedQuery.includes(key) || commonQueryParams.includes(key)) { + // @ts-expect-error + querystring[key] = params[key] + } else { + body = body ?? {} + // @ts-expect-error + body[key] = params[key] + } } } diff --git a/src/api/api/mget.ts b/src/api/api/mget.ts index c254d5fd8..0a37d3b40 100644 --- a/src/api/api/mget.ts +++ b/src/api/api/mget.ts @@ -35,7 +35,35 @@ import { TransportResult } from '@elastic/transport' import * as T from '../types' -interface That { transport: Transport } + +interface That { + transport: Transport +} + +const commonQueryParams = ['error_trace', 'filter_path', 'human', 'pretty'] + +const acceptedParams: Record<string, { path: string[], body: string[], query: string[] }> = { + mget: { + path: [ + 'index' + ], + body: [ + 'docs', + 'ids' + ], + query: [ + 'force_synthetic_source', + 'preference', + 'realtime', + 'refresh', + 'routing', + '_source', + '_source_excludes', + '_source_includes', + 'stored_fields' + ] + } +} /** * Get multiple documents. Get multiple JSON documents by ID from one or more indices. If you specify an index in the request URI, you only need to specify the document IDs in the request body. To ensure fast responses, this multi get (mget) API responds with partial results if one or more shards fail. **Filter source fields** By default, the `_source` field is returned for every document (if stored). Use the `_source` and `_source_include` or `source_exclude` attributes to filter what fields are returned for a particular document. You can include the `_source`, `_source_includes`, and `_source_excludes` query parameters in the request URI to specify the defaults to use when there are no per-document instructions. **Get stored fields** Use the `stored_fields` attribute to specify the set of stored fields you want to retrieve. Any requested fields that are not stored are ignored. You can include the `stored_fields` query parameter in the request URI to specify the defaults to use when there are no per-document instructions. @@ -45,8 +73,12 @@ export default async function MgetApi<TDocument = unknown> (this: That, params?: export default async function MgetApi<TDocument = unknown> (this: That, params?: T.MgetRequest, options?: TransportRequestOptionsWithMeta): Promise<TransportResult<T.MgetResponse<TDocument>, unknown>> export default async function MgetApi<TDocument = unknown> (this: That, params?: T.MgetRequest, options?: TransportRequestOptions): Promise<T.MgetResponse<TDocument>> export default async function MgetApi<TDocument = unknown> (this: That, params?: T.MgetRequest, options?: TransportRequestOptions): Promise<any> { - const acceptedPath: string[] = ['index'] - const acceptedBody: string[] = ['docs', 'ids'] + const { + path: acceptedPath, + body: acceptedBody, + query: acceptedQuery + } = acceptedParams.mget + const userQuery = params?.querystring const querystring: Record<string, any> = userQuery != null ? { ...userQuery } : {} @@ -69,8 +101,14 @@ export default async function MgetApi<TDocument = unknown> (this: That, params?: } else if (acceptedPath.includes(key)) { continue } else if (key !== 'body' && key !== 'querystring') { - // @ts-expect-error - querystring[key] = params[key] + if (acceptedQuery.includes(key) || commonQueryParams.includes(key)) { + // @ts-expect-error + querystring[key] = params[key] + } else { + body = body ?? {} + // @ts-expect-error + body[key] = params[key] + } } } diff --git a/src/api/api/migration.ts b/src/api/api/migration.ts index 5ddf19b7d..28c0188a7 100644 --- a/src/api/api/migration.ts +++ b/src/api/api/migration.ts @@ -35,12 +35,36 @@ import { TransportResult } from '@elastic/transport' import * as T from '../types' -interface That { transport: Transport } + +interface That { + transport: Transport + acceptedParams: Record<string, { path: string[], body: string[], query: string[] }> +} export default class Migration { transport: Transport + acceptedParams: Record<string, { path: string[], body: string[], query: string[] }> constructor (transport: Transport) { this.transport = transport + this.acceptedParams = { + 'migration.deprecations': { + path: [ + 'index' + ], + body: [], + query: [] + }, + 'migration.get_feature_upgrade_status': { + path: [], + body: [], + query: [] + }, + 'migration.post_feature_upgrade': { + path: [], + body: [], + query: [] + } + } } /** @@ -51,7 +75,10 @@ export default class Migration { async deprecations (this: That, params?: T.MigrationDeprecationsRequest, options?: TransportRequestOptionsWithMeta): Promise<TransportResult<T.MigrationDeprecationsResponse, unknown>> async deprecations (this: That, params?: T.MigrationDeprecationsRequest, options?: TransportRequestOptions): Promise<T.MigrationDeprecationsResponse> async deprecations (this: That, params?: T.MigrationDeprecationsRequest, options?: TransportRequestOptions): Promise<any> { - const acceptedPath: string[] = ['index'] + const { + path: acceptedPath + } = this.acceptedParams['migration.deprecations'] + const userQuery = params?.querystring const querystring: Record<string, any> = userQuery != null ? { ...userQuery } : {} @@ -101,7 +128,10 @@ export default class Migration { async getFeatureUpgradeStatus (this: That, params?: T.MigrationGetFeatureUpgradeStatusRequest, options?: TransportRequestOptionsWithMeta): Promise<TransportResult<T.MigrationGetFeatureUpgradeStatusResponse, unknown>> async getFeatureUpgradeStatus (this: That, params?: T.MigrationGetFeatureUpgradeStatusRequest, options?: TransportRequestOptions): Promise<T.MigrationGetFeatureUpgradeStatusResponse> async getFeatureUpgradeStatus (this: That, params?: T.MigrationGetFeatureUpgradeStatusRequest, options?: TransportRequestOptions): Promise<any> { - const acceptedPath: string[] = [] + const { + path: acceptedPath + } = this.acceptedParams['migration.get_feature_upgrade_status'] + const userQuery = params?.querystring const querystring: Record<string, any> = userQuery != null ? { ...userQuery } : {} @@ -141,7 +171,10 @@ export default class Migration { async postFeatureUpgrade (this: That, params?: T.MigrationPostFeatureUpgradeRequest, options?: TransportRequestOptionsWithMeta): Promise<TransportResult<T.MigrationPostFeatureUpgradeResponse, unknown>> async postFeatureUpgrade (this: That, params?: T.MigrationPostFeatureUpgradeRequest, options?: TransportRequestOptions): Promise<T.MigrationPostFeatureUpgradeResponse> async postFeatureUpgrade (this: That, params?: T.MigrationPostFeatureUpgradeRequest, options?: TransportRequestOptions): Promise<any> { - const acceptedPath: string[] = [] + const { + path: acceptedPath + } = this.acceptedParams['migration.post_feature_upgrade'] + const userQuery = params?.querystring const querystring: Record<string, any> = userQuery != null ? { ...userQuery } : {} diff --git a/src/api/api/ml.ts b/src/api/api/ml.ts index 282fc38a5..677f3e54f 100644 --- a/src/api/api/ml.ts +++ b/src/api/api/ml.ts @@ -35,12 +35,958 @@ import { TransportResult } from '@elastic/transport' import * as T from '../types' -interface That { transport: Transport } + +interface That { + transport: Transport + acceptedParams: Record<string, { path: string[], body: string[], query: string[] }> +} + +const commonQueryParams = ['error_trace', 'filter_path', 'human', 'pretty'] export default class Ml { transport: Transport + acceptedParams: Record<string, { path: string[], body: string[], query: string[] }> constructor (transport: Transport) { this.transport = transport + this.acceptedParams = { + 'ml.clear_trained_model_deployment_cache': { + path: [ + 'model_id' + ], + body: [], + query: [] + }, + 'ml.close_job': { + path: [ + 'job_id' + ], + body: [ + 'allow_no_match', + 'force', + 'timeout' + ], + query: [ + 'allow_no_match', + 'force', + 'timeout' + ] + }, + 'ml.delete_calendar': { + path: [ + 'calendar_id' + ], + body: [], + query: [] + }, + 'ml.delete_calendar_event': { + path: [ + 'calendar_id', + 'event_id' + ], + body: [], + query: [] + }, + 'ml.delete_calendar_job': { + path: [ + 'calendar_id', + 'job_id' + ], + body: [], + query: [] + }, + 'ml.delete_data_frame_analytics': { + path: [ + 'id' + ], + body: [], + query: [ + 'force', + 'timeout' + ] + }, + 'ml.delete_datafeed': { + path: [ + 'datafeed_id' + ], + body: [], + query: [ + 'force' + ] + }, + 'ml.delete_expired_data': { + path: [ + 'job_id' + ], + body: [ + 'requests_per_second', + 'timeout' + ], + query: [ + 'requests_per_second', + 'timeout' + ] + }, + 'ml.delete_filter': { + path: [ + 'filter_id' + ], + body: [], + query: [] + }, + 'ml.delete_forecast': { + path: [ + 'job_id', + 'forecast_id' + ], + body: [], + query: [ + 'allow_no_forecasts', + 'timeout' + ] + }, + 'ml.delete_job': { + path: [ + 'job_id' + ], + body: [], + query: [ + 'force', + 'delete_user_annotations', + 'wait_for_completion' + ] + }, + 'ml.delete_model_snapshot': { + path: [ + 'job_id', + 'snapshot_id' + ], + body: [], + query: [] + }, + 'ml.delete_trained_model': { + path: [ + 'model_id' + ], + body: [], + query: [ + 'force', + 'timeout' + ] + }, + 'ml.delete_trained_model_alias': { + path: [ + 'model_alias', + 'model_id' + ], + body: [], + query: [] + }, + 'ml.estimate_model_memory': { + path: [], + body: [ + 'analysis_config', + 'max_bucket_cardinality', + 'overall_cardinality' + ], + query: [] + }, + 'ml.evaluate_data_frame': { + path: [], + body: [ + 'evaluation', + 'index', + 'query' + ], + query: [] + }, + 'ml.explain_data_frame_analytics': { + path: [ + 'id' + ], + body: [ + 'source', + 'dest', + 'analysis', + 'description', + 'model_memory_limit', + 'max_num_threads', + 'analyzed_fields', + 'allow_lazy_start' + ], + query: [] + }, + 'ml.flush_job': { + path: [ + 'job_id' + ], + body: [ + 'advance_time', + 'calc_interim', + 'end', + 'skip_time', + 'start' + ], + query: [ + 'advance_time', + 'calc_interim', + 'end', + 'skip_time', + 'start' + ] + }, + 'ml.forecast': { + path: [ + 'job_id' + ], + body: [ + 'duration', + 'expires_in', + 'max_model_memory' + ], + query: [ + 'duration', + 'expires_in', + 'max_model_memory' + ] + }, + 'ml.get_buckets': { + path: [ + 'job_id', + 'timestamp' + ], + body: [ + 'anomaly_score', + 'desc', + 'end', + 'exclude_interim', + 'expand', + 'page', + 'sort', + 'start' + ], + query: [ + 'anomaly_score', + 'desc', + 'end', + 'exclude_interim', + 'expand', + 'from', + 'size', + 'sort', + 'start' + ] + }, + 'ml.get_calendar_events': { + path: [ + 'calendar_id' + ], + body: [], + query: [ + 'end', + 'from', + 'job_id', + 'size', + 'start' + ] + }, + 'ml.get_calendars': { + path: [ + 'calendar_id' + ], + body: [ + 'page' + ], + query: [ + 'from', + 'size' + ] + }, + 'ml.get_categories': { + path: [ + 'job_id', + 'category_id' + ], + body: [ + 'page' + ], + query: [ + 'from', + 'partition_field_value', + 'size' + ] + }, + 'ml.get_data_frame_analytics': { + path: [ + 'id' + ], + body: [], + query: [ + 'allow_no_match', + 'from', + 'size', + 'exclude_generated' + ] + }, + 'ml.get_data_frame_analytics_stats': { + path: [ + 'id' + ], + body: [], + query: [ + 'allow_no_match', + 'from', + 'size', + 'verbose' + ] + }, + 'ml.get_datafeed_stats': { + path: [ + 'datafeed_id' + ], + body: [], + query: [ + 'allow_no_match' + ] + }, + 'ml.get_datafeeds': { + path: [ + 'datafeed_id' + ], + body: [], + query: [ + 'allow_no_match', + 'exclude_generated' + ] + }, + 'ml.get_filters': { + path: [ + 'filter_id' + ], + body: [], + query: [ + 'from', + 'size' + ] + }, + 'ml.get_influencers': { + path: [ + 'job_id' + ], + body: [ + 'page' + ], + query: [ + 'desc', + 'end', + 'exclude_interim', + 'influencer_score', + 'from', + 'size', + 'sort', + 'start' + ] + }, + 'ml.get_job_stats': { + path: [ + 'job_id' + ], + body: [], + query: [ + 'allow_no_match' + ] + }, + 'ml.get_jobs': { + path: [ + 'job_id' + ], + body: [], + query: [ + 'allow_no_match', + 'exclude_generated' + ] + }, + 'ml.get_memory_stats': { + path: [ + 'node_id' + ], + body: [], + query: [ + 'master_timeout', + 'timeout' + ] + }, + 'ml.get_model_snapshot_upgrade_stats': { + path: [ + 'job_id', + 'snapshot_id' + ], + body: [], + query: [ + 'allow_no_match' + ] + }, + 'ml.get_model_snapshots': { + path: [ + 'job_id', + 'snapshot_id' + ], + body: [ + 'desc', + 'end', + 'page', + 'sort', + 'start' + ], + query: [ + 'desc', + 'end', + 'from', + 'size', + 'sort', + 'start' + ] + }, + 'ml.get_overall_buckets': { + path: [ + 'job_id' + ], + body: [ + 'allow_no_match', + 'bucket_span', + 'end', + 'exclude_interim', + 'overall_score', + 'start', + 'top_n' + ], + query: [ + 'allow_no_match', + 'bucket_span', + 'end', + 'exclude_interim', + 'overall_score', + 'start', + 'top_n' + ] + }, + 'ml.get_records': { + path: [ + 'job_id' + ], + body: [ + 'desc', + 'end', + 'exclude_interim', + 'page', + 'record_score', + 'sort', + 'start' + ], + query: [ + 'desc', + 'end', + 'exclude_interim', + 'from', + 'record_score', + 'size', + 'sort', + 'start' + ] + }, + 'ml.get_trained_models': { + path: [ + 'model_id' + ], + body: [], + query: [ + 'allow_no_match', + 'decompress_definition', + 'exclude_generated', + 'from', + 'include', + 'include_model_definition', + 'size', + 'tags' + ] + }, + 'ml.get_trained_models_stats': { + path: [ + 'model_id' + ], + body: [], + query: [ + 'allow_no_match', + 'from', + 'size' + ] + }, + 'ml.infer_trained_model': { + path: [ + 'model_id' + ], + body: [ + 'docs', + 'inference_config' + ], + query: [ + 'timeout' + ] + }, + 'ml.info': { + path: [], + body: [], + query: [] + }, + 'ml.open_job': { + path: [ + 'job_id' + ], + body: [ + 'timeout' + ], + query: [ + 'timeout' + ] + }, + 'ml.post_calendar_events': { + path: [ + 'calendar_id' + ], + body: [ + 'events' + ], + query: [] + }, + 'ml.post_data': { + path: [ + 'job_id' + ], + body: [ + 'data' + ], + query: [ + 'reset_end', + 'reset_start' + ] + }, + 'ml.preview_data_frame_analytics': { + path: [ + 'id' + ], + body: [ + 'config' + ], + query: [] + }, + 'ml.preview_datafeed': { + path: [ + 'datafeed_id' + ], + body: [ + 'datafeed_config', + 'job_config' + ], + query: [ + 'start', + 'end' + ] + }, + 'ml.put_calendar': { + path: [ + 'calendar_id' + ], + body: [ + 'job_ids', + 'description' + ], + query: [] + }, + 'ml.put_calendar_job': { + path: [ + 'calendar_id', + 'job_id' + ], + body: [], + query: [] + }, + 'ml.put_data_frame_analytics': { + path: [ + 'id' + ], + body: [ + 'allow_lazy_start', + 'analysis', + 'analyzed_fields', + 'description', + 'dest', + 'max_num_threads', + '_meta', + 'model_memory_limit', + 'source', + 'headers', + 'version' + ], + query: [] + }, + 'ml.put_datafeed': { + path: [ + 'datafeed_id' + ], + body: [ + 'aggregations', + 'aggs', + 'chunking_config', + 'delayed_data_check_config', + 'frequency', + 'indices', + 'indexes', + 'indices_options', + 'job_id', + 'max_empty_searches', + 'query', + 'query_delay', + 'runtime_mappings', + 'script_fields', + 'scroll_size', + 'headers' + ], + query: [ + 'allow_no_indices', + 'expand_wildcards', + 'ignore_throttled', + 'ignore_unavailable' + ] + }, + 'ml.put_filter': { + path: [ + 'filter_id' + ], + body: [ + 'description', + 'items' + ], + query: [] + }, + 'ml.put_job': { + path: [], + body: [ + 'allow_lazy_open', + 'analysis_config', + 'analysis_limits', + 'background_persist_interval', + 'custom_settings', + 'daily_model_snapshot_retention_after_days', + 'data_description', + 'datafeed_config', + 'description', + 'job_id', + 'groups', + 'model_plot_config', + 'model_snapshot_retention_days', + 'renormalization_window_days', + 'results_index_name', + 'results_retention_days' + ], + query: [ + 'allow_no_indices', + 'expand_wildcards', + 'ignore_throttled', + 'ignore_unavailable' + ] + }, + 'ml.put_trained_model': { + path: [ + 'model_id' + ], + body: [ + 'compressed_definition', + 'definition', + 'description', + 'inference_config', + 'input', + 'metadata', + 'model_type', + 'model_size_bytes', + 'platform_architecture', + 'tags', + 'prefix_strings' + ], + query: [ + 'defer_definition_decompression', + 'wait_for_completion' + ] + }, + 'ml.put_trained_model_alias': { + path: [ + 'model_alias', + 'model_id' + ], + body: [], + query: [ + 'reassign' + ] + }, + 'ml.put_trained_model_definition_part': { + path: [ + 'model_id', + 'part' + ], + body: [ + 'definition', + 'total_definition_length', + 'total_parts' + ], + query: [] + }, + 'ml.put_trained_model_vocabulary': { + path: [ + 'model_id' + ], + body: [ + 'vocabulary', + 'merges', + 'scores' + ], + query: [] + }, + 'ml.reset_job': { + path: [ + 'job_id' + ], + body: [], + query: [ + 'wait_for_completion', + 'delete_user_annotations' + ] + }, + 'ml.revert_model_snapshot': { + path: [ + 'job_id', + 'snapshot_id' + ], + body: [ + 'delete_intervening_results' + ], + query: [ + 'delete_intervening_results' + ] + }, + 'ml.set_upgrade_mode': { + path: [], + body: [], + query: [ + 'enabled', + 'timeout' + ] + }, + 'ml.start_data_frame_analytics': { + path: [ + 'id' + ], + body: [], + query: [ + 'timeout' + ] + }, + 'ml.start_datafeed': { + path: [ + 'datafeed_id' + ], + body: [ + 'end', + 'start', + 'timeout' + ], + query: [ + 'end', + 'start', + 'timeout' + ] + }, + 'ml.start_trained_model_deployment': { + path: [ + 'model_id' + ], + body: [ + 'adaptive_allocations' + ], + query: [ + 'cache_size', + 'deployment_id', + 'number_of_allocations', + 'priority', + 'queue_capacity', + 'threads_per_allocation', + 'timeout', + 'wait_for' + ] + }, + 'ml.stop_data_frame_analytics': { + path: [ + 'id' + ], + body: [], + query: [ + 'allow_no_match', + 'force', + 'timeout' + ] + }, + 'ml.stop_datafeed': { + path: [ + 'datafeed_id' + ], + body: [ + 'allow_no_match', + 'force', + 'timeout' + ], + query: [ + 'allow_no_match', + 'force', + 'timeout' + ] + }, + 'ml.stop_trained_model_deployment': { + path: [ + 'model_id' + ], + body: [], + query: [ + 'allow_no_match', + 'force' + ] + }, + 'ml.update_data_frame_analytics': { + path: [ + 'id' + ], + body: [ + 'description', + 'model_memory_limit', + 'max_num_threads', + 'allow_lazy_start' + ], + query: [] + }, + 'ml.update_datafeed': { + path: [ + 'datafeed_id' + ], + body: [ + 'aggregations', + 'chunking_config', + 'delayed_data_check_config', + 'frequency', + 'indices', + 'indexes', + 'indices_options', + 'job_id', + 'max_empty_searches', + 'query', + 'query_delay', + 'runtime_mappings', + 'script_fields', + 'scroll_size' + ], + query: [ + 'allow_no_indices', + 'expand_wildcards', + 'ignore_throttled', + 'ignore_unavailable' + ] + }, + 'ml.update_filter': { + path: [ + 'filter_id' + ], + body: [ + 'add_items', + 'description', + 'remove_items' + ], + query: [] + }, + 'ml.update_job': { + path: [ + 'job_id' + ], + body: [ + 'allow_lazy_open', + 'analysis_limits', + 'background_persist_interval', + 'custom_settings', + 'categorization_filters', + 'description', + 'model_plot_config', + 'model_prune_window', + 'daily_model_snapshot_retention_after_days', + 'model_snapshot_retention_days', + 'renormalization_window_days', + 'results_retention_days', + 'groups', + 'detectors', + 'per_partition_categorization' + ], + query: [] + }, + 'ml.update_model_snapshot': { + path: [ + 'job_id', + 'snapshot_id' + ], + body: [ + 'description', + 'retain' + ], + query: [] + }, + 'ml.update_trained_model_deployment': { + path: [ + 'model_id' + ], + body: [ + 'number_of_allocations', + 'adaptive_allocations' + ], + query: [ + 'number_of_allocations' + ] + }, + 'ml.upgrade_job_snapshot': { + path: [ + 'job_id', + 'snapshot_id' + ], + body: [], + query: [ + 'wait_for_completion', + 'timeout' + ] + }, + 'ml.validate': { + path: [], + body: [ + 'job_id', + 'analysis_config', + 'analysis_limits', + 'data_description', + 'description', + 'model_plot', + 'model_snapshot_id', + 'model_snapshot_retention_days', + 'results_index_name' + ], + query: [] + }, + 'ml.validate_detector': { + path: [], + body: [ + 'detector' + ], + query: [] + } + } } /** @@ -51,7 +997,10 @@ export default class Ml { async clearTrainedModelDeploymentCache (this: That, params: T.MlClearTrainedModelDeploymentCacheRequest, options?: TransportRequestOptionsWithMeta): Promise<TransportResult<T.MlClearTrainedModelDeploymentCacheResponse, unknown>> async clearTrainedModelDeploymentCache (this: That, params: T.MlClearTrainedModelDeploymentCacheRequest, options?: TransportRequestOptions): Promise<T.MlClearTrainedModelDeploymentCacheResponse> async clearTrainedModelDeploymentCache (this: That, params: T.MlClearTrainedModelDeploymentCacheRequest, options?: TransportRequestOptions): Promise<any> { - const acceptedPath: string[] = ['model_id'] + const { + path: acceptedPath + } = this.acceptedParams['ml.clear_trained_model_deployment_cache'] + const userQuery = params?.querystring const querystring: Record<string, any> = userQuery != null ? { ...userQuery } : {} @@ -93,8 +1042,12 @@ export default class Ml { async closeJob (this: That, params: T.MlCloseJobRequest, options?: TransportRequestOptionsWithMeta): Promise<TransportResult<T.MlCloseJobResponse, unknown>> async closeJob (this: That, params: T.MlCloseJobRequest, options?: TransportRequestOptions): Promise<T.MlCloseJobResponse> async closeJob (this: That, params: T.MlCloseJobRequest, options?: TransportRequestOptions): Promise<any> { - const acceptedPath: string[] = ['job_id'] - const acceptedBody: string[] = ['allow_no_match', 'force', 'timeout'] + const { + path: acceptedPath, + body: acceptedBody, + query: acceptedQuery + } = this.acceptedParams['ml.close_job'] + const userQuery = params?.querystring const querystring: Record<string, any> = userQuery != null ? { ...userQuery } : {} @@ -116,8 +1069,14 @@ export default class Ml { } else if (acceptedPath.includes(key)) { continue } else if (key !== 'body' && key !== 'querystring') { - // @ts-expect-error - querystring[key] = params[key] + if (acceptedQuery.includes(key) || commonQueryParams.includes(key)) { + // @ts-expect-error + querystring[key] = params[key] + } else { + body = body ?? {} + // @ts-expect-error + body[key] = params[key] + } } } @@ -140,7 +1099,10 @@ export default class Ml { async deleteCalendar (this: That, params: T.MlDeleteCalendarRequest, options?: TransportRequestOptionsWithMeta): Promise<TransportResult<T.MlDeleteCalendarResponse, unknown>> async deleteCalendar (this: That, params: T.MlDeleteCalendarRequest, options?: TransportRequestOptions): Promise<T.MlDeleteCalendarResponse> async deleteCalendar (this: That, params: T.MlDeleteCalendarRequest, options?: TransportRequestOptions): Promise<any> { - const acceptedPath: string[] = ['calendar_id'] + const { + path: acceptedPath + } = this.acceptedParams['ml.delete_calendar'] + const userQuery = params?.querystring const querystring: Record<string, any> = userQuery != null ? { ...userQuery } : {} @@ -182,7 +1144,10 @@ export default class Ml { async deleteCalendarEvent (this: That, params: T.MlDeleteCalendarEventRequest, options?: TransportRequestOptionsWithMeta): Promise<TransportResult<T.MlDeleteCalendarEventResponse, unknown>> async deleteCalendarEvent (this: That, params: T.MlDeleteCalendarEventRequest, options?: TransportRequestOptions): Promise<T.MlDeleteCalendarEventResponse> async deleteCalendarEvent (this: That, params: T.MlDeleteCalendarEventRequest, options?: TransportRequestOptions): Promise<any> { - const acceptedPath: string[] = ['calendar_id', 'event_id'] + const { + path: acceptedPath + } = this.acceptedParams['ml.delete_calendar_event'] + const userQuery = params?.querystring const querystring: Record<string, any> = userQuery != null ? { ...userQuery } : {} @@ -225,7 +1190,10 @@ export default class Ml { async deleteCalendarJob (this: That, params: T.MlDeleteCalendarJobRequest, options?: TransportRequestOptionsWithMeta): Promise<TransportResult<T.MlDeleteCalendarJobResponse, unknown>> async deleteCalendarJob (this: That, params: T.MlDeleteCalendarJobRequest, options?: TransportRequestOptions): Promise<T.MlDeleteCalendarJobResponse> async deleteCalendarJob (this: That, params: T.MlDeleteCalendarJobRequest, options?: TransportRequestOptions): Promise<any> { - const acceptedPath: string[] = ['calendar_id', 'job_id'] + const { + path: acceptedPath + } = this.acceptedParams['ml.delete_calendar_job'] + const userQuery = params?.querystring const querystring: Record<string, any> = userQuery != null ? { ...userQuery } : {} @@ -268,7 +1236,10 @@ export default class Ml { async deleteDataFrameAnalytics (this: That, params: T.MlDeleteDataFrameAnalyticsRequest, options?: TransportRequestOptionsWithMeta): Promise<TransportResult<T.MlDeleteDataFrameAnalyticsResponse, unknown>> async deleteDataFrameAnalytics (this: That, params: T.MlDeleteDataFrameAnalyticsRequest, options?: TransportRequestOptions): Promise<T.MlDeleteDataFrameAnalyticsResponse> async deleteDataFrameAnalytics (this: That, params: T.MlDeleteDataFrameAnalyticsRequest, options?: TransportRequestOptions): Promise<any> { - const acceptedPath: string[] = ['id'] + const { + path: acceptedPath + } = this.acceptedParams['ml.delete_data_frame_analytics'] + const userQuery = params?.querystring const querystring: Record<string, any> = userQuery != null ? { ...userQuery } : {} @@ -310,7 +1281,10 @@ export default class Ml { async deleteDatafeed (this: That, params: T.MlDeleteDatafeedRequest, options?: TransportRequestOptionsWithMeta): Promise<TransportResult<T.MlDeleteDatafeedResponse, unknown>> async deleteDatafeed (this: That, params: T.MlDeleteDatafeedRequest, options?: TransportRequestOptions): Promise<T.MlDeleteDatafeedResponse> async deleteDatafeed (this: That, params: T.MlDeleteDatafeedRequest, options?: TransportRequestOptions): Promise<any> { - const acceptedPath: string[] = ['datafeed_id'] + const { + path: acceptedPath + } = this.acceptedParams['ml.delete_datafeed'] + const userQuery = params?.querystring const querystring: Record<string, any> = userQuery != null ? { ...userQuery } : {} @@ -352,8 +1326,12 @@ export default class Ml { async deleteExpiredData (this: That, params?: T.MlDeleteExpiredDataRequest, options?: TransportRequestOptionsWithMeta): Promise<TransportResult<T.MlDeleteExpiredDataResponse, unknown>> async deleteExpiredData (this: That, params?: T.MlDeleteExpiredDataRequest, options?: TransportRequestOptions): Promise<T.MlDeleteExpiredDataResponse> async deleteExpiredData (this: That, params?: T.MlDeleteExpiredDataRequest, options?: TransportRequestOptions): Promise<any> { - const acceptedPath: string[] = ['job_id'] - const acceptedBody: string[] = ['requests_per_second', 'timeout'] + const { + path: acceptedPath, + body: acceptedBody, + query: acceptedQuery + } = this.acceptedParams['ml.delete_expired_data'] + const userQuery = params?.querystring const querystring: Record<string, any> = userQuery != null ? { ...userQuery } : {} @@ -376,8 +1354,14 @@ export default class Ml { } else if (acceptedPath.includes(key)) { continue } else if (key !== 'body' && key !== 'querystring') { - // @ts-expect-error - querystring[key] = params[key] + if (acceptedQuery.includes(key) || commonQueryParams.includes(key)) { + // @ts-expect-error + querystring[key] = params[key] + } else { + body = body ?? {} + // @ts-expect-error + body[key] = params[key] + } } } @@ -407,7 +1391,10 @@ export default class Ml { async deleteFilter (this: That, params: T.MlDeleteFilterRequest, options?: TransportRequestOptionsWithMeta): Promise<TransportResult<T.MlDeleteFilterResponse, unknown>> async deleteFilter (this: That, params: T.MlDeleteFilterRequest, options?: TransportRequestOptions): Promise<T.MlDeleteFilterResponse> async deleteFilter (this: That, params: T.MlDeleteFilterRequest, options?: TransportRequestOptions): Promise<any> { - const acceptedPath: string[] = ['filter_id'] + const { + path: acceptedPath + } = this.acceptedParams['ml.delete_filter'] + const userQuery = params?.querystring const querystring: Record<string, any> = userQuery != null ? { ...userQuery } : {} @@ -449,7 +1436,10 @@ export default class Ml { async deleteForecast (this: That, params: T.MlDeleteForecastRequest, options?: TransportRequestOptionsWithMeta): Promise<TransportResult<T.MlDeleteForecastResponse, unknown>> async deleteForecast (this: That, params: T.MlDeleteForecastRequest, options?: TransportRequestOptions): Promise<T.MlDeleteForecastResponse> async deleteForecast (this: That, params: T.MlDeleteForecastRequest, options?: TransportRequestOptions): Promise<any> { - const acceptedPath: string[] = ['job_id', 'forecast_id'] + const { + path: acceptedPath + } = this.acceptedParams['ml.delete_forecast'] + const userQuery = params?.querystring const querystring: Record<string, any> = userQuery != null ? { ...userQuery } : {} @@ -499,7 +1489,10 @@ export default class Ml { async deleteJob (this: That, params: T.MlDeleteJobRequest, options?: TransportRequestOptionsWithMeta): Promise<TransportResult<T.MlDeleteJobResponse, unknown>> async deleteJob (this: That, params: T.MlDeleteJobRequest, options?: TransportRequestOptions): Promise<T.MlDeleteJobResponse> async deleteJob (this: That, params: T.MlDeleteJobRequest, options?: TransportRequestOptions): Promise<any> { - const acceptedPath: string[] = ['job_id'] + const { + path: acceptedPath + } = this.acceptedParams['ml.delete_job'] + const userQuery = params?.querystring const querystring: Record<string, any> = userQuery != null ? { ...userQuery } : {} @@ -541,7 +1534,10 @@ export default class Ml { async deleteModelSnapshot (this: That, params: T.MlDeleteModelSnapshotRequest, options?: TransportRequestOptionsWithMeta): Promise<TransportResult<T.MlDeleteModelSnapshotResponse, unknown>> async deleteModelSnapshot (this: That, params: T.MlDeleteModelSnapshotRequest, options?: TransportRequestOptions): Promise<T.MlDeleteModelSnapshotResponse> async deleteModelSnapshot (this: That, params: T.MlDeleteModelSnapshotRequest, options?: TransportRequestOptions): Promise<any> { - const acceptedPath: string[] = ['job_id', 'snapshot_id'] + const { + path: acceptedPath + } = this.acceptedParams['ml.delete_model_snapshot'] + const userQuery = params?.querystring const querystring: Record<string, any> = userQuery != null ? { ...userQuery } : {} @@ -584,7 +1580,10 @@ export default class Ml { async deleteTrainedModel (this: That, params: T.MlDeleteTrainedModelRequest, options?: TransportRequestOptionsWithMeta): Promise<TransportResult<T.MlDeleteTrainedModelResponse, unknown>> async deleteTrainedModel (this: That, params: T.MlDeleteTrainedModelRequest, options?: TransportRequestOptions): Promise<T.MlDeleteTrainedModelResponse> async deleteTrainedModel (this: That, params: T.MlDeleteTrainedModelRequest, options?: TransportRequestOptions): Promise<any> { - const acceptedPath: string[] = ['model_id'] + const { + path: acceptedPath + } = this.acceptedParams['ml.delete_trained_model'] + const userQuery = params?.querystring const querystring: Record<string, any> = userQuery != null ? { ...userQuery } : {} @@ -626,7 +1625,10 @@ export default class Ml { async deleteTrainedModelAlias (this: That, params: T.MlDeleteTrainedModelAliasRequest, options?: TransportRequestOptionsWithMeta): Promise<TransportResult<T.MlDeleteTrainedModelAliasResponse, unknown>> async deleteTrainedModelAlias (this: That, params: T.MlDeleteTrainedModelAliasRequest, options?: TransportRequestOptions): Promise<T.MlDeleteTrainedModelAliasResponse> async deleteTrainedModelAlias (this: That, params: T.MlDeleteTrainedModelAliasRequest, options?: TransportRequestOptions): Promise<any> { - const acceptedPath: string[] = ['model_alias', 'model_id'] + const { + path: acceptedPath + } = this.acceptedParams['ml.delete_trained_model_alias'] + const userQuery = params?.querystring const querystring: Record<string, any> = userQuery != null ? { ...userQuery } : {} @@ -669,8 +1671,12 @@ export default class Ml { async estimateModelMemory (this: That, params?: T.MlEstimateModelMemoryRequest, options?: TransportRequestOptionsWithMeta): Promise<TransportResult<T.MlEstimateModelMemoryResponse, unknown>> async estimateModelMemory (this: That, params?: T.MlEstimateModelMemoryRequest, options?: TransportRequestOptions): Promise<T.MlEstimateModelMemoryResponse> async estimateModelMemory (this: That, params?: T.MlEstimateModelMemoryRequest, options?: TransportRequestOptions): Promise<any> { - const acceptedPath: string[] = [] - const acceptedBody: string[] = ['analysis_config', 'max_bucket_cardinality', 'overall_cardinality'] + const { + path: acceptedPath, + body: acceptedBody, + query: acceptedQuery + } = this.acceptedParams['ml.estimate_model_memory'] + const userQuery = params?.querystring const querystring: Record<string, any> = userQuery != null ? { ...userQuery } : {} @@ -693,8 +1699,14 @@ export default class Ml { } else if (acceptedPath.includes(key)) { continue } else if (key !== 'body' && key !== 'querystring') { - // @ts-expect-error - querystring[key] = params[key] + if (acceptedQuery.includes(key) || commonQueryParams.includes(key)) { + // @ts-expect-error + querystring[key] = params[key] + } else { + body = body ?? {} + // @ts-expect-error + body[key] = params[key] + } } } @@ -714,8 +1726,12 @@ export default class Ml { async evaluateDataFrame (this: That, params: T.MlEvaluateDataFrameRequest, options?: TransportRequestOptionsWithMeta): Promise<TransportResult<T.MlEvaluateDataFrameResponse, unknown>> async evaluateDataFrame (this: That, params: T.MlEvaluateDataFrameRequest, options?: TransportRequestOptions): Promise<T.MlEvaluateDataFrameResponse> async evaluateDataFrame (this: That, params: T.MlEvaluateDataFrameRequest, options?: TransportRequestOptions): Promise<any> { - const acceptedPath: string[] = [] - const acceptedBody: string[] = ['evaluation', 'index', 'query'] + const { + path: acceptedPath, + body: acceptedBody, + query: acceptedQuery + } = this.acceptedParams['ml.evaluate_data_frame'] + const userQuery = params?.querystring const querystring: Record<string, any> = userQuery != null ? { ...userQuery } : {} @@ -737,8 +1753,14 @@ export default class Ml { } else if (acceptedPath.includes(key)) { continue } else if (key !== 'body' && key !== 'querystring') { - // @ts-expect-error - querystring[key] = params[key] + if (acceptedQuery.includes(key) || commonQueryParams.includes(key)) { + // @ts-expect-error + querystring[key] = params[key] + } else { + body = body ?? {} + // @ts-expect-error + body[key] = params[key] + } } } @@ -758,8 +1780,12 @@ export default class Ml { async explainDataFrameAnalytics (this: That, params?: T.MlExplainDataFrameAnalyticsRequest, options?: TransportRequestOptionsWithMeta): Promise<TransportResult<T.MlExplainDataFrameAnalyticsResponse, unknown>> async explainDataFrameAnalytics (this: That, params?: T.MlExplainDataFrameAnalyticsRequest, options?: TransportRequestOptions): Promise<T.MlExplainDataFrameAnalyticsResponse> async explainDataFrameAnalytics (this: That, params?: T.MlExplainDataFrameAnalyticsRequest, options?: TransportRequestOptions): Promise<any> { - const acceptedPath: string[] = ['id'] - const acceptedBody: string[] = ['source', 'dest', 'analysis', 'description', 'model_memory_limit', 'max_num_threads', 'analyzed_fields', 'allow_lazy_start'] + const { + path: acceptedPath, + body: acceptedBody, + query: acceptedQuery + } = this.acceptedParams['ml.explain_data_frame_analytics'] + const userQuery = params?.querystring const querystring: Record<string, any> = userQuery != null ? { ...userQuery } : {} @@ -782,8 +1808,14 @@ export default class Ml { } else if (acceptedPath.includes(key)) { continue } else if (key !== 'body' && key !== 'querystring') { - // @ts-expect-error - querystring[key] = params[key] + if (acceptedQuery.includes(key) || commonQueryParams.includes(key)) { + // @ts-expect-error + querystring[key] = params[key] + } else { + body = body ?? {} + // @ts-expect-error + body[key] = params[key] + } } } @@ -813,8 +1845,12 @@ export default class Ml { async flushJob (this: That, params: T.MlFlushJobRequest, options?: TransportRequestOptionsWithMeta): Promise<TransportResult<T.MlFlushJobResponse, unknown>> async flushJob (this: That, params: T.MlFlushJobRequest, options?: TransportRequestOptions): Promise<T.MlFlushJobResponse> async flushJob (this: That, params: T.MlFlushJobRequest, options?: TransportRequestOptions): Promise<any> { - const acceptedPath: string[] = ['job_id'] - const acceptedBody: string[] = ['advance_time', 'calc_interim', 'end', 'skip_time', 'start'] + const { + path: acceptedPath, + body: acceptedBody, + query: acceptedQuery + } = this.acceptedParams['ml.flush_job'] + const userQuery = params?.querystring const querystring: Record<string, any> = userQuery != null ? { ...userQuery } : {} @@ -836,8 +1872,14 @@ export default class Ml { } else if (acceptedPath.includes(key)) { continue } else if (key !== 'body' && key !== 'querystring') { - // @ts-expect-error - querystring[key] = params[key] + if (acceptedQuery.includes(key) || commonQueryParams.includes(key)) { + // @ts-expect-error + querystring[key] = params[key] + } else { + body = body ?? {} + // @ts-expect-error + body[key] = params[key] + } } } @@ -860,8 +1902,12 @@ export default class Ml { async forecast (this: That, params: T.MlForecastRequest, options?: TransportRequestOptionsWithMeta): Promise<TransportResult<T.MlForecastResponse, unknown>> async forecast (this: That, params: T.MlForecastRequest, options?: TransportRequestOptions): Promise<T.MlForecastResponse> async forecast (this: That, params: T.MlForecastRequest, options?: TransportRequestOptions): Promise<any> { - const acceptedPath: string[] = ['job_id'] - const acceptedBody: string[] = ['duration', 'expires_in', 'max_model_memory'] + const { + path: acceptedPath, + body: acceptedBody, + query: acceptedQuery + } = this.acceptedParams['ml.forecast'] + const userQuery = params?.querystring const querystring: Record<string, any> = userQuery != null ? { ...userQuery } : {} @@ -883,8 +1929,14 @@ export default class Ml { } else if (acceptedPath.includes(key)) { continue } else if (key !== 'body' && key !== 'querystring') { - // @ts-expect-error - querystring[key] = params[key] + if (acceptedQuery.includes(key) || commonQueryParams.includes(key)) { + // @ts-expect-error + querystring[key] = params[key] + } else { + body = body ?? {} + // @ts-expect-error + body[key] = params[key] + } } } @@ -907,8 +1959,12 @@ export default class Ml { async getBuckets (this: That, params: T.MlGetBucketsRequest, options?: TransportRequestOptionsWithMeta): Promise<TransportResult<T.MlGetBucketsResponse, unknown>> async getBuckets (this: That, params: T.MlGetBucketsRequest, options?: TransportRequestOptions): Promise<T.MlGetBucketsResponse> async getBuckets (this: That, params: T.MlGetBucketsRequest, options?: TransportRequestOptions): Promise<any> { - const acceptedPath: string[] = ['job_id', 'timestamp'] - const acceptedBody: string[] = ['anomaly_score', 'desc', 'end', 'exclude_interim', 'expand', 'page', 'sort', 'start'] + const { + path: acceptedPath, + body: acceptedBody, + query: acceptedQuery + } = this.acceptedParams['ml.get_buckets'] + const userQuery = params?.querystring const querystring: Record<string, any> = userQuery != null ? { ...userQuery } : {} @@ -930,8 +1986,14 @@ export default class Ml { } else if (acceptedPath.includes(key)) { continue } else if (key !== 'body' && key !== 'querystring') { - // @ts-expect-error - querystring[key] = params[key] + if (acceptedQuery.includes(key) || commonQueryParams.includes(key)) { + // @ts-expect-error + querystring[key] = params[key] + } else { + body = body ?? {} + // @ts-expect-error + body[key] = params[key] + } } } @@ -962,7 +2024,10 @@ export default class Ml { async getCalendarEvents (this: That, params: T.MlGetCalendarEventsRequest, options?: TransportRequestOptionsWithMeta): Promise<TransportResult<T.MlGetCalendarEventsResponse, unknown>> async getCalendarEvents (this: That, params: T.MlGetCalendarEventsRequest, options?: TransportRequestOptions): Promise<T.MlGetCalendarEventsResponse> async getCalendarEvents (this: That, params: T.MlGetCalendarEventsRequest, options?: TransportRequestOptions): Promise<any> { - const acceptedPath: string[] = ['calendar_id'] + const { + path: acceptedPath + } = this.acceptedParams['ml.get_calendar_events'] + const userQuery = params?.querystring const querystring: Record<string, any> = userQuery != null ? { ...userQuery } : {} @@ -1004,8 +2069,12 @@ export default class Ml { async getCalendars (this: That, params?: T.MlGetCalendarsRequest, options?: TransportRequestOptionsWithMeta): Promise<TransportResult<T.MlGetCalendarsResponse, unknown>> async getCalendars (this: That, params?: T.MlGetCalendarsRequest, options?: TransportRequestOptions): Promise<T.MlGetCalendarsResponse> async getCalendars (this: That, params?: T.MlGetCalendarsRequest, options?: TransportRequestOptions): Promise<any> { - const acceptedPath: string[] = ['calendar_id'] - const acceptedBody: string[] = ['page'] + const { + path: acceptedPath, + body: acceptedBody, + query: acceptedQuery + } = this.acceptedParams['ml.get_calendars'] + const userQuery = params?.querystring const querystring: Record<string, any> = userQuery != null ? { ...userQuery } : {} @@ -1028,8 +2097,14 @@ export default class Ml { } else if (acceptedPath.includes(key)) { continue } else if (key !== 'body' && key !== 'querystring') { - // @ts-expect-error - querystring[key] = params[key] + if (acceptedQuery.includes(key) || commonQueryParams.includes(key)) { + // @ts-expect-error + querystring[key] = params[key] + } else { + body = body ?? {} + // @ts-expect-error + body[key] = params[key] + } } } @@ -1059,8 +2134,12 @@ export default class Ml { async getCategories (this: That, params: T.MlGetCategoriesRequest, options?: TransportRequestOptionsWithMeta): Promise<TransportResult<T.MlGetCategoriesResponse, unknown>> async getCategories (this: That, params: T.MlGetCategoriesRequest, options?: TransportRequestOptions): Promise<T.MlGetCategoriesResponse> async getCategories (this: That, params: T.MlGetCategoriesRequest, options?: TransportRequestOptions): Promise<any> { - const acceptedPath: string[] = ['job_id', 'category_id'] - const acceptedBody: string[] = ['page'] + const { + path: acceptedPath, + body: acceptedBody, + query: acceptedQuery + } = this.acceptedParams['ml.get_categories'] + const userQuery = params?.querystring const querystring: Record<string, any> = userQuery != null ? { ...userQuery } : {} @@ -1082,8 +2161,14 @@ export default class Ml { } else if (acceptedPath.includes(key)) { continue } else if (key !== 'body' && key !== 'querystring') { - // @ts-expect-error - querystring[key] = params[key] + if (acceptedQuery.includes(key) || commonQueryParams.includes(key)) { + // @ts-expect-error + querystring[key] = params[key] + } else { + body = body ?? {} + // @ts-expect-error + body[key] = params[key] + } } } @@ -1114,7 +2199,10 @@ export default class Ml { async getDataFrameAnalytics (this: That, params?: T.MlGetDataFrameAnalyticsRequest, options?: TransportRequestOptionsWithMeta): Promise<TransportResult<T.MlGetDataFrameAnalyticsResponse, unknown>> async getDataFrameAnalytics (this: That, params?: T.MlGetDataFrameAnalyticsRequest, options?: TransportRequestOptions): Promise<T.MlGetDataFrameAnalyticsResponse> async getDataFrameAnalytics (this: That, params?: T.MlGetDataFrameAnalyticsRequest, options?: TransportRequestOptions): Promise<any> { - const acceptedPath: string[] = ['id'] + const { + path: acceptedPath + } = this.acceptedParams['ml.get_data_frame_analytics'] + const userQuery = params?.querystring const querystring: Record<string, any> = userQuery != null ? { ...userQuery } : {} @@ -1164,7 +2252,10 @@ export default class Ml { async getDataFrameAnalyticsStats (this: That, params?: T.MlGetDataFrameAnalyticsStatsRequest, options?: TransportRequestOptionsWithMeta): Promise<TransportResult<T.MlGetDataFrameAnalyticsStatsResponse, unknown>> async getDataFrameAnalyticsStats (this: That, params?: T.MlGetDataFrameAnalyticsStatsRequest, options?: TransportRequestOptions): Promise<T.MlGetDataFrameAnalyticsStatsResponse> async getDataFrameAnalyticsStats (this: That, params?: T.MlGetDataFrameAnalyticsStatsRequest, options?: TransportRequestOptions): Promise<any> { - const acceptedPath: string[] = ['id'] + const { + path: acceptedPath + } = this.acceptedParams['ml.get_data_frame_analytics_stats'] + const userQuery = params?.querystring const querystring: Record<string, any> = userQuery != null ? { ...userQuery } : {} @@ -1214,7 +2305,10 @@ export default class Ml { async getDatafeedStats (this: That, params?: T.MlGetDatafeedStatsRequest, options?: TransportRequestOptionsWithMeta): Promise<TransportResult<T.MlGetDatafeedStatsResponse, unknown>> async getDatafeedStats (this: That, params?: T.MlGetDatafeedStatsRequest, options?: TransportRequestOptions): Promise<T.MlGetDatafeedStatsResponse> async getDatafeedStats (this: That, params?: T.MlGetDatafeedStatsRequest, options?: TransportRequestOptions): Promise<any> { - const acceptedPath: string[] = ['datafeed_id'] + const { + path: acceptedPath + } = this.acceptedParams['ml.get_datafeed_stats'] + const userQuery = params?.querystring const querystring: Record<string, any> = userQuery != null ? { ...userQuery } : {} @@ -1264,7 +2358,10 @@ export default class Ml { async getDatafeeds (this: That, params?: T.MlGetDatafeedsRequest, options?: TransportRequestOptionsWithMeta): Promise<TransportResult<T.MlGetDatafeedsResponse, unknown>> async getDatafeeds (this: That, params?: T.MlGetDatafeedsRequest, options?: TransportRequestOptions): Promise<T.MlGetDatafeedsResponse> async getDatafeeds (this: That, params?: T.MlGetDatafeedsRequest, options?: TransportRequestOptions): Promise<any> { - const acceptedPath: string[] = ['datafeed_id'] + const { + path: acceptedPath + } = this.acceptedParams['ml.get_datafeeds'] + const userQuery = params?.querystring const querystring: Record<string, any> = userQuery != null ? { ...userQuery } : {} @@ -1314,7 +2411,10 @@ export default class Ml { async getFilters (this: That, params?: T.MlGetFiltersRequest, options?: TransportRequestOptionsWithMeta): Promise<TransportResult<T.MlGetFiltersResponse, unknown>> async getFilters (this: That, params?: T.MlGetFiltersRequest, options?: TransportRequestOptions): Promise<T.MlGetFiltersResponse> async getFilters (this: That, params?: T.MlGetFiltersRequest, options?: TransportRequestOptions): Promise<any> { - const acceptedPath: string[] = ['filter_id'] + const { + path: acceptedPath + } = this.acceptedParams['ml.get_filters'] + const userQuery = params?.querystring const querystring: Record<string, any> = userQuery != null ? { ...userQuery } : {} @@ -1364,8 +2464,12 @@ export default class Ml { async getInfluencers (this: That, params: T.MlGetInfluencersRequest, options?: TransportRequestOptionsWithMeta): Promise<TransportResult<T.MlGetInfluencersResponse, unknown>> async getInfluencers (this: That, params: T.MlGetInfluencersRequest, options?: TransportRequestOptions): Promise<T.MlGetInfluencersResponse> async getInfluencers (this: That, params: T.MlGetInfluencersRequest, options?: TransportRequestOptions): Promise<any> { - const acceptedPath: string[] = ['job_id'] - const acceptedBody: string[] = ['page'] + const { + path: acceptedPath, + body: acceptedBody, + query: acceptedQuery + } = this.acceptedParams['ml.get_influencers'] + const userQuery = params?.querystring const querystring: Record<string, any> = userQuery != null ? { ...userQuery } : {} @@ -1387,8 +2491,14 @@ export default class Ml { } else if (acceptedPath.includes(key)) { continue } else if (key !== 'body' && key !== 'querystring') { - // @ts-expect-error - querystring[key] = params[key] + if (acceptedQuery.includes(key) || commonQueryParams.includes(key)) { + // @ts-expect-error + querystring[key] = params[key] + } else { + body = body ?? {} + // @ts-expect-error + body[key] = params[key] + } } } @@ -1411,7 +2521,10 @@ export default class Ml { async getJobStats (this: That, params?: T.MlGetJobStatsRequest, options?: TransportRequestOptionsWithMeta): Promise<TransportResult<T.MlGetJobStatsResponse, unknown>> async getJobStats (this: That, params?: T.MlGetJobStatsRequest, options?: TransportRequestOptions): Promise<T.MlGetJobStatsResponse> async getJobStats (this: That, params?: T.MlGetJobStatsRequest, options?: TransportRequestOptions): Promise<any> { - const acceptedPath: string[] = ['job_id'] + const { + path: acceptedPath + } = this.acceptedParams['ml.get_job_stats'] + const userQuery = params?.querystring const querystring: Record<string, any> = userQuery != null ? { ...userQuery } : {} @@ -1461,7 +2574,10 @@ export default class Ml { async getJobs (this: That, params?: T.MlGetJobsRequest, options?: TransportRequestOptionsWithMeta): Promise<TransportResult<T.MlGetJobsResponse, unknown>> async getJobs (this: That, params?: T.MlGetJobsRequest, options?: TransportRequestOptions): Promise<T.MlGetJobsResponse> async getJobs (this: That, params?: T.MlGetJobsRequest, options?: TransportRequestOptions): Promise<any> { - const acceptedPath: string[] = ['job_id'] + const { + path: acceptedPath + } = this.acceptedParams['ml.get_jobs'] + const userQuery = params?.querystring const querystring: Record<string, any> = userQuery != null ? { ...userQuery } : {} @@ -1511,7 +2627,10 @@ export default class Ml { async getMemoryStats (this: That, params?: T.MlGetMemoryStatsRequest, options?: TransportRequestOptionsWithMeta): Promise<TransportResult<T.MlGetMemoryStatsResponse, unknown>> async getMemoryStats (this: That, params?: T.MlGetMemoryStatsRequest, options?: TransportRequestOptions): Promise<T.MlGetMemoryStatsResponse> async getMemoryStats (this: That, params?: T.MlGetMemoryStatsRequest, options?: TransportRequestOptions): Promise<any> { - const acceptedPath: string[] = ['node_id'] + const { + path: acceptedPath + } = this.acceptedParams['ml.get_memory_stats'] + const userQuery = params?.querystring const querystring: Record<string, any> = userQuery != null ? { ...userQuery } : {} @@ -1561,7 +2680,10 @@ export default class Ml { async getModelSnapshotUpgradeStats (this: That, params: T.MlGetModelSnapshotUpgradeStatsRequest, options?: TransportRequestOptionsWithMeta): Promise<TransportResult<T.MlGetModelSnapshotUpgradeStatsResponse, unknown>> async getModelSnapshotUpgradeStats (this: That, params: T.MlGetModelSnapshotUpgradeStatsRequest, options?: TransportRequestOptions): Promise<T.MlGetModelSnapshotUpgradeStatsResponse> async getModelSnapshotUpgradeStats (this: That, params: T.MlGetModelSnapshotUpgradeStatsRequest, options?: TransportRequestOptions): Promise<any> { - const acceptedPath: string[] = ['job_id', 'snapshot_id'] + const { + path: acceptedPath + } = this.acceptedParams['ml.get_model_snapshot_upgrade_stats'] + const userQuery = params?.querystring const querystring: Record<string, any> = userQuery != null ? { ...userQuery } : {} @@ -1604,8 +2726,12 @@ export default class Ml { async getModelSnapshots (this: That, params: T.MlGetModelSnapshotsRequest, options?: TransportRequestOptionsWithMeta): Promise<TransportResult<T.MlGetModelSnapshotsResponse, unknown>> async getModelSnapshots (this: That, params: T.MlGetModelSnapshotsRequest, options?: TransportRequestOptions): Promise<T.MlGetModelSnapshotsResponse> async getModelSnapshots (this: That, params: T.MlGetModelSnapshotsRequest, options?: TransportRequestOptions): Promise<any> { - const acceptedPath: string[] = ['job_id', 'snapshot_id'] - const acceptedBody: string[] = ['desc', 'end', 'page', 'sort', 'start'] + const { + path: acceptedPath, + body: acceptedBody, + query: acceptedQuery + } = this.acceptedParams['ml.get_model_snapshots'] + const userQuery = params?.querystring const querystring: Record<string, any> = userQuery != null ? { ...userQuery } : {} @@ -1627,8 +2753,14 @@ export default class Ml { } else if (acceptedPath.includes(key)) { continue } else if (key !== 'body' && key !== 'querystring') { - // @ts-expect-error - querystring[key] = params[key] + if (acceptedQuery.includes(key) || commonQueryParams.includes(key)) { + // @ts-expect-error + querystring[key] = params[key] + } else { + body = body ?? {} + // @ts-expect-error + body[key] = params[key] + } } } @@ -1659,8 +2791,12 @@ export default class Ml { async getOverallBuckets (this: That, params: T.MlGetOverallBucketsRequest, options?: TransportRequestOptionsWithMeta): Promise<TransportResult<T.MlGetOverallBucketsResponse, unknown>> async getOverallBuckets (this: That, params: T.MlGetOverallBucketsRequest, options?: TransportRequestOptions): Promise<T.MlGetOverallBucketsResponse> async getOverallBuckets (this: That, params: T.MlGetOverallBucketsRequest, options?: TransportRequestOptions): Promise<any> { - const acceptedPath: string[] = ['job_id'] - const acceptedBody: string[] = ['allow_no_match', 'bucket_span', 'end', 'exclude_interim', 'overall_score', 'start', 'top_n'] + const { + path: acceptedPath, + body: acceptedBody, + query: acceptedQuery + } = this.acceptedParams['ml.get_overall_buckets'] + const userQuery = params?.querystring const querystring: Record<string, any> = userQuery != null ? { ...userQuery } : {} @@ -1682,8 +2818,14 @@ export default class Ml { } else if (acceptedPath.includes(key)) { continue } else if (key !== 'body' && key !== 'querystring') { - // @ts-expect-error - querystring[key] = params[key] + if (acceptedQuery.includes(key) || commonQueryParams.includes(key)) { + // @ts-expect-error + querystring[key] = params[key] + } else { + body = body ?? {} + // @ts-expect-error + body[key] = params[key] + } } } @@ -1706,8 +2848,12 @@ export default class Ml { async getRecords (this: That, params: T.MlGetRecordsRequest, options?: TransportRequestOptionsWithMeta): Promise<TransportResult<T.MlGetRecordsResponse, unknown>> async getRecords (this: That, params: T.MlGetRecordsRequest, options?: TransportRequestOptions): Promise<T.MlGetRecordsResponse> async getRecords (this: That, params: T.MlGetRecordsRequest, options?: TransportRequestOptions): Promise<any> { - const acceptedPath: string[] = ['job_id'] - const acceptedBody: string[] = ['desc', 'end', 'exclude_interim', 'page', 'record_score', 'sort', 'start'] + const { + path: acceptedPath, + body: acceptedBody, + query: acceptedQuery + } = this.acceptedParams['ml.get_records'] + const userQuery = params?.querystring const querystring: Record<string, any> = userQuery != null ? { ...userQuery } : {} @@ -1729,8 +2875,14 @@ export default class Ml { } else if (acceptedPath.includes(key)) { continue } else if (key !== 'body' && key !== 'querystring') { - // @ts-expect-error - querystring[key] = params[key] + if (acceptedQuery.includes(key) || commonQueryParams.includes(key)) { + // @ts-expect-error + querystring[key] = params[key] + } else { + body = body ?? {} + // @ts-expect-error + body[key] = params[key] + } } } @@ -1753,7 +2905,10 @@ export default class Ml { async getTrainedModels (this: That, params?: T.MlGetTrainedModelsRequest, options?: TransportRequestOptionsWithMeta): Promise<TransportResult<T.MlGetTrainedModelsResponse, unknown>> async getTrainedModels (this: That, params?: T.MlGetTrainedModelsRequest, options?: TransportRequestOptions): Promise<T.MlGetTrainedModelsResponse> async getTrainedModels (this: That, params?: T.MlGetTrainedModelsRequest, options?: TransportRequestOptions): Promise<any> { - const acceptedPath: string[] = ['model_id'] + const { + path: acceptedPath + } = this.acceptedParams['ml.get_trained_models'] + const userQuery = params?.querystring const querystring: Record<string, any> = userQuery != null ? { ...userQuery } : {} @@ -1803,7 +2958,10 @@ export default class Ml { async getTrainedModelsStats (this: That, params?: T.MlGetTrainedModelsStatsRequest, options?: TransportRequestOptionsWithMeta): Promise<TransportResult<T.MlGetTrainedModelsStatsResponse, unknown>> async getTrainedModelsStats (this: That, params?: T.MlGetTrainedModelsStatsRequest, options?: TransportRequestOptions): Promise<T.MlGetTrainedModelsStatsResponse> async getTrainedModelsStats (this: That, params?: T.MlGetTrainedModelsStatsRequest, options?: TransportRequestOptions): Promise<any> { - const acceptedPath: string[] = ['model_id'] + const { + path: acceptedPath + } = this.acceptedParams['ml.get_trained_models_stats'] + const userQuery = params?.querystring const querystring: Record<string, any> = userQuery != null ? { ...userQuery } : {} @@ -1853,8 +3011,12 @@ export default class Ml { async inferTrainedModel (this: That, params: T.MlInferTrainedModelRequest, options?: TransportRequestOptionsWithMeta): Promise<TransportResult<T.MlInferTrainedModelResponse, unknown>> async inferTrainedModel (this: That, params: T.MlInferTrainedModelRequest, options?: TransportRequestOptions): Promise<T.MlInferTrainedModelResponse> async inferTrainedModel (this: That, params: T.MlInferTrainedModelRequest, options?: TransportRequestOptions): Promise<any> { - const acceptedPath: string[] = ['model_id'] - const acceptedBody: string[] = ['docs', 'inference_config'] + const { + path: acceptedPath, + body: acceptedBody, + query: acceptedQuery + } = this.acceptedParams['ml.infer_trained_model'] + const userQuery = params?.querystring const querystring: Record<string, any> = userQuery != null ? { ...userQuery } : {} @@ -1876,8 +3038,14 @@ export default class Ml { } else if (acceptedPath.includes(key)) { continue } else if (key !== 'body' && key !== 'querystring') { - // @ts-expect-error - querystring[key] = params[key] + if (acceptedQuery.includes(key) || commonQueryParams.includes(key)) { + // @ts-expect-error + querystring[key] = params[key] + } else { + body = body ?? {} + // @ts-expect-error + body[key] = params[key] + } } } @@ -1900,7 +3068,10 @@ export default class Ml { async info (this: That, params?: T.MlInfoRequest, options?: TransportRequestOptionsWithMeta): Promise<TransportResult<T.MlInfoResponse, unknown>> async info (this: That, params?: T.MlInfoRequest, options?: TransportRequestOptions): Promise<T.MlInfoResponse> async info (this: That, params?: T.MlInfoRequest, options?: TransportRequestOptions): Promise<any> { - const acceptedPath: string[] = [] + const { + path: acceptedPath + } = this.acceptedParams['ml.info'] + const userQuery = params?.querystring const querystring: Record<string, any> = userQuery != null ? { ...userQuery } : {} @@ -1940,8 +3111,12 @@ export default class Ml { async openJob (this: That, params: T.MlOpenJobRequest, options?: TransportRequestOptionsWithMeta): Promise<TransportResult<T.MlOpenJobResponse, unknown>> async openJob (this: That, params: T.MlOpenJobRequest, options?: TransportRequestOptions): Promise<T.MlOpenJobResponse> async openJob (this: That, params: T.MlOpenJobRequest, options?: TransportRequestOptions): Promise<any> { - const acceptedPath: string[] = ['job_id'] - const acceptedBody: string[] = ['timeout'] + const { + path: acceptedPath, + body: acceptedBody, + query: acceptedQuery + } = this.acceptedParams['ml.open_job'] + const userQuery = params?.querystring const querystring: Record<string, any> = userQuery != null ? { ...userQuery } : {} @@ -1963,8 +3138,14 @@ export default class Ml { } else if (acceptedPath.includes(key)) { continue } else if (key !== 'body' && key !== 'querystring') { - // @ts-expect-error - querystring[key] = params[key] + if (acceptedQuery.includes(key) || commonQueryParams.includes(key)) { + // @ts-expect-error + querystring[key] = params[key] + } else { + body = body ?? {} + // @ts-expect-error + body[key] = params[key] + } } } @@ -1987,8 +3168,12 @@ export default class Ml { async postCalendarEvents (this: That, params: T.MlPostCalendarEventsRequest, options?: TransportRequestOptionsWithMeta): Promise<TransportResult<T.MlPostCalendarEventsResponse, unknown>> async postCalendarEvents (this: That, params: T.MlPostCalendarEventsRequest, options?: TransportRequestOptions): Promise<T.MlPostCalendarEventsResponse> async postCalendarEvents (this: That, params: T.MlPostCalendarEventsRequest, options?: TransportRequestOptions): Promise<any> { - const acceptedPath: string[] = ['calendar_id'] - const acceptedBody: string[] = ['events'] + const { + path: acceptedPath, + body: acceptedBody, + query: acceptedQuery + } = this.acceptedParams['ml.post_calendar_events'] + const userQuery = params?.querystring const querystring: Record<string, any> = userQuery != null ? { ...userQuery } : {} @@ -2010,8 +3195,14 @@ export default class Ml { } else if (acceptedPath.includes(key)) { continue } else if (key !== 'body' && key !== 'querystring') { - // @ts-expect-error - querystring[key] = params[key] + if (acceptedQuery.includes(key) || commonQueryParams.includes(key)) { + // @ts-expect-error + querystring[key] = params[key] + } else { + body = body ?? {} + // @ts-expect-error + body[key] = params[key] + } } } @@ -2034,8 +3225,12 @@ export default class Ml { async postData<TData = unknown> (this: That, params: T.MlPostDataRequest<TData>, options?: TransportRequestOptionsWithMeta): Promise<TransportResult<T.MlPostDataResponse, unknown>> async postData<TData = unknown> (this: That, params: T.MlPostDataRequest<TData>, options?: TransportRequestOptions): Promise<T.MlPostDataResponse> async postData<TData = unknown> (this: That, params: T.MlPostDataRequest<TData>, options?: TransportRequestOptions): Promise<any> { - const acceptedPath: string[] = ['job_id'] - const acceptedBody: string[] = ['data'] + const { + path: acceptedPath, + body: acceptedBody, + query: acceptedQuery + } = this.acceptedParams['ml.post_data'] + const userQuery = params?.querystring const querystring: Record<string, any> = userQuery != null ? { ...userQuery } : {} @@ -2047,8 +3242,14 @@ export default class Ml { } else if (acceptedPath.includes(key)) { continue } else if (key !== 'body' && key !== 'querystring') { - // @ts-expect-error - querystring[key] = params[key] + if (acceptedQuery.includes(key) || commonQueryParams.includes(key)) { + // @ts-expect-error + querystring[key] = params[key] + } else { + body = body ?? {} + // @ts-expect-error + body[key] = params[key] + } } } @@ -2071,8 +3272,12 @@ export default class Ml { async previewDataFrameAnalytics (this: That, params?: T.MlPreviewDataFrameAnalyticsRequest, options?: TransportRequestOptionsWithMeta): Promise<TransportResult<T.MlPreviewDataFrameAnalyticsResponse, unknown>> async previewDataFrameAnalytics (this: That, params?: T.MlPreviewDataFrameAnalyticsRequest, options?: TransportRequestOptions): Promise<T.MlPreviewDataFrameAnalyticsResponse> async previewDataFrameAnalytics (this: That, params?: T.MlPreviewDataFrameAnalyticsRequest, options?: TransportRequestOptions): Promise<any> { - const acceptedPath: string[] = ['id'] - const acceptedBody: string[] = ['config'] + const { + path: acceptedPath, + body: acceptedBody, + query: acceptedQuery + } = this.acceptedParams['ml.preview_data_frame_analytics'] + const userQuery = params?.querystring const querystring: Record<string, any> = userQuery != null ? { ...userQuery } : {} @@ -2095,8 +3300,14 @@ export default class Ml { } else if (acceptedPath.includes(key)) { continue } else if (key !== 'body' && key !== 'querystring') { - // @ts-expect-error - querystring[key] = params[key] + if (acceptedQuery.includes(key) || commonQueryParams.includes(key)) { + // @ts-expect-error + querystring[key] = params[key] + } else { + body = body ?? {} + // @ts-expect-error + body[key] = params[key] + } } } @@ -2126,8 +3337,12 @@ export default class Ml { async previewDatafeed<TDocument = unknown> (this: That, params?: T.MlPreviewDatafeedRequest, options?: TransportRequestOptionsWithMeta): Promise<TransportResult<T.MlPreviewDatafeedResponse<TDocument>, unknown>> async previewDatafeed<TDocument = unknown> (this: That, params?: T.MlPreviewDatafeedRequest, options?: TransportRequestOptions): Promise<T.MlPreviewDatafeedResponse<TDocument>> async previewDatafeed<TDocument = unknown> (this: That, params?: T.MlPreviewDatafeedRequest, options?: TransportRequestOptions): Promise<any> { - const acceptedPath: string[] = ['datafeed_id'] - const acceptedBody: string[] = ['datafeed_config', 'job_config'] + const { + path: acceptedPath, + body: acceptedBody, + query: acceptedQuery + } = this.acceptedParams['ml.preview_datafeed'] + const userQuery = params?.querystring const querystring: Record<string, any> = userQuery != null ? { ...userQuery } : {} @@ -2150,8 +3365,14 @@ export default class Ml { } else if (acceptedPath.includes(key)) { continue } else if (key !== 'body' && key !== 'querystring') { - // @ts-expect-error - querystring[key] = params[key] + if (acceptedQuery.includes(key) || commonQueryParams.includes(key)) { + // @ts-expect-error + querystring[key] = params[key] + } else { + body = body ?? {} + // @ts-expect-error + body[key] = params[key] + } } } @@ -2181,8 +3402,12 @@ export default class Ml { async putCalendar (this: That, params: T.MlPutCalendarRequest, options?: TransportRequestOptionsWithMeta): Promise<TransportResult<T.MlPutCalendarResponse, unknown>> async putCalendar (this: That, params: T.MlPutCalendarRequest, options?: TransportRequestOptions): Promise<T.MlPutCalendarResponse> async putCalendar (this: That, params: T.MlPutCalendarRequest, options?: TransportRequestOptions): Promise<any> { - const acceptedPath: string[] = ['calendar_id'] - const acceptedBody: string[] = ['job_ids', 'description'] + const { + path: acceptedPath, + body: acceptedBody, + query: acceptedQuery + } = this.acceptedParams['ml.put_calendar'] + const userQuery = params?.querystring const querystring: Record<string, any> = userQuery != null ? { ...userQuery } : {} @@ -2204,8 +3429,14 @@ export default class Ml { } else if (acceptedPath.includes(key)) { continue } else if (key !== 'body' && key !== 'querystring') { - // @ts-expect-error - querystring[key] = params[key] + if (acceptedQuery.includes(key) || commonQueryParams.includes(key)) { + // @ts-expect-error + querystring[key] = params[key] + } else { + body = body ?? {} + // @ts-expect-error + body[key] = params[key] + } } } @@ -2228,7 +3459,10 @@ export default class Ml { async putCalendarJob (this: That, params: T.MlPutCalendarJobRequest, options?: TransportRequestOptionsWithMeta): Promise<TransportResult<T.MlPutCalendarJobResponse, unknown>> async putCalendarJob (this: That, params: T.MlPutCalendarJobRequest, options?: TransportRequestOptions): Promise<T.MlPutCalendarJobResponse> async putCalendarJob (this: That, params: T.MlPutCalendarJobRequest, options?: TransportRequestOptions): Promise<any> { - const acceptedPath: string[] = ['calendar_id', 'job_id'] + const { + path: acceptedPath + } = this.acceptedParams['ml.put_calendar_job'] + const userQuery = params?.querystring const querystring: Record<string, any> = userQuery != null ? { ...userQuery } : {} @@ -2271,8 +3505,12 @@ export default class Ml { async putDataFrameAnalytics (this: That, params: T.MlPutDataFrameAnalyticsRequest, options?: TransportRequestOptionsWithMeta): Promise<TransportResult<T.MlPutDataFrameAnalyticsResponse, unknown>> async putDataFrameAnalytics (this: That, params: T.MlPutDataFrameAnalyticsRequest, options?: TransportRequestOptions): Promise<T.MlPutDataFrameAnalyticsResponse> async putDataFrameAnalytics (this: That, params: T.MlPutDataFrameAnalyticsRequest, options?: TransportRequestOptions): Promise<any> { - const acceptedPath: string[] = ['id'] - const acceptedBody: string[] = ['allow_lazy_start', 'analysis', 'analyzed_fields', 'description', 'dest', 'max_num_threads', '_meta', 'model_memory_limit', 'source', 'headers', 'version'] + const { + path: acceptedPath, + body: acceptedBody, + query: acceptedQuery + } = this.acceptedParams['ml.put_data_frame_analytics'] + const userQuery = params?.querystring const querystring: Record<string, any> = userQuery != null ? { ...userQuery } : {} @@ -2294,8 +3532,14 @@ export default class Ml { } else if (acceptedPath.includes(key)) { continue } else if (key !== 'body' && key !== 'querystring') { - // @ts-expect-error - querystring[key] = params[key] + if (acceptedQuery.includes(key) || commonQueryParams.includes(key)) { + // @ts-expect-error + querystring[key] = params[key] + } else { + body = body ?? {} + // @ts-expect-error + body[key] = params[key] + } } } @@ -2318,8 +3562,12 @@ export default class Ml { async putDatafeed (this: That, params: T.MlPutDatafeedRequest, options?: TransportRequestOptionsWithMeta): Promise<TransportResult<T.MlPutDatafeedResponse, unknown>> async putDatafeed (this: That, params: T.MlPutDatafeedRequest, options?: TransportRequestOptions): Promise<T.MlPutDatafeedResponse> async putDatafeed (this: That, params: T.MlPutDatafeedRequest, options?: TransportRequestOptions): Promise<any> { - const acceptedPath: string[] = ['datafeed_id'] - const acceptedBody: string[] = ['aggregations', 'aggs', 'chunking_config', 'delayed_data_check_config', 'frequency', 'indices', 'indexes', 'indices_options', 'job_id', 'max_empty_searches', 'query', 'query_delay', 'runtime_mappings', 'script_fields', 'scroll_size', 'headers'] + const { + path: acceptedPath, + body: acceptedBody, + query: acceptedQuery + } = this.acceptedParams['ml.put_datafeed'] + const userQuery = params?.querystring const querystring: Record<string, any> = userQuery != null ? { ...userQuery } : {} @@ -2341,8 +3589,14 @@ export default class Ml { } else if (acceptedPath.includes(key)) { continue } else if (key !== 'body' && key !== 'querystring') { - // @ts-expect-error - querystring[key] = params[key] + if (acceptedQuery.includes(key) || commonQueryParams.includes(key)) { + // @ts-expect-error + querystring[key] = params[key] + } else { + body = body ?? {} + // @ts-expect-error + body[key] = params[key] + } } } @@ -2365,8 +3619,12 @@ export default class Ml { async putFilter (this: That, params: T.MlPutFilterRequest, options?: TransportRequestOptionsWithMeta): Promise<TransportResult<T.MlPutFilterResponse, unknown>> async putFilter (this: That, params: T.MlPutFilterRequest, options?: TransportRequestOptions): Promise<T.MlPutFilterResponse> async putFilter (this: That, params: T.MlPutFilterRequest, options?: TransportRequestOptions): Promise<any> { - const acceptedPath: string[] = ['filter_id'] - const acceptedBody: string[] = ['description', 'items'] + const { + path: acceptedPath, + body: acceptedBody, + query: acceptedQuery + } = this.acceptedParams['ml.put_filter'] + const userQuery = params?.querystring const querystring: Record<string, any> = userQuery != null ? { ...userQuery } : {} @@ -2388,8 +3646,14 @@ export default class Ml { } else if (acceptedPath.includes(key)) { continue } else if (key !== 'body' && key !== 'querystring') { - // @ts-expect-error - querystring[key] = params[key] + if (acceptedQuery.includes(key) || commonQueryParams.includes(key)) { + // @ts-expect-error + querystring[key] = params[key] + } else { + body = body ?? {} + // @ts-expect-error + body[key] = params[key] + } } } @@ -2412,8 +3676,12 @@ export default class Ml { async putJob (this: That, params: T.MlPutJobRequest, options?: TransportRequestOptionsWithMeta): Promise<TransportResult<T.MlPutJobResponse, unknown>> async putJob (this: That, params: T.MlPutJobRequest, options?: TransportRequestOptions): Promise<T.MlPutJobResponse> async putJob (this: That, params: T.MlPutJobRequest, options?: TransportRequestOptions): Promise<any> { - const acceptedPath: string[] = [] - const acceptedBody: string[] = ['allow_lazy_open', 'analysis_config', 'analysis_limits', 'background_persist_interval', 'custom_settings', 'daily_model_snapshot_retention_after_days', 'data_description', 'datafeed_config', 'description', 'job_id', 'groups', 'model_plot_config', 'model_snapshot_retention_days', 'renormalization_window_days', 'results_index_name', 'results_retention_days'] + const { + path: acceptedPath, + body: acceptedBody, + query: acceptedQuery + } = this.acceptedParams['ml.put_job'] + const userQuery = params?.querystring const querystring: Record<string, any> = userQuery != null ? { ...userQuery } : {} @@ -2435,8 +3703,14 @@ export default class Ml { } else if (acceptedPath.includes(key)) { continue } else if (key !== 'body' && key !== 'querystring') { - // @ts-expect-error - querystring[key] = params[key] + if (acceptedQuery.includes(key) || commonQueryParams.includes(key)) { + // @ts-expect-error + querystring[key] = params[key] + } else { + body = body ?? {} + // @ts-expect-error + body[key] = params[key] + } } } @@ -2459,8 +3733,12 @@ export default class Ml { async putTrainedModel (this: That, params: T.MlPutTrainedModelRequest, options?: TransportRequestOptionsWithMeta): Promise<TransportResult<T.MlPutTrainedModelResponse, unknown>> async putTrainedModel (this: That, params: T.MlPutTrainedModelRequest, options?: TransportRequestOptions): Promise<T.MlPutTrainedModelResponse> async putTrainedModel (this: That, params: T.MlPutTrainedModelRequest, options?: TransportRequestOptions): Promise<any> { - const acceptedPath: string[] = ['model_id'] - const acceptedBody: string[] = ['compressed_definition', 'definition', 'description', 'inference_config', 'input', 'metadata', 'model_type', 'model_size_bytes', 'platform_architecture', 'tags', 'prefix_strings'] + const { + path: acceptedPath, + body: acceptedBody, + query: acceptedQuery + } = this.acceptedParams['ml.put_trained_model'] + const userQuery = params?.querystring const querystring: Record<string, any> = userQuery != null ? { ...userQuery } : {} @@ -2482,8 +3760,14 @@ export default class Ml { } else if (acceptedPath.includes(key)) { continue } else if (key !== 'body' && key !== 'querystring') { - // @ts-expect-error - querystring[key] = params[key] + if (acceptedQuery.includes(key) || commonQueryParams.includes(key)) { + // @ts-expect-error + querystring[key] = params[key] + } else { + body = body ?? {} + // @ts-expect-error + body[key] = params[key] + } } } @@ -2506,7 +3790,10 @@ export default class Ml { async putTrainedModelAlias (this: That, params: T.MlPutTrainedModelAliasRequest, options?: TransportRequestOptionsWithMeta): Promise<TransportResult<T.MlPutTrainedModelAliasResponse, unknown>> async putTrainedModelAlias (this: That, params: T.MlPutTrainedModelAliasRequest, options?: TransportRequestOptions): Promise<T.MlPutTrainedModelAliasResponse> async putTrainedModelAlias (this: That, params: T.MlPutTrainedModelAliasRequest, options?: TransportRequestOptions): Promise<any> { - const acceptedPath: string[] = ['model_alias', 'model_id'] + const { + path: acceptedPath + } = this.acceptedParams['ml.put_trained_model_alias'] + const userQuery = params?.querystring const querystring: Record<string, any> = userQuery != null ? { ...userQuery } : {} @@ -2549,8 +3836,12 @@ export default class Ml { async putTrainedModelDefinitionPart (this: That, params: T.MlPutTrainedModelDefinitionPartRequest, options?: TransportRequestOptionsWithMeta): Promise<TransportResult<T.MlPutTrainedModelDefinitionPartResponse, unknown>> async putTrainedModelDefinitionPart (this: That, params: T.MlPutTrainedModelDefinitionPartRequest, options?: TransportRequestOptions): Promise<T.MlPutTrainedModelDefinitionPartResponse> async putTrainedModelDefinitionPart (this: That, params: T.MlPutTrainedModelDefinitionPartRequest, options?: TransportRequestOptions): Promise<any> { - const acceptedPath: string[] = ['model_id', 'part'] - const acceptedBody: string[] = ['definition', 'total_definition_length', 'total_parts'] + const { + path: acceptedPath, + body: acceptedBody, + query: acceptedQuery + } = this.acceptedParams['ml.put_trained_model_definition_part'] + const userQuery = params?.querystring const querystring: Record<string, any> = userQuery != null ? { ...userQuery } : {} @@ -2572,8 +3863,14 @@ export default class Ml { } else if (acceptedPath.includes(key)) { continue } else if (key !== 'body' && key !== 'querystring') { - // @ts-expect-error - querystring[key] = params[key] + if (acceptedQuery.includes(key) || commonQueryParams.includes(key)) { + // @ts-expect-error + querystring[key] = params[key] + } else { + body = body ?? {} + // @ts-expect-error + body[key] = params[key] + } } } @@ -2597,8 +3894,12 @@ export default class Ml { async putTrainedModelVocabulary (this: That, params: T.MlPutTrainedModelVocabularyRequest, options?: TransportRequestOptionsWithMeta): Promise<TransportResult<T.MlPutTrainedModelVocabularyResponse, unknown>> async putTrainedModelVocabulary (this: That, params: T.MlPutTrainedModelVocabularyRequest, options?: TransportRequestOptions): Promise<T.MlPutTrainedModelVocabularyResponse> async putTrainedModelVocabulary (this: That, params: T.MlPutTrainedModelVocabularyRequest, options?: TransportRequestOptions): Promise<any> { - const acceptedPath: string[] = ['model_id'] - const acceptedBody: string[] = ['vocabulary', 'merges', 'scores'] + const { + path: acceptedPath, + body: acceptedBody, + query: acceptedQuery + } = this.acceptedParams['ml.put_trained_model_vocabulary'] + const userQuery = params?.querystring const querystring: Record<string, any> = userQuery != null ? { ...userQuery } : {} @@ -2620,8 +3921,14 @@ export default class Ml { } else if (acceptedPath.includes(key)) { continue } else if (key !== 'body' && key !== 'querystring') { - // @ts-expect-error - querystring[key] = params[key] + if (acceptedQuery.includes(key) || commonQueryParams.includes(key)) { + // @ts-expect-error + querystring[key] = params[key] + } else { + body = body ?? {} + // @ts-expect-error + body[key] = params[key] + } } } @@ -2644,7 +3951,10 @@ export default class Ml { async resetJob (this: That, params: T.MlResetJobRequest, options?: TransportRequestOptionsWithMeta): Promise<TransportResult<T.MlResetJobResponse, unknown>> async resetJob (this: That, params: T.MlResetJobRequest, options?: TransportRequestOptions): Promise<T.MlResetJobResponse> async resetJob (this: That, params: T.MlResetJobRequest, options?: TransportRequestOptions): Promise<any> { - const acceptedPath: string[] = ['job_id'] + const { + path: acceptedPath + } = this.acceptedParams['ml.reset_job'] + const userQuery = params?.querystring const querystring: Record<string, any> = userQuery != null ? { ...userQuery } : {} @@ -2686,8 +3996,12 @@ export default class Ml { async revertModelSnapshot (this: That, params: T.MlRevertModelSnapshotRequest, options?: TransportRequestOptionsWithMeta): Promise<TransportResult<T.MlRevertModelSnapshotResponse, unknown>> async revertModelSnapshot (this: That, params: T.MlRevertModelSnapshotRequest, options?: TransportRequestOptions): Promise<T.MlRevertModelSnapshotResponse> async revertModelSnapshot (this: That, params: T.MlRevertModelSnapshotRequest, options?: TransportRequestOptions): Promise<any> { - const acceptedPath: string[] = ['job_id', 'snapshot_id'] - const acceptedBody: string[] = ['delete_intervening_results'] + const { + path: acceptedPath, + body: acceptedBody, + query: acceptedQuery + } = this.acceptedParams['ml.revert_model_snapshot'] + const userQuery = params?.querystring const querystring: Record<string, any> = userQuery != null ? { ...userQuery } : {} @@ -2709,8 +4023,14 @@ export default class Ml { } else if (acceptedPath.includes(key)) { continue } else if (key !== 'body' && key !== 'querystring') { - // @ts-expect-error - querystring[key] = params[key] + if (acceptedQuery.includes(key) || commonQueryParams.includes(key)) { + // @ts-expect-error + querystring[key] = params[key] + } else { + body = body ?? {} + // @ts-expect-error + body[key] = params[key] + } } } @@ -2734,7 +4054,10 @@ export default class Ml { async setUpgradeMode (this: That, params?: T.MlSetUpgradeModeRequest, options?: TransportRequestOptionsWithMeta): Promise<TransportResult<T.MlSetUpgradeModeResponse, unknown>> async setUpgradeMode (this: That, params?: T.MlSetUpgradeModeRequest, options?: TransportRequestOptions): Promise<T.MlSetUpgradeModeResponse> async setUpgradeMode (this: That, params?: T.MlSetUpgradeModeRequest, options?: TransportRequestOptions): Promise<any> { - const acceptedPath: string[] = [] + const { + path: acceptedPath + } = this.acceptedParams['ml.set_upgrade_mode'] + const userQuery = params?.querystring const querystring: Record<string, any> = userQuery != null ? { ...userQuery } : {} @@ -2774,7 +4097,10 @@ export default class Ml { async startDataFrameAnalytics (this: That, params: T.MlStartDataFrameAnalyticsRequest, options?: TransportRequestOptionsWithMeta): Promise<TransportResult<T.MlStartDataFrameAnalyticsResponse, unknown>> async startDataFrameAnalytics (this: That, params: T.MlStartDataFrameAnalyticsRequest, options?: TransportRequestOptions): Promise<T.MlStartDataFrameAnalyticsResponse> async startDataFrameAnalytics (this: That, params: T.MlStartDataFrameAnalyticsRequest, options?: TransportRequestOptions): Promise<any> { - const acceptedPath: string[] = ['id'] + const { + path: acceptedPath + } = this.acceptedParams['ml.start_data_frame_analytics'] + const userQuery = params?.querystring const querystring: Record<string, any> = userQuery != null ? { ...userQuery } : {} @@ -2816,8 +4142,12 @@ export default class Ml { async startDatafeed (this: That, params: T.MlStartDatafeedRequest, options?: TransportRequestOptionsWithMeta): Promise<TransportResult<T.MlStartDatafeedResponse, unknown>> async startDatafeed (this: That, params: T.MlStartDatafeedRequest, options?: TransportRequestOptions): Promise<T.MlStartDatafeedResponse> async startDatafeed (this: That, params: T.MlStartDatafeedRequest, options?: TransportRequestOptions): Promise<any> { - const acceptedPath: string[] = ['datafeed_id'] - const acceptedBody: string[] = ['end', 'start', 'timeout'] + const { + path: acceptedPath, + body: acceptedBody, + query: acceptedQuery + } = this.acceptedParams['ml.start_datafeed'] + const userQuery = params?.querystring const querystring: Record<string, any> = userQuery != null ? { ...userQuery } : {} @@ -2839,8 +4169,14 @@ export default class Ml { } else if (acceptedPath.includes(key)) { continue } else if (key !== 'body' && key !== 'querystring') { - // @ts-expect-error - querystring[key] = params[key] + if (acceptedQuery.includes(key) || commonQueryParams.includes(key)) { + // @ts-expect-error + querystring[key] = params[key] + } else { + body = body ?? {} + // @ts-expect-error + body[key] = params[key] + } } } @@ -2863,8 +4199,12 @@ export default class Ml { async startTrainedModelDeployment (this: That, params: T.MlStartTrainedModelDeploymentRequest, options?: TransportRequestOptionsWithMeta): Promise<TransportResult<T.MlStartTrainedModelDeploymentResponse, unknown>> async startTrainedModelDeployment (this: That, params: T.MlStartTrainedModelDeploymentRequest, options?: TransportRequestOptions): Promise<T.MlStartTrainedModelDeploymentResponse> async startTrainedModelDeployment (this: That, params: T.MlStartTrainedModelDeploymentRequest, options?: TransportRequestOptions): Promise<any> { - const acceptedPath: string[] = ['model_id'] - const acceptedBody: string[] = ['adaptive_allocations'] + const { + path: acceptedPath, + body: acceptedBody, + query: acceptedQuery + } = this.acceptedParams['ml.start_trained_model_deployment'] + const userQuery = params?.querystring const querystring: Record<string, any> = userQuery != null ? { ...userQuery } : {} @@ -2886,8 +4226,14 @@ export default class Ml { } else if (acceptedPath.includes(key)) { continue } else if (key !== 'body' && key !== 'querystring') { - // @ts-expect-error - querystring[key] = params[key] + if (acceptedQuery.includes(key) || commonQueryParams.includes(key)) { + // @ts-expect-error + querystring[key] = params[key] + } else { + body = body ?? {} + // @ts-expect-error + body[key] = params[key] + } } } @@ -2910,7 +4256,10 @@ export default class Ml { async stopDataFrameAnalytics (this: That, params: T.MlStopDataFrameAnalyticsRequest, options?: TransportRequestOptionsWithMeta): Promise<TransportResult<T.MlStopDataFrameAnalyticsResponse, unknown>> async stopDataFrameAnalytics (this: That, params: T.MlStopDataFrameAnalyticsRequest, options?: TransportRequestOptions): Promise<T.MlStopDataFrameAnalyticsResponse> async stopDataFrameAnalytics (this: That, params: T.MlStopDataFrameAnalyticsRequest, options?: TransportRequestOptions): Promise<any> { - const acceptedPath: string[] = ['id'] + const { + path: acceptedPath + } = this.acceptedParams['ml.stop_data_frame_analytics'] + const userQuery = params?.querystring const querystring: Record<string, any> = userQuery != null ? { ...userQuery } : {} @@ -2952,8 +4301,12 @@ export default class Ml { async stopDatafeed (this: That, params: T.MlStopDatafeedRequest, options?: TransportRequestOptionsWithMeta): Promise<TransportResult<T.MlStopDatafeedResponse, unknown>> async stopDatafeed (this: That, params: T.MlStopDatafeedRequest, options?: TransportRequestOptions): Promise<T.MlStopDatafeedResponse> async stopDatafeed (this: That, params: T.MlStopDatafeedRequest, options?: TransportRequestOptions): Promise<any> { - const acceptedPath: string[] = ['datafeed_id'] - const acceptedBody: string[] = ['allow_no_match', 'force', 'timeout'] + const { + path: acceptedPath, + body: acceptedBody, + query: acceptedQuery + } = this.acceptedParams['ml.stop_datafeed'] + const userQuery = params?.querystring const querystring: Record<string, any> = userQuery != null ? { ...userQuery } : {} @@ -2975,8 +4328,14 @@ export default class Ml { } else if (acceptedPath.includes(key)) { continue } else if (key !== 'body' && key !== 'querystring') { - // @ts-expect-error - querystring[key] = params[key] + if (acceptedQuery.includes(key) || commonQueryParams.includes(key)) { + // @ts-expect-error + querystring[key] = params[key] + } else { + body = body ?? {} + // @ts-expect-error + body[key] = params[key] + } } } @@ -2999,7 +4358,10 @@ export default class Ml { async stopTrainedModelDeployment (this: That, params: T.MlStopTrainedModelDeploymentRequest, options?: TransportRequestOptionsWithMeta): Promise<TransportResult<T.MlStopTrainedModelDeploymentResponse, unknown>> async stopTrainedModelDeployment (this: That, params: T.MlStopTrainedModelDeploymentRequest, options?: TransportRequestOptions): Promise<T.MlStopTrainedModelDeploymentResponse> async stopTrainedModelDeployment (this: That, params: T.MlStopTrainedModelDeploymentRequest, options?: TransportRequestOptions): Promise<any> { - const acceptedPath: string[] = ['model_id'] + const { + path: acceptedPath + } = this.acceptedParams['ml.stop_trained_model_deployment'] + const userQuery = params?.querystring const querystring: Record<string, any> = userQuery != null ? { ...userQuery } : {} @@ -3041,8 +4403,12 @@ export default class Ml { async updateDataFrameAnalytics (this: That, params: T.MlUpdateDataFrameAnalyticsRequest, options?: TransportRequestOptionsWithMeta): Promise<TransportResult<T.MlUpdateDataFrameAnalyticsResponse, unknown>> async updateDataFrameAnalytics (this: That, params: T.MlUpdateDataFrameAnalyticsRequest, options?: TransportRequestOptions): Promise<T.MlUpdateDataFrameAnalyticsResponse> async updateDataFrameAnalytics (this: That, params: T.MlUpdateDataFrameAnalyticsRequest, options?: TransportRequestOptions): Promise<any> { - const acceptedPath: string[] = ['id'] - const acceptedBody: string[] = ['description', 'model_memory_limit', 'max_num_threads', 'allow_lazy_start'] + const { + path: acceptedPath, + body: acceptedBody, + query: acceptedQuery + } = this.acceptedParams['ml.update_data_frame_analytics'] + const userQuery = params?.querystring const querystring: Record<string, any> = userQuery != null ? { ...userQuery } : {} @@ -3064,8 +4430,14 @@ export default class Ml { } else if (acceptedPath.includes(key)) { continue } else if (key !== 'body' && key !== 'querystring') { - // @ts-expect-error - querystring[key] = params[key] + if (acceptedQuery.includes(key) || commonQueryParams.includes(key)) { + // @ts-expect-error + querystring[key] = params[key] + } else { + body = body ?? {} + // @ts-expect-error + body[key] = params[key] + } } } @@ -3088,8 +4460,12 @@ export default class Ml { async updateDatafeed (this: That, params: T.MlUpdateDatafeedRequest, options?: TransportRequestOptionsWithMeta): Promise<TransportResult<T.MlUpdateDatafeedResponse, unknown>> async updateDatafeed (this: That, params: T.MlUpdateDatafeedRequest, options?: TransportRequestOptions): Promise<T.MlUpdateDatafeedResponse> async updateDatafeed (this: That, params: T.MlUpdateDatafeedRequest, options?: TransportRequestOptions): Promise<any> { - const acceptedPath: string[] = ['datafeed_id'] - const acceptedBody: string[] = ['aggregations', 'chunking_config', 'delayed_data_check_config', 'frequency', 'indices', 'indexes', 'indices_options', 'job_id', 'max_empty_searches', 'query', 'query_delay', 'runtime_mappings', 'script_fields', 'scroll_size'] + const { + path: acceptedPath, + body: acceptedBody, + query: acceptedQuery + } = this.acceptedParams['ml.update_datafeed'] + const userQuery = params?.querystring const querystring: Record<string, any> = userQuery != null ? { ...userQuery } : {} @@ -3111,8 +4487,14 @@ export default class Ml { } else if (acceptedPath.includes(key)) { continue } else if (key !== 'body' && key !== 'querystring') { - // @ts-expect-error - querystring[key] = params[key] + if (acceptedQuery.includes(key) || commonQueryParams.includes(key)) { + // @ts-expect-error + querystring[key] = params[key] + } else { + body = body ?? {} + // @ts-expect-error + body[key] = params[key] + } } } @@ -3135,8 +4517,12 @@ export default class Ml { async updateFilter (this: That, params: T.MlUpdateFilterRequest, options?: TransportRequestOptionsWithMeta): Promise<TransportResult<T.MlUpdateFilterResponse, unknown>> async updateFilter (this: That, params: T.MlUpdateFilterRequest, options?: TransportRequestOptions): Promise<T.MlUpdateFilterResponse> async updateFilter (this: That, params: T.MlUpdateFilterRequest, options?: TransportRequestOptions): Promise<any> { - const acceptedPath: string[] = ['filter_id'] - const acceptedBody: string[] = ['add_items', 'description', 'remove_items'] + const { + path: acceptedPath, + body: acceptedBody, + query: acceptedQuery + } = this.acceptedParams['ml.update_filter'] + const userQuery = params?.querystring const querystring: Record<string, any> = userQuery != null ? { ...userQuery } : {} @@ -3158,8 +4544,14 @@ export default class Ml { } else if (acceptedPath.includes(key)) { continue } else if (key !== 'body' && key !== 'querystring') { - // @ts-expect-error - querystring[key] = params[key] + if (acceptedQuery.includes(key) || commonQueryParams.includes(key)) { + // @ts-expect-error + querystring[key] = params[key] + } else { + body = body ?? {} + // @ts-expect-error + body[key] = params[key] + } } } @@ -3182,8 +4574,12 @@ export default class Ml { async updateJob (this: That, params: T.MlUpdateJobRequest, options?: TransportRequestOptionsWithMeta): Promise<TransportResult<T.MlUpdateJobResponse, unknown>> async updateJob (this: That, params: T.MlUpdateJobRequest, options?: TransportRequestOptions): Promise<T.MlUpdateJobResponse> async updateJob (this: That, params: T.MlUpdateJobRequest, options?: TransportRequestOptions): Promise<any> { - const acceptedPath: string[] = ['job_id'] - const acceptedBody: string[] = ['allow_lazy_open', 'analysis_limits', 'background_persist_interval', 'custom_settings', 'categorization_filters', 'description', 'model_plot_config', 'model_prune_window', 'daily_model_snapshot_retention_after_days', 'model_snapshot_retention_days', 'renormalization_window_days', 'results_retention_days', 'groups', 'detectors', 'per_partition_categorization'] + const { + path: acceptedPath, + body: acceptedBody, + query: acceptedQuery + } = this.acceptedParams['ml.update_job'] + const userQuery = params?.querystring const querystring: Record<string, any> = userQuery != null ? { ...userQuery } : {} @@ -3205,8 +4601,14 @@ export default class Ml { } else if (acceptedPath.includes(key)) { continue } else if (key !== 'body' && key !== 'querystring') { - // @ts-expect-error - querystring[key] = params[key] + if (acceptedQuery.includes(key) || commonQueryParams.includes(key)) { + // @ts-expect-error + querystring[key] = params[key] + } else { + body = body ?? {} + // @ts-expect-error + body[key] = params[key] + } } } @@ -3229,8 +4631,12 @@ export default class Ml { async updateModelSnapshot (this: That, params: T.MlUpdateModelSnapshotRequest, options?: TransportRequestOptionsWithMeta): Promise<TransportResult<T.MlUpdateModelSnapshotResponse, unknown>> async updateModelSnapshot (this: That, params: T.MlUpdateModelSnapshotRequest, options?: TransportRequestOptions): Promise<T.MlUpdateModelSnapshotResponse> async updateModelSnapshot (this: That, params: T.MlUpdateModelSnapshotRequest, options?: TransportRequestOptions): Promise<any> { - const acceptedPath: string[] = ['job_id', 'snapshot_id'] - const acceptedBody: string[] = ['description', 'retain'] + const { + path: acceptedPath, + body: acceptedBody, + query: acceptedQuery + } = this.acceptedParams['ml.update_model_snapshot'] + const userQuery = params?.querystring const querystring: Record<string, any> = userQuery != null ? { ...userQuery } : {} @@ -3252,8 +4658,14 @@ export default class Ml { } else if (acceptedPath.includes(key)) { continue } else if (key !== 'body' && key !== 'querystring') { - // @ts-expect-error - querystring[key] = params[key] + if (acceptedQuery.includes(key) || commonQueryParams.includes(key)) { + // @ts-expect-error + querystring[key] = params[key] + } else { + body = body ?? {} + // @ts-expect-error + body[key] = params[key] + } } } @@ -3277,8 +4689,12 @@ export default class Ml { async updateTrainedModelDeployment (this: That, params: T.MlUpdateTrainedModelDeploymentRequest, options?: TransportRequestOptionsWithMeta): Promise<TransportResult<T.MlUpdateTrainedModelDeploymentResponse, unknown>> async updateTrainedModelDeployment (this: That, params: T.MlUpdateTrainedModelDeploymentRequest, options?: TransportRequestOptions): Promise<T.MlUpdateTrainedModelDeploymentResponse> async updateTrainedModelDeployment (this: That, params: T.MlUpdateTrainedModelDeploymentRequest, options?: TransportRequestOptions): Promise<any> { - const acceptedPath: string[] = ['model_id'] - const acceptedBody: string[] = ['number_of_allocations', 'adaptive_allocations'] + const { + path: acceptedPath, + body: acceptedBody, + query: acceptedQuery + } = this.acceptedParams['ml.update_trained_model_deployment'] + const userQuery = params?.querystring const querystring: Record<string, any> = userQuery != null ? { ...userQuery } : {} @@ -3300,8 +4716,14 @@ export default class Ml { } else if (acceptedPath.includes(key)) { continue } else if (key !== 'body' && key !== 'querystring') { - // @ts-expect-error - querystring[key] = params[key] + if (acceptedQuery.includes(key) || commonQueryParams.includes(key)) { + // @ts-expect-error + querystring[key] = params[key] + } else { + body = body ?? {} + // @ts-expect-error + body[key] = params[key] + } } } @@ -3324,7 +4746,10 @@ export default class Ml { async upgradeJobSnapshot (this: That, params: T.MlUpgradeJobSnapshotRequest, options?: TransportRequestOptionsWithMeta): Promise<TransportResult<T.MlUpgradeJobSnapshotResponse, unknown>> async upgradeJobSnapshot (this: That, params: T.MlUpgradeJobSnapshotRequest, options?: TransportRequestOptions): Promise<T.MlUpgradeJobSnapshotResponse> async upgradeJobSnapshot (this: That, params: T.MlUpgradeJobSnapshotRequest, options?: TransportRequestOptions): Promise<any> { - const acceptedPath: string[] = ['job_id', 'snapshot_id'] + const { + path: acceptedPath + } = this.acceptedParams['ml.upgrade_job_snapshot'] + const userQuery = params?.querystring const querystring: Record<string, any> = userQuery != null ? { ...userQuery } : {} @@ -3367,8 +4792,12 @@ export default class Ml { async validate (this: That, params?: T.MlValidateRequest, options?: TransportRequestOptionsWithMeta): Promise<TransportResult<T.MlValidateResponse, unknown>> async validate (this: That, params?: T.MlValidateRequest, options?: TransportRequestOptions): Promise<T.MlValidateResponse> async validate (this: That, params?: T.MlValidateRequest, options?: TransportRequestOptions): Promise<any> { - const acceptedPath: string[] = [] - const acceptedBody: string[] = ['job_id', 'analysis_config', 'analysis_limits', 'data_description', 'description', 'model_plot', 'model_snapshot_id', 'model_snapshot_retention_days', 'results_index_name'] + const { + path: acceptedPath, + body: acceptedBody, + query: acceptedQuery + } = this.acceptedParams['ml.validate'] + const userQuery = params?.querystring const querystring: Record<string, any> = userQuery != null ? { ...userQuery } : {} @@ -3391,8 +4820,14 @@ export default class Ml { } else if (acceptedPath.includes(key)) { continue } else if (key !== 'body' && key !== 'querystring') { - // @ts-expect-error - querystring[key] = params[key] + if (acceptedQuery.includes(key) || commonQueryParams.includes(key)) { + // @ts-expect-error + querystring[key] = params[key] + } else { + body = body ?? {} + // @ts-expect-error + body[key] = params[key] + } } } @@ -3412,8 +4847,12 @@ export default class Ml { async validateDetector (this: That, params: T.MlValidateDetectorRequest, options?: TransportRequestOptionsWithMeta): Promise<TransportResult<T.MlValidateDetectorResponse, unknown>> async validateDetector (this: That, params: T.MlValidateDetectorRequest, options?: TransportRequestOptions): Promise<T.MlValidateDetectorResponse> async validateDetector (this: That, params: T.MlValidateDetectorRequest, options?: TransportRequestOptions): Promise<any> { - const acceptedPath: string[] = [] - const acceptedBody: string[] = ['detector'] + const { + path: acceptedPath, + body: acceptedBody, + query: acceptedQuery + } = this.acceptedParams['ml.validate_detector'] + const userQuery = params?.querystring const querystring: Record<string, any> = userQuery != null ? { ...userQuery } : {} @@ -3425,8 +4864,14 @@ export default class Ml { } else if (acceptedPath.includes(key)) { continue } else if (key !== 'body' && key !== 'querystring') { - // @ts-expect-error - querystring[key] = params[key] + if (acceptedQuery.includes(key) || commonQueryParams.includes(key)) { + // @ts-expect-error + querystring[key] = params[key] + } else { + body = body ?? {} + // @ts-expect-error + body[key] = params[key] + } } } diff --git a/src/api/api/monitoring.ts b/src/api/api/monitoring.ts index 053fea53a..58bde33fa 100644 --- a/src/api/api/monitoring.ts +++ b/src/api/api/monitoring.ts @@ -35,12 +35,34 @@ import { TransportResult } from '@elastic/transport' import * as T from '../types' -interface That { transport: Transport } + +interface That { + transport: Transport + acceptedParams: Record<string, { path: string[], body: string[], query: string[] }> +} + +const commonQueryParams = ['error_trace', 'filter_path', 'human', 'pretty'] export default class Monitoring { transport: Transport + acceptedParams: Record<string, { path: string[], body: string[], query: string[] }> constructor (transport: Transport) { this.transport = transport + this.acceptedParams = { + 'monitoring.bulk': { + path: [ + 'type' + ], + body: [ + 'operations' + ], + query: [ + 'system_id', + 'system_api_version', + 'interval' + ] + } + } } /** @@ -51,8 +73,12 @@ export default class Monitoring { async bulk<TDocument = unknown, TPartialDocument = unknown> (this: That, params: T.MonitoringBulkRequest<TDocument, TPartialDocument>, options?: TransportRequestOptionsWithMeta): Promise<TransportResult<T.MonitoringBulkResponse, unknown>> async bulk<TDocument = unknown, TPartialDocument = unknown> (this: That, params: T.MonitoringBulkRequest<TDocument, TPartialDocument>, options?: TransportRequestOptions): Promise<T.MonitoringBulkResponse> async bulk<TDocument = unknown, TPartialDocument = unknown> (this: That, params: T.MonitoringBulkRequest<TDocument, TPartialDocument>, options?: TransportRequestOptions): Promise<any> { - const acceptedPath: string[] = ['type'] - const acceptedBody: string[] = ['operations'] + const { + path: acceptedPath, + body: acceptedBody, + query: acceptedQuery + } = this.acceptedParams['monitoring.bulk'] + const userQuery = params?.querystring const querystring: Record<string, any> = userQuery != null ? { ...userQuery } : {} @@ -64,8 +90,14 @@ export default class Monitoring { } else if (acceptedPath.includes(key)) { continue } else if (key !== 'body' && key !== 'querystring') { - // @ts-expect-error - querystring[key] = params[key] + if (acceptedQuery.includes(key) || commonQueryParams.includes(key)) { + // @ts-expect-error + querystring[key] = params[key] + } else { + body = body ?? {} + // @ts-expect-error + body[key] = params[key] + } } } diff --git a/src/api/api/msearch.ts b/src/api/api/msearch.ts index 573c4f385..a70ea2055 100644 --- a/src/api/api/msearch.ts +++ b/src/api/api/msearch.ts @@ -35,7 +35,38 @@ import { TransportResult } from '@elastic/transport' import * as T from '../types' -interface That { transport: Transport } + +interface That { + transport: Transport +} + +const commonQueryParams = ['error_trace', 'filter_path', 'human', 'pretty'] + +const acceptedParams: Record<string, { path: string[], body: string[], query: string[] }> = { + msearch: { + path: [ + 'index' + ], + body: [ + 'searches' + ], + query: [ + 'allow_no_indices', + 'ccs_minimize_roundtrips', + 'expand_wildcards', + 'ignore_throttled', + 'ignore_unavailable', + 'include_named_queries_score', + 'max_concurrent_searches', + 'max_concurrent_shard_requests', + 'pre_filter_shard_size', + 'rest_total_hits_as_int', + 'routing', + 'search_type', + 'typed_keys' + ] + } +} /** * Run multiple searches. The format of the request is similar to the bulk API format and makes use of the newline delimited JSON (NDJSON) format. The structure is as follows: ``` header\n body\n header\n body\n ``` This structure is specifically optimized to reduce parsing if a specific search ends up redirected to another node. IMPORTANT: The final line of data must end with a newline character `\n`. Each newline character may be preceded by a carriage return `\r`. When sending requests to this endpoint the `Content-Type` header should be set to `application/x-ndjson`. @@ -45,8 +76,12 @@ export default async function MsearchApi<TDocument = unknown, TAggregations = Re export default async function MsearchApi<TDocument = unknown, TAggregations = Record<T.AggregateName, T.AggregationsAggregate>> (this: That, params: T.MsearchRequest, options?: TransportRequestOptionsWithMeta): Promise<TransportResult<T.MsearchResponse<TDocument, TAggregations>, unknown>> export default async function MsearchApi<TDocument = unknown, TAggregations = Record<T.AggregateName, T.AggregationsAggregate>> (this: That, params: T.MsearchRequest, options?: TransportRequestOptions): Promise<T.MsearchResponse<TDocument, TAggregations>> export default async function MsearchApi<TDocument = unknown, TAggregations = Record<T.AggregateName, T.AggregationsAggregate>> (this: That, params: T.MsearchRequest, options?: TransportRequestOptions): Promise<any> { - const acceptedPath: string[] = ['index'] - const acceptedBody: string[] = ['searches'] + const { + path: acceptedPath, + body: acceptedBody, + query: acceptedQuery + } = acceptedParams.msearch + const userQuery = params?.querystring const querystring: Record<string, any> = userQuery != null ? { ...userQuery } : {} @@ -58,8 +93,14 @@ export default async function MsearchApi<TDocument = unknown, TAggregations = Re } else if (acceptedPath.includes(key)) { continue } else if (key !== 'body' && key !== 'querystring') { - // @ts-expect-error - querystring[key] = params[key] + if (acceptedQuery.includes(key) || commonQueryParams.includes(key)) { + // @ts-expect-error + querystring[key] = params[key] + } else { + body = body ?? {} + // @ts-expect-error + body[key] = params[key] + } } } diff --git a/src/api/api/msearch_template.ts b/src/api/api/msearch_template.ts index 019b9d1b8..20cee9851 100644 --- a/src/api/api/msearch_template.ts +++ b/src/api/api/msearch_template.ts @@ -35,7 +35,30 @@ import { TransportResult } from '@elastic/transport' import * as T from '../types' -interface That { transport: Transport } + +interface That { + transport: Transport +} + +const commonQueryParams = ['error_trace', 'filter_path', 'human', 'pretty'] + +const acceptedParams: Record<string, { path: string[], body: string[], query: string[] }> = { + msearch_template: { + path: [ + 'index' + ], + body: [ + 'search_templates' + ], + query: [ + 'ccs_minimize_roundtrips', + 'max_concurrent_searches', + 'search_type', + 'rest_total_hits_as_int', + 'typed_keys' + ] + } +} /** * Run multiple templated searches. Run multiple templated searches with a single request. If you are providing a text file or text input to `curl`, use the `--data-binary` flag instead of `-d` to preserve newlines. For example: ``` $ cat requests { "index": "my-index" } { "id": "my-search-template", "params": { "query_string": "hello world", "from": 0, "size": 10 }} { "index": "my-other-index" } { "id": "my-other-search-template", "params": { "query_type": "match_all" }} $ curl -H "Content-Type: application/x-ndjson" -XGET localhost:9200/_msearch/template --data-binary "@requests"; echo ``` @@ -45,8 +68,12 @@ export default async function MsearchTemplateApi<TDocument = unknown, TAggregati export default async function MsearchTemplateApi<TDocument = unknown, TAggregations = Record<T.AggregateName, T.AggregationsAggregate>> (this: That, params: T.MsearchTemplateRequest, options?: TransportRequestOptionsWithMeta): Promise<TransportResult<T.MsearchTemplateResponse<TDocument, TAggregations>, unknown>> export default async function MsearchTemplateApi<TDocument = unknown, TAggregations = Record<T.AggregateName, T.AggregationsAggregate>> (this: That, params: T.MsearchTemplateRequest, options?: TransportRequestOptions): Promise<T.MsearchTemplateResponse<TDocument, TAggregations>> export default async function MsearchTemplateApi<TDocument = unknown, TAggregations = Record<T.AggregateName, T.AggregationsAggregate>> (this: That, params: T.MsearchTemplateRequest, options?: TransportRequestOptions): Promise<any> { - const acceptedPath: string[] = ['index'] - const acceptedBody: string[] = ['search_templates'] + const { + path: acceptedPath, + body: acceptedBody, + query: acceptedQuery + } = acceptedParams.msearch_template + const userQuery = params?.querystring const querystring: Record<string, any> = userQuery != null ? { ...userQuery } : {} @@ -58,8 +85,14 @@ export default async function MsearchTemplateApi<TDocument = unknown, TAggregati } else if (acceptedPath.includes(key)) { continue } else if (key !== 'body' && key !== 'querystring') { - // @ts-expect-error - querystring[key] = params[key] + if (acceptedQuery.includes(key) || commonQueryParams.includes(key)) { + // @ts-expect-error + querystring[key] = params[key] + } else { + body = body ?? {} + // @ts-expect-error + body[key] = params[key] + } } } diff --git a/src/api/api/mtermvectors.ts b/src/api/api/mtermvectors.ts index bd4faccbb..7f60ec523 100644 --- a/src/api/api/mtermvectors.ts +++ b/src/api/api/mtermvectors.ts @@ -35,7 +35,38 @@ import { TransportResult } from '@elastic/transport' import * as T from '../types' -interface That { transport: Transport } + +interface That { + transport: Transport +} + +const commonQueryParams = ['error_trace', 'filter_path', 'human', 'pretty'] + +const acceptedParams: Record<string, { path: string[], body: string[], query: string[] }> = { + mtermvectors: { + path: [ + 'index' + ], + body: [ + 'docs', + 'ids' + ], + query: [ + 'ids', + 'fields', + 'field_statistics', + 'offsets', + 'payloads', + 'positions', + 'preference', + 'realtime', + 'routing', + 'term_statistics', + 'version', + 'version_type' + ] + } +} /** * Get multiple term vectors. Get multiple term vectors with a single request. You can specify existing documents by index and ID or provide artificial documents in the body of the request. You can specify the index in the request body or request URI. The response contains a `docs` array with all the fetched termvectors. Each element has the structure provided by the termvectors API. **Artificial documents** You can also use `mtermvectors` to generate term vectors for artificial documents provided in the body of the request. The mapping used is determined by the specified `_index`. @@ -45,8 +76,12 @@ export default async function MtermvectorsApi (this: That, params?: T.Mtermvecto export default async function MtermvectorsApi (this: That, params?: T.MtermvectorsRequest, options?: TransportRequestOptionsWithMeta): Promise<TransportResult<T.MtermvectorsResponse, unknown>> export default async function MtermvectorsApi (this: That, params?: T.MtermvectorsRequest, options?: TransportRequestOptions): Promise<T.MtermvectorsResponse> export default async function MtermvectorsApi (this: That, params?: T.MtermvectorsRequest, options?: TransportRequestOptions): Promise<any> { - const acceptedPath: string[] = ['index'] - const acceptedBody: string[] = ['docs', 'ids'] + const { + path: acceptedPath, + body: acceptedBody, + query: acceptedQuery + } = acceptedParams.mtermvectors + const userQuery = params?.querystring const querystring: Record<string, any> = userQuery != null ? { ...userQuery } : {} @@ -69,8 +104,14 @@ export default async function MtermvectorsApi (this: That, params?: T.Mtermvecto } else if (acceptedPath.includes(key)) { continue } else if (key !== 'body' && key !== 'querystring') { - // @ts-expect-error - querystring[key] = params[key] + if (acceptedQuery.includes(key) || commonQueryParams.includes(key)) { + // @ts-expect-error + querystring[key] = params[key] + } else { + body = body ?? {} + // @ts-expect-error + body[key] = params[key] + } } } diff --git a/src/api/api/nodes.ts b/src/api/api/nodes.ts index 1ce489ae0..8980be517 100644 --- a/src/api/api/nodes.ts +++ b/src/api/api/nodes.ts @@ -35,12 +35,102 @@ import { TransportResult } from '@elastic/transport' import * as T from '../types' -interface That { transport: Transport } + +interface That { + transport: Transport + acceptedParams: Record<string, { path: string[], body: string[], query: string[] }> +} + +const commonQueryParams = ['error_trace', 'filter_path', 'human', 'pretty'] export default class Nodes { transport: Transport + acceptedParams: Record<string, { path: string[], body: string[], query: string[] }> constructor (transport: Transport) { this.transport = transport + this.acceptedParams = { + 'nodes.clear_repositories_metering_archive': { + path: [ + 'node_id', + 'max_archive_version' + ], + body: [], + query: [] + }, + 'nodes.get_repositories_metering_info': { + path: [ + 'node_id' + ], + body: [], + query: [] + }, + 'nodes.hot_threads': { + path: [ + 'node_id' + ], + body: [], + query: [ + 'ignore_idle_threads', + 'interval', + 'snapshots', + 'threads', + 'timeout', + 'type', + 'sort' + ] + }, + 'nodes.info': { + path: [ + 'node_id', + 'metric' + ], + body: [], + query: [ + 'flat_settings', + 'timeout' + ] + }, + 'nodes.reload_secure_settings': { + path: [ + 'node_id' + ], + body: [ + 'secure_settings_password' + ], + query: [ + 'timeout' + ] + }, + 'nodes.stats': { + path: [ + 'node_id', + 'metric', + 'index_metric' + ], + body: [], + query: [ + 'completion_fields', + 'fielddata_fields', + 'fields', + 'groups', + 'include_segment_file_sizes', + 'level', + 'timeout', + 'types', + 'include_unloaded_segments' + ] + }, + 'nodes.usage': { + path: [ + 'node_id', + 'metric' + ], + body: [], + query: [ + 'timeout' + ] + } + } } /** @@ -51,7 +141,10 @@ export default class Nodes { async clearRepositoriesMeteringArchive (this: That, params: T.NodesClearRepositoriesMeteringArchiveRequest, options?: TransportRequestOptionsWithMeta): Promise<TransportResult<T.NodesClearRepositoriesMeteringArchiveResponse, unknown>> async clearRepositoriesMeteringArchive (this: That, params: T.NodesClearRepositoriesMeteringArchiveRequest, options?: TransportRequestOptions): Promise<T.NodesClearRepositoriesMeteringArchiveResponse> async clearRepositoriesMeteringArchive (this: That, params: T.NodesClearRepositoriesMeteringArchiveRequest, options?: TransportRequestOptions): Promise<any> { - const acceptedPath: string[] = ['node_id', 'max_archive_version'] + const { + path: acceptedPath + } = this.acceptedParams['nodes.clear_repositories_metering_archive'] + const userQuery = params?.querystring const querystring: Record<string, any> = userQuery != null ? { ...userQuery } : {} @@ -94,7 +187,10 @@ export default class Nodes { async getRepositoriesMeteringInfo (this: That, params: T.NodesGetRepositoriesMeteringInfoRequest, options?: TransportRequestOptionsWithMeta): Promise<TransportResult<T.NodesGetRepositoriesMeteringInfoResponse, unknown>> async getRepositoriesMeteringInfo (this: That, params: T.NodesGetRepositoriesMeteringInfoRequest, options?: TransportRequestOptions): Promise<T.NodesGetRepositoriesMeteringInfoResponse> async getRepositoriesMeteringInfo (this: That, params: T.NodesGetRepositoriesMeteringInfoRequest, options?: TransportRequestOptions): Promise<any> { - const acceptedPath: string[] = ['node_id'] + const { + path: acceptedPath + } = this.acceptedParams['nodes.get_repositories_metering_info'] + const userQuery = params?.querystring const querystring: Record<string, any> = userQuery != null ? { ...userQuery } : {} @@ -136,7 +232,10 @@ export default class Nodes { async hotThreads (this: That, params?: T.NodesHotThreadsRequest, options?: TransportRequestOptionsWithMeta): Promise<TransportResult<T.NodesHotThreadsResponse, unknown>> async hotThreads (this: That, params?: T.NodesHotThreadsRequest, options?: TransportRequestOptions): Promise<T.NodesHotThreadsResponse> async hotThreads (this: That, params?: T.NodesHotThreadsRequest, options?: TransportRequestOptions): Promise<any> { - const acceptedPath: string[] = ['node_id'] + const { + path: acceptedPath + } = this.acceptedParams['nodes.hot_threads'] + const userQuery = params?.querystring const querystring: Record<string, any> = userQuery != null ? { ...userQuery } : {} @@ -186,7 +285,10 @@ export default class Nodes { async info (this: That, params?: T.NodesInfoRequest, options?: TransportRequestOptionsWithMeta): Promise<TransportResult<T.NodesInfoResponse, unknown>> async info (this: That, params?: T.NodesInfoRequest, options?: TransportRequestOptions): Promise<T.NodesInfoResponse> async info (this: That, params?: T.NodesInfoRequest, options?: TransportRequestOptions): Promise<any> { - const acceptedPath: string[] = ['node_id', 'metric'] + const { + path: acceptedPath + } = this.acceptedParams['nodes.info'] + const userQuery = params?.querystring const querystring: Record<string, any> = userQuery != null ? { ...userQuery } : {} @@ -243,8 +345,12 @@ export default class Nodes { async reloadSecureSettings (this: That, params?: T.NodesReloadSecureSettingsRequest, options?: TransportRequestOptionsWithMeta): Promise<TransportResult<T.NodesReloadSecureSettingsResponse, unknown>> async reloadSecureSettings (this: That, params?: T.NodesReloadSecureSettingsRequest, options?: TransportRequestOptions): Promise<T.NodesReloadSecureSettingsResponse> async reloadSecureSettings (this: That, params?: T.NodesReloadSecureSettingsRequest, options?: TransportRequestOptions): Promise<any> { - const acceptedPath: string[] = ['node_id'] - const acceptedBody: string[] = ['secure_settings_password'] + const { + path: acceptedPath, + body: acceptedBody, + query: acceptedQuery + } = this.acceptedParams['nodes.reload_secure_settings'] + const userQuery = params?.querystring const querystring: Record<string, any> = userQuery != null ? { ...userQuery } : {} @@ -267,8 +373,14 @@ export default class Nodes { } else if (acceptedPath.includes(key)) { continue } else if (key !== 'body' && key !== 'querystring') { - // @ts-expect-error - querystring[key] = params[key] + if (acceptedQuery.includes(key) || commonQueryParams.includes(key)) { + // @ts-expect-error + querystring[key] = params[key] + } else { + body = body ?? {} + // @ts-expect-error + body[key] = params[key] + } } } @@ -298,7 +410,10 @@ export default class Nodes { async stats (this: That, params?: T.NodesStatsRequest, options?: TransportRequestOptionsWithMeta): Promise<TransportResult<T.NodesStatsResponse, unknown>> async stats (this: That, params?: T.NodesStatsRequest, options?: TransportRequestOptions): Promise<T.NodesStatsResponse> async stats (this: That, params?: T.NodesStatsRequest, options?: TransportRequestOptions): Promise<any> { - const acceptedPath: string[] = ['node_id', 'metric', 'index_metric'] + const { + path: acceptedPath + } = this.acceptedParams['nodes.stats'] + const userQuery = params?.querystring const querystring: Record<string, any> = userQuery != null ? { ...userQuery } : {} @@ -362,7 +477,10 @@ export default class Nodes { async usage (this: That, params?: T.NodesUsageRequest, options?: TransportRequestOptionsWithMeta): Promise<TransportResult<T.NodesUsageResponse, unknown>> async usage (this: That, params?: T.NodesUsageRequest, options?: TransportRequestOptions): Promise<T.NodesUsageResponse> async usage (this: That, params?: T.NodesUsageRequest, options?: TransportRequestOptions): Promise<any> { - const acceptedPath: string[] = ['node_id', 'metric'] + const { + path: acceptedPath + } = this.acceptedParams['nodes.usage'] + const userQuery = params?.querystring const querystring: Record<string, any> = userQuery != null ? { ...userQuery } : {} diff --git a/src/api/api/open_point_in_time.ts b/src/api/api/open_point_in_time.ts index 4cd2a733e..1ff65e50e 100644 --- a/src/api/api/open_point_in_time.ts +++ b/src/api/api/open_point_in_time.ts @@ -35,7 +35,31 @@ import { TransportResult } from '@elastic/transport' import * as T from '../types' -interface That { transport: Transport } + +interface That { + transport: Transport +} + +const commonQueryParams = ['error_trace', 'filter_path', 'human', 'pretty'] + +const acceptedParams: Record<string, { path: string[], body: string[], query: string[] }> = { + open_point_in_time: { + path: [ + 'index' + ], + body: [ + 'index_filter' + ], + query: [ + 'keep_alive', + 'ignore_unavailable', + 'preference', + 'routing', + 'expand_wildcards', + 'allow_partial_search_results' + ] + } +} /** * Open a point in time. A search request by default runs against the most recent visible data of the target indices, which is called point in time. Elasticsearch pit (point in time) is a lightweight view into the state of the data as it existed when initiated. In some cases, it’s preferred to perform multiple search requests using the same point in time. For example, if refreshes happen between `search_after` requests, then the results of those requests might not be consistent as changes happening between searches are only visible to the more recent point in time. A point in time must be opened explicitly before being used in search requests. A subsequent search request with the `pit` parameter must not specify `index`, `routing`, or `preference` values as these parameters are copied from the point in time. Just like regular searches, you can use `from` and `size` to page through point in time search results, up to the first 10,000 hits. If you want to retrieve more hits, use PIT with `search_after`. IMPORTANT: The open point in time request and each subsequent search request can return different identifiers; always use the most recently received ID for the next search request. When a PIT that contains shard failures is used in a search request, the missing are always reported in the search response as a `NoShardAvailableActionException` exception. To get rid of these exceptions, a new PIT needs to be created so that shards missing from the previous PIT can be handled, assuming they become available in the meantime. **Keeping point in time alive** The `keep_alive` parameter, which is passed to a open point in time request and search request, extends the time to live of the corresponding point in time. The value does not need to be long enough to process all data — it just needs to be long enough for the next request. Normally, the background merge process optimizes the index by merging together smaller segments to create new, bigger segments. Once the smaller segments are no longer needed they are deleted. However, open point-in-times prevent the old segments from being deleted since they are still in use. TIP: Keeping older segments alive means that more disk space and file handles are needed. Ensure that you have configured your nodes to have ample free file handles. Additionally, if a segment contains deleted or updated documents then the point in time must keep track of whether each document in the segment was live at the time of the initial search request. Ensure that your nodes have sufficient heap space if you have many open point-in-times on an index that is subject to ongoing deletes or updates. Note that a point-in-time doesn't prevent its associated indices from being deleted. You can check how many point-in-times (that is, search contexts) are open with the nodes stats API. @@ -45,8 +69,12 @@ export default async function OpenPointInTimeApi (this: That, params: T.OpenPoin export default async function OpenPointInTimeApi (this: That, params: T.OpenPointInTimeRequest, options?: TransportRequestOptionsWithMeta): Promise<TransportResult<T.OpenPointInTimeResponse, unknown>> export default async function OpenPointInTimeApi (this: That, params: T.OpenPointInTimeRequest, options?: TransportRequestOptions): Promise<T.OpenPointInTimeResponse> export default async function OpenPointInTimeApi (this: That, params: T.OpenPointInTimeRequest, options?: TransportRequestOptions): Promise<any> { - const acceptedPath: string[] = ['index'] - const acceptedBody: string[] = ['index_filter'] + const { + path: acceptedPath, + body: acceptedBody, + query: acceptedQuery + } = acceptedParams.open_point_in_time + const userQuery = params?.querystring const querystring: Record<string, any> = userQuery != null ? { ...userQuery } : {} @@ -68,8 +96,14 @@ export default async function OpenPointInTimeApi (this: That, params: T.OpenPoin } else if (acceptedPath.includes(key)) { continue } else if (key !== 'body' && key !== 'querystring') { - // @ts-expect-error - querystring[key] = params[key] + if (acceptedQuery.includes(key) || commonQueryParams.includes(key)) { + // @ts-expect-error + querystring[key] = params[key] + } else { + body = body ?? {} + // @ts-expect-error + body[key] = params[key] + } } } diff --git a/src/api/api/ping.ts b/src/api/api/ping.ts index 908709afd..81c05df92 100644 --- a/src/api/api/ping.ts +++ b/src/api/api/ping.ts @@ -35,7 +35,18 @@ import { TransportResult } from '@elastic/transport' import * as T from '../types' -interface That { transport: Transport } + +interface That { + transport: Transport +} + +const acceptedParams: Record<string, { path: string[], body: string[], query: string[] }> = { + ping: { + path: [], + body: [], + query: [] + } +} /** * Ping the cluster. Get information about whether the cluster is running. @@ -45,7 +56,10 @@ export default async function PingApi (this: That, params?: T.PingRequest, optio export default async function PingApi (this: That, params?: T.PingRequest, options?: TransportRequestOptionsWithMeta): Promise<TransportResult<T.PingResponse, unknown>> export default async function PingApi (this: That, params?: T.PingRequest, options?: TransportRequestOptions): Promise<T.PingResponse> export default async function PingApi (this: That, params?: T.PingRequest, options?: TransportRequestOptions): Promise<any> { - const acceptedPath: string[] = [] + const { + path: acceptedPath + } = acceptedParams.ping + const userQuery = params?.querystring const querystring: Record<string, any> = userQuery != null ? { ...userQuery } : {} diff --git a/src/api/api/profiling.ts b/src/api/api/profiling.ts index 75f2d46cc..631c1df17 100644 --- a/src/api/api/profiling.ts +++ b/src/api/api/profiling.ts @@ -35,12 +35,39 @@ import { TransportResult } from '@elastic/transport' import * as T from '../types' -interface That { transport: Transport } + +interface That { + transport: Transport + acceptedParams: Record<string, { path: string[], body: string[], query: string[] }> +} export default class Profiling { transport: Transport + acceptedParams: Record<string, { path: string[], body: string[], query: string[] }> constructor (transport: Transport) { this.transport = transport + this.acceptedParams = { + 'profiling.flamegraph': { + path: [], + body: [], + query: [] + }, + 'profiling.stacktraces': { + path: [], + body: [], + query: [] + }, + 'profiling.status': { + path: [], + body: [], + query: [] + }, + 'profiling.topn_functions': { + path: [], + body: [], + query: [] + } + } } /** @@ -51,7 +78,10 @@ export default class Profiling { async flamegraph (this: That, params?: T.TODO, options?: TransportRequestOptionsWithMeta): Promise<TransportResult<T.TODO, unknown>> async flamegraph (this: That, params?: T.TODO, options?: TransportRequestOptions): Promise<T.TODO> async flamegraph (this: That, params?: T.TODO, options?: TransportRequestOptions): Promise<any> { - const acceptedPath: string[] = [] + const { + path: acceptedPath + } = this.acceptedParams['profiling.flamegraph'] + const userQuery = params?.querystring const querystring: Record<string, any> = userQuery != null ? { ...userQuery } : {} @@ -90,7 +120,10 @@ export default class Profiling { async stacktraces (this: That, params?: T.TODO, options?: TransportRequestOptionsWithMeta): Promise<TransportResult<T.TODO, unknown>> async stacktraces (this: That, params?: T.TODO, options?: TransportRequestOptions): Promise<T.TODO> async stacktraces (this: That, params?: T.TODO, options?: TransportRequestOptions): Promise<any> { - const acceptedPath: string[] = [] + const { + path: acceptedPath + } = this.acceptedParams['profiling.stacktraces'] + const userQuery = params?.querystring const querystring: Record<string, any> = userQuery != null ? { ...userQuery } : {} @@ -129,7 +162,10 @@ export default class Profiling { async status (this: That, params?: T.TODO, options?: TransportRequestOptionsWithMeta): Promise<TransportResult<T.TODO, unknown>> async status (this: That, params?: T.TODO, options?: TransportRequestOptions): Promise<T.TODO> async status (this: That, params?: T.TODO, options?: TransportRequestOptions): Promise<any> { - const acceptedPath: string[] = [] + const { + path: acceptedPath + } = this.acceptedParams['profiling.status'] + const userQuery = params?.querystring const querystring: Record<string, any> = userQuery != null ? { ...userQuery } : {} @@ -168,7 +204,10 @@ export default class Profiling { async topnFunctions (this: That, params?: T.TODO, options?: TransportRequestOptionsWithMeta): Promise<TransportResult<T.TODO, unknown>> async topnFunctions (this: That, params?: T.TODO, options?: TransportRequestOptions): Promise<T.TODO> async topnFunctions (this: That, params?: T.TODO, options?: TransportRequestOptions): Promise<any> { - const acceptedPath: string[] = [] + const { + path: acceptedPath + } = this.acceptedParams['profiling.topn_functions'] + const userQuery = params?.querystring const querystring: Record<string, any> = userQuery != null ? { ...userQuery } : {} diff --git a/src/api/api/put_script.ts b/src/api/api/put_script.ts index d3350ca5b..c412b1faf 100644 --- a/src/api/api/put_script.ts +++ b/src/api/api/put_script.ts @@ -35,7 +35,29 @@ import { TransportResult } from '@elastic/transport' import * as T from '../types' -interface That { transport: Transport } + +interface That { + transport: Transport +} + +const commonQueryParams = ['error_trace', 'filter_path', 'human', 'pretty'] + +const acceptedParams: Record<string, { path: string[], body: string[], query: string[] }> = { + put_script: { + path: [ + 'id', + 'context' + ], + body: [ + 'script' + ], + query: [ + 'context', + 'master_timeout', + 'timeout' + ] + } +} /** * Create or update a script or search template. Creates or updates a stored script or search template. @@ -45,8 +67,12 @@ export default async function PutScriptApi (this: That, params: T.PutScriptReque export default async function PutScriptApi (this: That, params: T.PutScriptRequest, options?: TransportRequestOptionsWithMeta): Promise<TransportResult<T.PutScriptResponse, unknown>> export default async function PutScriptApi (this: That, params: T.PutScriptRequest, options?: TransportRequestOptions): Promise<T.PutScriptResponse> export default async function PutScriptApi (this: That, params: T.PutScriptRequest, options?: TransportRequestOptions): Promise<any> { - const acceptedPath: string[] = ['id', 'context'] - const acceptedBody: string[] = ['script'] + const { + path: acceptedPath, + body: acceptedBody, + query: acceptedQuery + } = acceptedParams.put_script + const userQuery = params?.querystring const querystring: Record<string, any> = userQuery != null ? { ...userQuery } : {} @@ -68,8 +94,14 @@ export default async function PutScriptApi (this: That, params: T.PutScriptReque } else if (acceptedPath.includes(key)) { continue } else if (key !== 'body' && key !== 'querystring') { - // @ts-expect-error - querystring[key] = params[key] + if (acceptedQuery.includes(key) || commonQueryParams.includes(key)) { + // @ts-expect-error + querystring[key] = params[key] + } else { + body = body ?? {} + // @ts-expect-error + body[key] = params[key] + } } } diff --git a/src/api/api/query_rules.ts b/src/api/api/query_rules.ts index bb7a964ee..3fa80dccd 100644 --- a/src/api/api/query_rules.ts +++ b/src/api/api/query_rules.ts @@ -35,12 +35,90 @@ import { TransportResult } from '@elastic/transport' import * as T from '../types' -interface That { transport: Transport } + +interface That { + transport: Transport + acceptedParams: Record<string, { path: string[], body: string[], query: string[] }> +} + +const commonQueryParams = ['error_trace', 'filter_path', 'human', 'pretty'] export default class QueryRules { transport: Transport + acceptedParams: Record<string, { path: string[], body: string[], query: string[] }> constructor (transport: Transport) { this.transport = transport + this.acceptedParams = { + 'query_rules.delete_rule': { + path: [ + 'ruleset_id', + 'rule_id' + ], + body: [], + query: [] + }, + 'query_rules.delete_ruleset': { + path: [ + 'ruleset_id' + ], + body: [], + query: [] + }, + 'query_rules.get_rule': { + path: [ + 'ruleset_id', + 'rule_id' + ], + body: [], + query: [] + }, + 'query_rules.get_ruleset': { + path: [ + 'ruleset_id' + ], + body: [], + query: [] + }, + 'query_rules.list_rulesets': { + path: [], + body: [], + query: [ + 'from', + 'size' + ] + }, + 'query_rules.put_rule': { + path: [ + 'ruleset_id', + 'rule_id' + ], + body: [ + 'type', + 'criteria', + 'actions', + 'priority' + ], + query: [] + }, + 'query_rules.put_ruleset': { + path: [ + 'ruleset_id' + ], + body: [ + 'rules' + ], + query: [] + }, + 'query_rules.test': { + path: [ + 'ruleset_id' + ], + body: [ + 'match_criteria' + ], + query: [] + } + } } /** @@ -51,7 +129,10 @@ export default class QueryRules { async deleteRule (this: That, params: T.QueryRulesDeleteRuleRequest, options?: TransportRequestOptionsWithMeta): Promise<TransportResult<T.QueryRulesDeleteRuleResponse, unknown>> async deleteRule (this: That, params: T.QueryRulesDeleteRuleRequest, options?: TransportRequestOptions): Promise<T.QueryRulesDeleteRuleResponse> async deleteRule (this: That, params: T.QueryRulesDeleteRuleRequest, options?: TransportRequestOptions): Promise<any> { - const acceptedPath: string[] = ['ruleset_id', 'rule_id'] + const { + path: acceptedPath + } = this.acceptedParams['query_rules.delete_rule'] + const userQuery = params?.querystring const querystring: Record<string, any> = userQuery != null ? { ...userQuery } : {} @@ -94,7 +175,10 @@ export default class QueryRules { async deleteRuleset (this: That, params: T.QueryRulesDeleteRulesetRequest, options?: TransportRequestOptionsWithMeta): Promise<TransportResult<T.QueryRulesDeleteRulesetResponse, unknown>> async deleteRuleset (this: That, params: T.QueryRulesDeleteRulesetRequest, options?: TransportRequestOptions): Promise<T.QueryRulesDeleteRulesetResponse> async deleteRuleset (this: That, params: T.QueryRulesDeleteRulesetRequest, options?: TransportRequestOptions): Promise<any> { - const acceptedPath: string[] = ['ruleset_id'] + const { + path: acceptedPath + } = this.acceptedParams['query_rules.delete_ruleset'] + const userQuery = params?.querystring const querystring: Record<string, any> = userQuery != null ? { ...userQuery } : {} @@ -136,7 +220,10 @@ export default class QueryRules { async getRule (this: That, params: T.QueryRulesGetRuleRequest, options?: TransportRequestOptionsWithMeta): Promise<TransportResult<T.QueryRulesGetRuleResponse, unknown>> async getRule (this: That, params: T.QueryRulesGetRuleRequest, options?: TransportRequestOptions): Promise<T.QueryRulesGetRuleResponse> async getRule (this: That, params: T.QueryRulesGetRuleRequest, options?: TransportRequestOptions): Promise<any> { - const acceptedPath: string[] = ['ruleset_id', 'rule_id'] + const { + path: acceptedPath + } = this.acceptedParams['query_rules.get_rule'] + const userQuery = params?.querystring const querystring: Record<string, any> = userQuery != null ? { ...userQuery } : {} @@ -179,7 +266,10 @@ export default class QueryRules { async getRuleset (this: That, params: T.QueryRulesGetRulesetRequest, options?: TransportRequestOptionsWithMeta): Promise<TransportResult<T.QueryRulesGetRulesetResponse, unknown>> async getRuleset (this: That, params: T.QueryRulesGetRulesetRequest, options?: TransportRequestOptions): Promise<T.QueryRulesGetRulesetResponse> async getRuleset (this: That, params: T.QueryRulesGetRulesetRequest, options?: TransportRequestOptions): Promise<any> { - const acceptedPath: string[] = ['ruleset_id'] + const { + path: acceptedPath + } = this.acceptedParams['query_rules.get_ruleset'] + const userQuery = params?.querystring const querystring: Record<string, any> = userQuery != null ? { ...userQuery } : {} @@ -221,7 +311,10 @@ export default class QueryRules { async listRulesets (this: That, params?: T.QueryRulesListRulesetsRequest, options?: TransportRequestOptionsWithMeta): Promise<TransportResult<T.QueryRulesListRulesetsResponse, unknown>> async listRulesets (this: That, params?: T.QueryRulesListRulesetsRequest, options?: TransportRequestOptions): Promise<T.QueryRulesListRulesetsResponse> async listRulesets (this: That, params?: T.QueryRulesListRulesetsRequest, options?: TransportRequestOptions): Promise<any> { - const acceptedPath: string[] = [] + const { + path: acceptedPath + } = this.acceptedParams['query_rules.list_rulesets'] + const userQuery = params?.querystring const querystring: Record<string, any> = userQuery != null ? { ...userQuery } : {} @@ -261,8 +354,12 @@ export default class QueryRules { async putRule (this: That, params: T.QueryRulesPutRuleRequest, options?: TransportRequestOptionsWithMeta): Promise<TransportResult<T.QueryRulesPutRuleResponse, unknown>> async putRule (this: That, params: T.QueryRulesPutRuleRequest, options?: TransportRequestOptions): Promise<T.QueryRulesPutRuleResponse> async putRule (this: That, params: T.QueryRulesPutRuleRequest, options?: TransportRequestOptions): Promise<any> { - const acceptedPath: string[] = ['ruleset_id', 'rule_id'] - const acceptedBody: string[] = ['type', 'criteria', 'actions', 'priority'] + const { + path: acceptedPath, + body: acceptedBody, + query: acceptedQuery + } = this.acceptedParams['query_rules.put_rule'] + const userQuery = params?.querystring const querystring: Record<string, any> = userQuery != null ? { ...userQuery } : {} @@ -284,8 +381,14 @@ export default class QueryRules { } else if (acceptedPath.includes(key)) { continue } else if (key !== 'body' && key !== 'querystring') { - // @ts-expect-error - querystring[key] = params[key] + if (acceptedQuery.includes(key) || commonQueryParams.includes(key)) { + // @ts-expect-error + querystring[key] = params[key] + } else { + body = body ?? {} + // @ts-expect-error + body[key] = params[key] + } } } @@ -309,8 +412,12 @@ export default class QueryRules { async putRuleset (this: That, params: T.QueryRulesPutRulesetRequest, options?: TransportRequestOptionsWithMeta): Promise<TransportResult<T.QueryRulesPutRulesetResponse, unknown>> async putRuleset (this: That, params: T.QueryRulesPutRulesetRequest, options?: TransportRequestOptions): Promise<T.QueryRulesPutRulesetResponse> async putRuleset (this: That, params: T.QueryRulesPutRulesetRequest, options?: TransportRequestOptions): Promise<any> { - const acceptedPath: string[] = ['ruleset_id'] - const acceptedBody: string[] = ['rules'] + const { + path: acceptedPath, + body: acceptedBody, + query: acceptedQuery + } = this.acceptedParams['query_rules.put_ruleset'] + const userQuery = params?.querystring const querystring: Record<string, any> = userQuery != null ? { ...userQuery } : {} @@ -332,8 +439,14 @@ export default class QueryRules { } else if (acceptedPath.includes(key)) { continue } else if (key !== 'body' && key !== 'querystring') { - // @ts-expect-error - querystring[key] = params[key] + if (acceptedQuery.includes(key) || commonQueryParams.includes(key)) { + // @ts-expect-error + querystring[key] = params[key] + } else { + body = body ?? {} + // @ts-expect-error + body[key] = params[key] + } } } @@ -356,8 +469,12 @@ export default class QueryRules { async test (this: That, params: T.QueryRulesTestRequest, options?: TransportRequestOptionsWithMeta): Promise<TransportResult<T.QueryRulesTestResponse, unknown>> async test (this: That, params: T.QueryRulesTestRequest, options?: TransportRequestOptions): Promise<T.QueryRulesTestResponse> async test (this: That, params: T.QueryRulesTestRequest, options?: TransportRequestOptions): Promise<any> { - const acceptedPath: string[] = ['ruleset_id'] - const acceptedBody: string[] = ['match_criteria'] + const { + path: acceptedPath, + body: acceptedBody, + query: acceptedQuery + } = this.acceptedParams['query_rules.test'] + const userQuery = params?.querystring const querystring: Record<string, any> = userQuery != null ? { ...userQuery } : {} @@ -379,8 +496,14 @@ export default class QueryRules { } else if (acceptedPath.includes(key)) { continue } else if (key !== 'body' && key !== 'querystring') { - // @ts-expect-error - querystring[key] = params[key] + if (acceptedQuery.includes(key) || commonQueryParams.includes(key)) { + // @ts-expect-error + querystring[key] = params[key] + } else { + body = body ?? {} + // @ts-expect-error + body[key] = params[key] + } } } diff --git a/src/api/api/rank_eval.ts b/src/api/api/rank_eval.ts index bd3af65e5..cd9207896 100644 --- a/src/api/api/rank_eval.ts +++ b/src/api/api/rank_eval.ts @@ -35,7 +35,30 @@ import { TransportResult } from '@elastic/transport' import * as T from '../types' -interface That { transport: Transport } + +interface That { + transport: Transport +} + +const commonQueryParams = ['error_trace', 'filter_path', 'human', 'pretty'] + +const acceptedParams: Record<string, { path: string[], body: string[], query: string[] }> = { + rank_eval: { + path: [ + 'index' + ], + body: [ + 'requests', + 'metric' + ], + query: [ + 'allow_no_indices', + 'expand_wildcards', + 'ignore_unavailable', + 'search_type' + ] + } +} /** * Evaluate ranked search results. Evaluate the quality of ranked search results over a set of typical search queries. @@ -45,8 +68,12 @@ export default async function RankEvalApi (this: That, params: T.RankEvalRequest export default async function RankEvalApi (this: That, params: T.RankEvalRequest, options?: TransportRequestOptionsWithMeta): Promise<TransportResult<T.RankEvalResponse, unknown>> export default async function RankEvalApi (this: That, params: T.RankEvalRequest, options?: TransportRequestOptions): Promise<T.RankEvalResponse> export default async function RankEvalApi (this: That, params: T.RankEvalRequest, options?: TransportRequestOptions): Promise<any> { - const acceptedPath: string[] = ['index'] - const acceptedBody: string[] = ['requests', 'metric'] + const { + path: acceptedPath, + body: acceptedBody, + query: acceptedQuery + } = acceptedParams.rank_eval + const userQuery = params?.querystring const querystring: Record<string, any> = userQuery != null ? { ...userQuery } : {} @@ -68,8 +95,14 @@ export default async function RankEvalApi (this: That, params: T.RankEvalRequest } else if (acceptedPath.includes(key)) { continue } else if (key !== 'body' && key !== 'querystring') { - // @ts-expect-error - querystring[key] = params[key] + if (acceptedQuery.includes(key) || commonQueryParams.includes(key)) { + // @ts-expect-error + querystring[key] = params[key] + } else { + body = body ?? {} + // @ts-expect-error + body[key] = params[key] + } } } diff --git a/src/api/api/reindex.ts b/src/api/api/reindex.ts index 5c83f147b..2fe9d235d 100644 --- a/src/api/api/reindex.ts +++ b/src/api/api/reindex.ts @@ -35,7 +35,36 @@ import { TransportResult } from '@elastic/transport' import * as T from '../types' -interface That { transport: Transport } + +interface That { + transport: Transport +} + +const commonQueryParams = ['error_trace', 'filter_path', 'human', 'pretty'] + +const acceptedParams: Record<string, { path: string[], body: string[], query: string[] }> = { + reindex: { + path: [], + body: [ + 'conflicts', + 'dest', + 'max_docs', + 'script', + 'size', + 'source' + ], + query: [ + 'refresh', + 'requests_per_second', + 'scroll', + 'slices', + 'timeout', + 'wait_for_active_shards', + 'wait_for_completion', + 'require_alias' + ] + } +} /** * Reindex documents. Copy documents from a source to a destination. You can copy all documents to the destination index or reindex a subset of the documents. The source can be any existing index, alias, or data stream. The destination must differ from the source. For example, you cannot reindex a data stream into itself. IMPORTANT: Reindex requires `_source` to be enabled for all documents in the source. The destination should be configured as wanted before calling the reindex API. Reindex does not copy the settings from the source or its associated template. Mappings, shard counts, and replicas, for example, must be configured ahead of time. If the Elasticsearch security features are enabled, you must have the following security privileges: * The `read` index privilege for the source data stream, index, or alias. * The `write` index privilege for the destination data stream, index, or index alias. * To automatically create a data stream or index with a reindex API request, you must have the `auto_configure`, `create_index`, or `manage` index privilege for the destination data stream, index, or alias. * If reindexing from a remote cluster, the `source.remote.user` must have the `monitor` cluster privilege and the `read` index privilege for the source data stream, index, or alias. If reindexing from a remote cluster, you must explicitly allow the remote host in the `reindex.remote.whitelist` setting. Automatic data stream creation requires a matching index template with data stream enabled. The `dest` element can be configured like the index API to control optimistic concurrency control. Omitting `version_type` or setting it to `internal` causes Elasticsearch to blindly dump documents into the destination, overwriting any that happen to have the same ID. Setting `version_type` to `external` causes Elasticsearch to preserve the `version` from the source, create any documents that are missing, and update any documents that have an older version in the destination than they do in the source. Setting `op_type` to `create` causes the reindex API to create only missing documents in the destination. All existing documents will cause a version conflict. IMPORTANT: Because data streams are append-only, any reindex request to a destination data stream must have an `op_type` of `create`. A reindex can only add new documents to a destination data stream. It cannot update existing documents in a destination data stream. By default, version conflicts abort the reindex process. To continue reindexing if there are conflicts, set the `conflicts` request body property to `proceed`. In this case, the response includes a count of the version conflicts that were encountered. Note that the handling of other error types is unaffected by the `conflicts` property. Additionally, if you opt to count version conflicts, the operation could attempt to reindex more documents from the source than `max_docs` until it has successfully indexed `max_docs` documents into the target or it has gone through every document in the source query. NOTE: The reindex API makes no effort to handle ID collisions. The last document written will "win" but the order isn't usually predictable so it is not a good idea to rely on this behavior. Instead, make sure that IDs are unique by using a script. **Running reindex asynchronously** If the request contains `wait_for_completion=false`, Elasticsearch performs some preflight checks, launches the request, and returns a task you can use to cancel or get the status of the task. Elasticsearch creates a record of this task as a document at `_tasks/<task_id>`. **Reindex from multiple sources** If you have many sources to reindex it is generally better to reindex them one at a time rather than using a glob pattern to pick up multiple sources. That way you can resume the process if there are any errors by removing the partially completed source and starting over. It also makes parallelizing the process fairly simple: split the list of sources to reindex and run each list in parallel. For example, you can use a bash script like this: ``` for index in i1 i2 i3 i4 i5; do curl -HContent-Type:application/json -XPOST localhost:9200/_reindex?pretty -d'{ "source": { "index": "'$index'" }, "dest": { "index": "'$index'-reindexed" } }' done ``` **Throttling** Set `requests_per_second` to any positive decimal number (`1.4`, `6`, `1000`, for example) to throttle the rate at which reindex issues batches of index operations. Requests are throttled by padding each batch with a wait time. To turn off throttling, set `requests_per_second` to `-1`. The throttling is done by waiting between batches so that the scroll that reindex uses internally can be given a timeout that takes into account the padding. The padding time is the difference between the batch size divided by the `requests_per_second` and the time spent writing. By default the batch size is `1000`, so if `requests_per_second` is set to `500`: ``` target_time = 1000 / 500 per second = 2 seconds wait_time = target_time - write_time = 2 seconds - .5 seconds = 1.5 seconds ``` Since the batch is issued as a single bulk request, large batch sizes cause Elasticsearch to create many requests and then wait for a while before starting the next set. This is "bursty" instead of "smooth". **Slicing** Reindex supports sliced scroll to parallelize the reindexing process. This parallelization can improve efficiency and provide a convenient way to break the request down into smaller parts. NOTE: Reindexing from remote clusters does not support manual or automatic slicing. You can slice a reindex request manually by providing a slice ID and total number of slices to each request. You can also let reindex automatically parallelize by using sliced scroll to slice on `_id`. The `slices` parameter specifies the number of slices to use. Adding `slices` to the reindex request just automates the manual process, creating sub-requests which means it has some quirks: * You can see these requests in the tasks API. These sub-requests are "child" tasks of the task for the request with slices. * Fetching the status of the task for the request with `slices` only contains the status of completed slices. * These sub-requests are individually addressable for things like cancellation and rethrottling. * Rethrottling the request with `slices` will rethrottle the unfinished sub-request proportionally. * Canceling the request with `slices` will cancel each sub-request. * Due to the nature of `slices`, each sub-request won't get a perfectly even portion of the documents. All documents will be addressed, but some slices may be larger than others. Expect larger slices to have a more even distribution. * Parameters like `requests_per_second` and `max_docs` on a request with `slices` are distributed proportionally to each sub-request. Combine that with the previous point about distribution being uneven and you should conclude that using `max_docs` with `slices` might not result in exactly `max_docs` documents being reindexed. * Each sub-request gets a slightly different snapshot of the source, though these are all taken at approximately the same time. If slicing automatically, setting `slices` to `auto` will choose a reasonable number for most indices. If slicing manually or otherwise tuning automatic slicing, use the following guidelines. Query performance is most efficient when the number of slices is equal to the number of shards in the index. If that number is large (for example, `500`), choose a lower number as too many slices will hurt performance. Setting slices higher than the number of shards generally does not improve efficiency and adds overhead. Indexing performance scales linearly across available resources with the number of slices. Whether query or indexing performance dominates the runtime depends on the documents being reindexed and cluster resources. **Modify documents during reindexing** Like `_update_by_query`, reindex operations support a script that modifies the document. Unlike `_update_by_query`, the script is allowed to modify the document's metadata. Just as in `_update_by_query`, you can set `ctx.op` to change the operation that is run on the destination. For example, set `ctx.op` to `noop` if your script decides that the document doesn’t have to be indexed in the destination. This "no operation" will be reported in the `noop` counter in the response body. Set `ctx.op` to `delete` if your script decides that the document must be deleted from the destination. The deletion will be reported in the `deleted` counter in the response body. Setting `ctx.op` to anything else will return an error, as will setting any other field in `ctx`. Think of the possibilities! Just be careful; you are able to change: * `_id` * `_index` * `_version` * `_routing` Setting `_version` to `null` or clearing it from the `ctx` map is just like not sending the version in an indexing request. It will cause the document to be overwritten in the destination regardless of the version on the target or the version type you use in the reindex API. **Reindex from remote** Reindex supports reindexing from a remote Elasticsearch cluster. The `host` parameter must contain a scheme, host, port, and optional path. The `username` and `password` parameters are optional and when they are present the reindex operation will connect to the remote Elasticsearch node using basic authentication. Be sure to use HTTPS when using basic authentication or the password will be sent in plain text. There are a range of settings available to configure the behavior of the HTTPS connection. When using Elastic Cloud, it is also possible to authenticate against the remote cluster through the use of a valid API key. Remote hosts must be explicitly allowed with the `reindex.remote.whitelist` setting. It can be set to a comma delimited list of allowed remote host and port combinations. Scheme is ignored; only the host and port are used. For example: ``` reindex.remote.whitelist: [otherhost:9200, another:9200, 127.0.10.*:9200, localhost:*"] ``` The list of allowed hosts must be configured on any nodes that will coordinate the reindex. This feature should work with remote clusters of any version of Elasticsearch. This should enable you to upgrade from any version of Elasticsearch to the current version by reindexing from a cluster of the old version. WARNING: Elasticsearch does not support forward compatibility across major versions. For example, you cannot reindex from a 7.x cluster into a 6.x cluster. To enable queries sent to older versions of Elasticsearch, the `query` parameter is sent directly to the remote host without validation or modification. NOTE: Reindexing from remote clusters does not support manual or automatic slicing. Reindexing from a remote server uses an on-heap buffer that defaults to a maximum size of 100mb. If the remote index includes very large documents you'll need to use a smaller batch size. It is also possible to set the socket read timeout on the remote connection with the `socket_timeout` field and the connection timeout with the `connect_timeout` field. Both default to 30 seconds. **Configuring SSL parameters** Reindex from remote supports configurable SSL settings. These must be specified in the `elasticsearch.yml` file, with the exception of the secure settings, which you add in the Elasticsearch keystore. It is not possible to configure SSL in the body of the reindex request. @@ -45,8 +74,12 @@ export default async function ReindexApi (this: That, params: T.ReindexRequest, export default async function ReindexApi (this: That, params: T.ReindexRequest, options?: TransportRequestOptionsWithMeta): Promise<TransportResult<T.ReindexResponse, unknown>> export default async function ReindexApi (this: That, params: T.ReindexRequest, options?: TransportRequestOptions): Promise<T.ReindexResponse> export default async function ReindexApi (this: That, params: T.ReindexRequest, options?: TransportRequestOptions): Promise<any> { - const acceptedPath: string[] = [] - const acceptedBody: string[] = ['conflicts', 'dest', 'max_docs', 'script', 'size', 'source'] + const { + path: acceptedPath, + body: acceptedBody, + query: acceptedQuery + } = acceptedParams.reindex + const userQuery = params?.querystring const querystring: Record<string, any> = userQuery != null ? { ...userQuery } : {} @@ -68,8 +101,14 @@ export default async function ReindexApi (this: That, params: T.ReindexRequest, } else if (acceptedPath.includes(key)) { continue } else if (key !== 'body' && key !== 'querystring') { - // @ts-expect-error - querystring[key] = params[key] + if (acceptedQuery.includes(key) || commonQueryParams.includes(key)) { + // @ts-expect-error + querystring[key] = params[key] + } else { + body = body ?? {} + // @ts-expect-error + body[key] = params[key] + } } } diff --git a/src/api/api/reindex_rethrottle.ts b/src/api/api/reindex_rethrottle.ts index d32f80c01..13a52ff25 100644 --- a/src/api/api/reindex_rethrottle.ts +++ b/src/api/api/reindex_rethrottle.ts @@ -35,7 +35,22 @@ import { TransportResult } from '@elastic/transport' import * as T from '../types' -interface That { transport: Transport } + +interface That { + transport: Transport +} + +const acceptedParams: Record<string, { path: string[], body: string[], query: string[] }> = { + reindex_rethrottle: { + path: [ + 'task_id' + ], + body: [], + query: [ + 'requests_per_second' + ] + } +} /** * Throttle a reindex operation. Change the number of requests per second for a particular reindex operation. For example: ``` POST _reindex/r1A2WoRbTwKZ516z6NEs5A:36619/_rethrottle?requests_per_second=-1 ``` Rethrottling that speeds up the query takes effect immediately. Rethrottling that slows down the query will take effect after completing the current batch. This behavior prevents scroll timeouts. @@ -45,7 +60,10 @@ export default async function ReindexRethrottleApi (this: That, params: T.Reinde export default async function ReindexRethrottleApi (this: That, params: T.ReindexRethrottleRequest, options?: TransportRequestOptionsWithMeta): Promise<TransportResult<T.ReindexRethrottleResponse, unknown>> export default async function ReindexRethrottleApi (this: That, params: T.ReindexRethrottleRequest, options?: TransportRequestOptions): Promise<T.ReindexRethrottleResponse> export default async function ReindexRethrottleApi (this: That, params: T.ReindexRethrottleRequest, options?: TransportRequestOptions): Promise<any> { - const acceptedPath: string[] = ['task_id'] + const { + path: acceptedPath + } = acceptedParams.reindex_rethrottle + const userQuery = params?.querystring const querystring: Record<string, any> = userQuery != null ? { ...userQuery } : {} diff --git a/src/api/api/render_search_template.ts b/src/api/api/render_search_template.ts index 57b5377c6..40af73935 100644 --- a/src/api/api/render_search_template.ts +++ b/src/api/api/render_search_template.ts @@ -35,7 +35,25 @@ import { TransportResult } from '@elastic/transport' import * as T from '../types' -interface That { transport: Transport } + +interface That { + transport: Transport +} + +const commonQueryParams = ['error_trace', 'filter_path', 'human', 'pretty'] + +const acceptedParams: Record<string, { path: string[], body: string[], query: string[] }> = { + render_search_template: { + path: [], + body: [ + 'id', + 'file', + 'params', + 'source' + ], + query: [] + } +} /** * Render a search template. Render a search template as a search request body. @@ -45,8 +63,12 @@ export default async function RenderSearchTemplateApi (this: That, params?: T.Re export default async function RenderSearchTemplateApi (this: That, params?: T.RenderSearchTemplateRequest, options?: TransportRequestOptionsWithMeta): Promise<TransportResult<T.RenderSearchTemplateResponse, unknown>> export default async function RenderSearchTemplateApi (this: That, params?: T.RenderSearchTemplateRequest, options?: TransportRequestOptions): Promise<T.RenderSearchTemplateResponse> export default async function RenderSearchTemplateApi (this: That, params?: T.RenderSearchTemplateRequest, options?: TransportRequestOptions): Promise<any> { - const acceptedPath: string[] = [] - const acceptedBody: string[] = ['id', 'file', 'params', 'source'] + const { + path: acceptedPath, + body: acceptedBody, + query: acceptedQuery + } = acceptedParams.render_search_template + const userQuery = params?.querystring const querystring: Record<string, any> = userQuery != null ? { ...userQuery } : {} @@ -69,8 +91,14 @@ export default async function RenderSearchTemplateApi (this: That, params?: T.Re } else if (acceptedPath.includes(key)) { continue } else if (key !== 'body' && key !== 'querystring') { - // @ts-expect-error - querystring[key] = params[key] + if (acceptedQuery.includes(key) || commonQueryParams.includes(key)) { + // @ts-expect-error + querystring[key] = params[key] + } else { + body = body ?? {} + // @ts-expect-error + body[key] = params[key] + } } } diff --git a/src/api/api/rollup.ts b/src/api/api/rollup.ts index b45043728..753acf55a 100644 --- a/src/api/api/rollup.ts +++ b/src/api/api/rollup.ts @@ -35,12 +35,97 @@ import { TransportResult } from '@elastic/transport' import * as T from '../types' -interface That { transport: Transport } + +interface That { + transport: Transport + acceptedParams: Record<string, { path: string[], body: string[], query: string[] }> +} + +const commonQueryParams = ['error_trace', 'filter_path', 'human', 'pretty'] export default class Rollup { transport: Transport + acceptedParams: Record<string, { path: string[], body: string[], query: string[] }> constructor (transport: Transport) { this.transport = transport + this.acceptedParams = { + 'rollup.delete_job': { + path: [ + 'id' + ], + body: [], + query: [] + }, + 'rollup.get_jobs': { + path: [ + 'id' + ], + body: [], + query: [] + }, + 'rollup.get_rollup_caps': { + path: [ + 'id' + ], + body: [], + query: [] + }, + 'rollup.get_rollup_index_caps': { + path: [ + 'index' + ], + body: [], + query: [] + }, + 'rollup.put_job': { + path: [ + 'id' + ], + body: [ + 'cron', + 'groups', + 'index_pattern', + 'metrics', + 'page_size', + 'rollup_index', + 'timeout', + 'headers' + ], + query: [] + }, + 'rollup.rollup_search': { + path: [ + 'index' + ], + body: [ + 'aggregations', + 'aggs', + 'query', + 'size' + ], + query: [ + 'rest_total_hits_as_int', + 'typed_keys' + ] + }, + 'rollup.start_job': { + path: [ + 'id' + ], + body: [], + query: [] + }, + 'rollup.stop_job': { + path: [ + 'id' + ], + body: [], + query: [ + 'timeout', + 'wait_for_completion' + ] + } + } } /** @@ -51,7 +136,10 @@ export default class Rollup { async deleteJob (this: That, params: T.RollupDeleteJobRequest, options?: TransportRequestOptionsWithMeta): Promise<TransportResult<T.RollupDeleteJobResponse, unknown>> async deleteJob (this: That, params: T.RollupDeleteJobRequest, options?: TransportRequestOptions): Promise<T.RollupDeleteJobResponse> async deleteJob (this: That, params: T.RollupDeleteJobRequest, options?: TransportRequestOptions): Promise<any> { - const acceptedPath: string[] = ['id'] + const { + path: acceptedPath + } = this.acceptedParams['rollup.delete_job'] + const userQuery = params?.querystring const querystring: Record<string, any> = userQuery != null ? { ...userQuery } : {} @@ -93,7 +181,10 @@ export default class Rollup { async getJobs (this: That, params?: T.RollupGetJobsRequest, options?: TransportRequestOptionsWithMeta): Promise<TransportResult<T.RollupGetJobsResponse, unknown>> async getJobs (this: That, params?: T.RollupGetJobsRequest, options?: TransportRequestOptions): Promise<T.RollupGetJobsResponse> async getJobs (this: That, params?: T.RollupGetJobsRequest, options?: TransportRequestOptions): Promise<any> { - const acceptedPath: string[] = ['id'] + const { + path: acceptedPath + } = this.acceptedParams['rollup.get_jobs'] + const userQuery = params?.querystring const querystring: Record<string, any> = userQuery != null ? { ...userQuery } : {} @@ -143,7 +234,10 @@ export default class Rollup { async getRollupCaps (this: That, params?: T.RollupGetRollupCapsRequest, options?: TransportRequestOptionsWithMeta): Promise<TransportResult<T.RollupGetRollupCapsResponse, unknown>> async getRollupCaps (this: That, params?: T.RollupGetRollupCapsRequest, options?: TransportRequestOptions): Promise<T.RollupGetRollupCapsResponse> async getRollupCaps (this: That, params?: T.RollupGetRollupCapsRequest, options?: TransportRequestOptions): Promise<any> { - const acceptedPath: string[] = ['id'] + const { + path: acceptedPath + } = this.acceptedParams['rollup.get_rollup_caps'] + const userQuery = params?.querystring const querystring: Record<string, any> = userQuery != null ? { ...userQuery } : {} @@ -193,7 +287,10 @@ export default class Rollup { async getRollupIndexCaps (this: That, params: T.RollupGetRollupIndexCapsRequest, options?: TransportRequestOptionsWithMeta): Promise<TransportResult<T.RollupGetRollupIndexCapsResponse, unknown>> async getRollupIndexCaps (this: That, params: T.RollupGetRollupIndexCapsRequest, options?: TransportRequestOptions): Promise<T.RollupGetRollupIndexCapsResponse> async getRollupIndexCaps (this: That, params: T.RollupGetRollupIndexCapsRequest, options?: TransportRequestOptions): Promise<any> { - const acceptedPath: string[] = ['index'] + const { + path: acceptedPath + } = this.acceptedParams['rollup.get_rollup_index_caps'] + const userQuery = params?.querystring const querystring: Record<string, any> = userQuery != null ? { ...userQuery } : {} @@ -235,8 +332,12 @@ export default class Rollup { async putJob (this: That, params: T.RollupPutJobRequest, options?: TransportRequestOptionsWithMeta): Promise<TransportResult<T.RollupPutJobResponse, unknown>> async putJob (this: That, params: T.RollupPutJobRequest, options?: TransportRequestOptions): Promise<T.RollupPutJobResponse> async putJob (this: That, params: T.RollupPutJobRequest, options?: TransportRequestOptions): Promise<any> { - const acceptedPath: string[] = ['id'] - const acceptedBody: string[] = ['cron', 'groups', 'index_pattern', 'metrics', 'page_size', 'rollup_index', 'timeout', 'headers'] + const { + path: acceptedPath, + body: acceptedBody, + query: acceptedQuery + } = this.acceptedParams['rollup.put_job'] + const userQuery = params?.querystring const querystring: Record<string, any> = userQuery != null ? { ...userQuery } : {} @@ -258,8 +359,14 @@ export default class Rollup { } else if (acceptedPath.includes(key)) { continue } else if (key !== 'body' && key !== 'querystring') { - // @ts-expect-error - querystring[key] = params[key] + if (acceptedQuery.includes(key) || commonQueryParams.includes(key)) { + // @ts-expect-error + querystring[key] = params[key] + } else { + body = body ?? {} + // @ts-expect-error + body[key] = params[key] + } } } @@ -282,8 +389,12 @@ export default class Rollup { async rollupSearch<TDocument = unknown, TAggregations = Record<T.AggregateName, T.AggregationsAggregate>> (this: That, params: T.RollupRollupSearchRequest, options?: TransportRequestOptionsWithMeta): Promise<TransportResult<T.RollupRollupSearchResponse<TDocument, TAggregations>, unknown>> async rollupSearch<TDocument = unknown, TAggregations = Record<T.AggregateName, T.AggregationsAggregate>> (this: That, params: T.RollupRollupSearchRequest, options?: TransportRequestOptions): Promise<T.RollupRollupSearchResponse<TDocument, TAggregations>> async rollupSearch<TDocument = unknown, TAggregations = Record<T.AggregateName, T.AggregationsAggregate>> (this: That, params: T.RollupRollupSearchRequest, options?: TransportRequestOptions): Promise<any> { - const acceptedPath: string[] = ['index'] - const acceptedBody: string[] = ['aggregations', 'aggs', 'query', 'size'] + const { + path: acceptedPath, + body: acceptedBody, + query: acceptedQuery + } = this.acceptedParams['rollup.rollup_search'] + const userQuery = params?.querystring const querystring: Record<string, any> = userQuery != null ? { ...userQuery } : {} @@ -305,8 +416,14 @@ export default class Rollup { } else if (acceptedPath.includes(key)) { continue } else if (key !== 'body' && key !== 'querystring') { - // @ts-expect-error - querystring[key] = params[key] + if (acceptedQuery.includes(key) || commonQueryParams.includes(key)) { + // @ts-expect-error + querystring[key] = params[key] + } else { + body = body ?? {} + // @ts-expect-error + body[key] = params[key] + } } } @@ -329,7 +446,10 @@ export default class Rollup { async startJob (this: That, params: T.RollupStartJobRequest, options?: TransportRequestOptionsWithMeta): Promise<TransportResult<T.RollupStartJobResponse, unknown>> async startJob (this: That, params: T.RollupStartJobRequest, options?: TransportRequestOptions): Promise<T.RollupStartJobResponse> async startJob (this: That, params: T.RollupStartJobRequest, options?: TransportRequestOptions): Promise<any> { - const acceptedPath: string[] = ['id'] + const { + path: acceptedPath + } = this.acceptedParams['rollup.start_job'] + const userQuery = params?.querystring const querystring: Record<string, any> = userQuery != null ? { ...userQuery } : {} @@ -371,7 +491,10 @@ export default class Rollup { async stopJob (this: That, params: T.RollupStopJobRequest, options?: TransportRequestOptionsWithMeta): Promise<TransportResult<T.RollupStopJobResponse, unknown>> async stopJob (this: That, params: T.RollupStopJobRequest, options?: TransportRequestOptions): Promise<T.RollupStopJobResponse> async stopJob (this: That, params: T.RollupStopJobRequest, options?: TransportRequestOptions): Promise<any> { - const acceptedPath: string[] = ['id'] + const { + path: acceptedPath + } = this.acceptedParams['rollup.stop_job'] + const userQuery = params?.querystring const querystring: Record<string, any> = userQuery != null ? { ...userQuery } : {} diff --git a/src/api/api/scripts_painless_execute.ts b/src/api/api/scripts_painless_execute.ts index bbafbeff1..35fcd6225 100644 --- a/src/api/api/scripts_painless_execute.ts +++ b/src/api/api/scripts_painless_execute.ts @@ -35,7 +35,24 @@ import { TransportResult } from '@elastic/transport' import * as T from '../types' -interface That { transport: Transport } + +interface That { + transport: Transport +} + +const commonQueryParams = ['error_trace', 'filter_path', 'human', 'pretty'] + +const acceptedParams: Record<string, { path: string[], body: string[], query: string[] }> = { + scripts_painless_execute: { + path: [], + body: [ + 'context', + 'context_setup', + 'script' + ], + query: [] + } +} /** * Run a script. Runs a script and returns a result. Use this API to build and test scripts, such as when defining a script for a runtime field. This API requires very few dependencies and is especially useful if you don't have permissions to write documents on a cluster. The API uses several _contexts_, which control how scripts are run, what variables are available at runtime, and what the return type is. Each context requires a script, but additional parameters depend on the context you're using for that script. @@ -45,8 +62,12 @@ export default async function ScriptsPainlessExecuteApi<TResult = unknown> (this export default async function ScriptsPainlessExecuteApi<TResult = unknown> (this: That, params?: T.ScriptsPainlessExecuteRequest, options?: TransportRequestOptionsWithMeta): Promise<TransportResult<T.ScriptsPainlessExecuteResponse<TResult>, unknown>> export default async function ScriptsPainlessExecuteApi<TResult = unknown> (this: That, params?: T.ScriptsPainlessExecuteRequest, options?: TransportRequestOptions): Promise<T.ScriptsPainlessExecuteResponse<TResult>> export default async function ScriptsPainlessExecuteApi<TResult = unknown> (this: That, params?: T.ScriptsPainlessExecuteRequest, options?: TransportRequestOptions): Promise<any> { - const acceptedPath: string[] = [] - const acceptedBody: string[] = ['context', 'context_setup', 'script'] + const { + path: acceptedPath, + body: acceptedBody, + query: acceptedQuery + } = acceptedParams.scripts_painless_execute + const userQuery = params?.querystring const querystring: Record<string, any> = userQuery != null ? { ...userQuery } : {} @@ -69,8 +90,14 @@ export default async function ScriptsPainlessExecuteApi<TResult = unknown> (this } else if (acceptedPath.includes(key)) { continue } else if (key !== 'body' && key !== 'querystring') { - // @ts-expect-error - querystring[key] = params[key] + if (acceptedQuery.includes(key) || commonQueryParams.includes(key)) { + // @ts-expect-error + querystring[key] = params[key] + } else { + body = body ?? {} + // @ts-expect-error + body[key] = params[key] + } } } diff --git a/src/api/api/scroll.ts b/src/api/api/scroll.ts index 5bd03110b..184e45b2a 100644 --- a/src/api/api/scroll.ts +++ b/src/api/api/scroll.ts @@ -35,7 +35,27 @@ import { TransportResult } from '@elastic/transport' import * as T from '../types' -interface That { transport: Transport } + +interface That { + transport: Transport +} + +const commonQueryParams = ['error_trace', 'filter_path', 'human', 'pretty'] + +const acceptedParams: Record<string, { path: string[], body: string[], query: string[] }> = { + scroll: { + path: [], + body: [ + 'scroll', + 'scroll_id' + ], + query: [ + 'scroll', + 'scroll_id', + 'rest_total_hits_as_int' + ] + } +} /** * Run a scrolling search. IMPORTANT: The scroll API is no longer recommend for deep pagination. If you need to preserve the index state while paging through more than 10,000 hits, use the `search_after` parameter with a point in time (PIT). The scroll API gets large sets of results from a single scrolling search request. To get the necessary scroll ID, submit a search API request that includes an argument for the `scroll` query parameter. The `scroll` parameter indicates how long Elasticsearch should retain the search context for the request. The search response returns a scroll ID in the `_scroll_id` response body parameter. You can then use the scroll ID with the scroll API to retrieve the next batch of results for the request. If the Elasticsearch security features are enabled, the access to the results of a specific scroll ID is restricted to the user or API key that submitted the search. You can also use the scroll API to specify a new scroll parameter that extends or shortens the retention period for the search context. IMPORTANT: Results from a scrolling search reflect the state of the index at the time of the initial search request. Subsequent indexing or document changes only affect later search and scroll requests. @@ -45,8 +65,12 @@ export default async function ScrollApi<TDocument = unknown, TAggregations = Rec export default async function ScrollApi<TDocument = unknown, TAggregations = Record<T.AggregateName, T.AggregationsAggregate>> (this: That, params: T.ScrollRequest, options?: TransportRequestOptionsWithMeta): Promise<TransportResult<T.ScrollResponse<TDocument, TAggregations>, unknown>> export default async function ScrollApi<TDocument = unknown, TAggregations = Record<T.AggregateName, T.AggregationsAggregate>> (this: That, params: T.ScrollRequest, options?: TransportRequestOptions): Promise<T.ScrollResponse<TDocument, TAggregations>> export default async function ScrollApi<TDocument = unknown, TAggregations = Record<T.AggregateName, T.AggregationsAggregate>> (this: That, params: T.ScrollRequest, options?: TransportRequestOptions): Promise<any> { - const acceptedPath: string[] = [] - const acceptedBody: string[] = ['scroll', 'scroll_id'] + const { + path: acceptedPath, + body: acceptedBody, + query: acceptedQuery + } = acceptedParams.scroll + const userQuery = params?.querystring const querystring: Record<string, any> = userQuery != null ? { ...userQuery } : {} @@ -68,8 +92,14 @@ export default async function ScrollApi<TDocument = unknown, TAggregations = Rec } else if (acceptedPath.includes(key)) { continue } else if (key !== 'body' && key !== 'querystring') { - // @ts-expect-error - querystring[key] = params[key] + if (acceptedQuery.includes(key) || commonQueryParams.includes(key)) { + // @ts-expect-error + querystring[key] = params[key] + } else { + body = body ?? {} + // @ts-expect-error + body[key] = params[key] + } } } diff --git a/src/api/api/search.ts b/src/api/api/search.ts index cf2630413..20f38edd1 100644 --- a/src/api/api/search.ts +++ b/src/api/api/search.ts @@ -35,7 +35,103 @@ import { TransportResult } from '@elastic/transport' import * as T from '../types' -interface That { transport: Transport } + +interface That { + transport: Transport +} + +const commonQueryParams = ['error_trace', 'filter_path', 'human', 'pretty'] + +const acceptedParams: Record<string, { path: string[], body: string[], query: string[] }> = { + search: { + path: [ + 'index' + ], + body: [ + 'aggregations', + 'aggs', + 'collapse', + 'explain', + 'ext', + 'from', + 'highlight', + 'track_total_hits', + 'indices_boost', + 'docvalue_fields', + 'knn', + 'rank', + 'min_score', + 'post_filter', + 'profile', + 'query', + 'rescore', + 'retriever', + 'script_fields', + 'search_after', + 'size', + 'slice', + 'sort', + '_source', + 'fields', + 'suggest', + 'terminate_after', + 'timeout', + 'track_scores', + 'version', + 'seq_no_primary_term', + 'stored_fields', + 'pit', + 'runtime_mappings', + 'stats' + ], + query: [ + 'allow_no_indices', + 'allow_partial_search_results', + 'analyzer', + 'analyze_wildcard', + 'batched_reduce_size', + 'ccs_minimize_roundtrips', + 'default_operator', + 'df', + 'docvalue_fields', + 'expand_wildcards', + 'explain', + 'ignore_throttled', + 'ignore_unavailable', + 'include_named_queries_score', + 'lenient', + 'max_concurrent_shard_requests', + 'preference', + 'pre_filter_shard_size', + 'request_cache', + 'routing', + 'scroll', + 'search_type', + 'stats', + 'stored_fields', + 'suggest_field', + 'suggest_mode', + 'suggest_size', + 'suggest_text', + 'terminate_after', + 'timeout', + 'track_total_hits', + 'track_scores', + 'typed_keys', + 'rest_total_hits_as_int', + 'version', + '_source', + '_source_excludes', + '_source_includes', + 'seq_no_primary_term', + 'q', + 'size', + 'from', + 'sort', + 'force_synthetic_source' + ] + } +} /** * Run a search. Get search hits that match the query defined in the request. You can provide search queries using the `q` query string parameter or the request body. If both are specified, only the query parameter is used. If the Elasticsearch security features are enabled, you must have the read index privilege for the target data stream, index, or alias. For cross-cluster search, refer to the documentation about configuring CCS privileges. To search a point in time (PIT) for an alias, you must have the `read` index privilege for the alias's data streams or indices. **Search slicing** When paging through a large number of documents, it can be helpful to split the search into multiple slices to consume them independently with the `slice` and `pit` properties. By default the splitting is done first on the shards, then locally on each shard. The local splitting partitions the shard into contiguous ranges based on Lucene document IDs. For instance if the number of shards is equal to 2 and you request 4 slices, the slices 0 and 2 are assigned to the first shard and the slices 1 and 3 are assigned to the second shard. IMPORTANT: The same point-in-time ID should be used for all slices. If different PIT IDs are used, slices can overlap and miss documents. This situation can occur because the splitting criterion is based on Lucene document IDs, which are not stable across changes to the index. @@ -45,8 +141,12 @@ export default async function SearchApi<TDocument = unknown, TAggregations = Rec export default async function SearchApi<TDocument = unknown, TAggregations = Record<T.AggregateName, T.AggregationsAggregate>> (this: That, params?: T.SearchRequest, options?: TransportRequestOptionsWithMeta): Promise<TransportResult<T.SearchResponse<TDocument, TAggregations>, unknown>> export default async function SearchApi<TDocument = unknown, TAggregations = Record<T.AggregateName, T.AggregationsAggregate>> (this: That, params?: T.SearchRequest, options?: TransportRequestOptions): Promise<T.SearchResponse<TDocument, TAggregations>> export default async function SearchApi<TDocument = unknown, TAggregations = Record<T.AggregateName, T.AggregationsAggregate>> (this: That, params?: T.SearchRequest, options?: TransportRequestOptions): Promise<any> { - const acceptedPath: string[] = ['index'] - const acceptedBody: string[] = ['aggregations', 'aggs', 'collapse', 'explain', 'ext', 'from', 'highlight', 'track_total_hits', 'indices_boost', 'docvalue_fields', 'knn', 'rank', 'min_score', 'post_filter', 'profile', 'query', 'rescore', 'retriever', 'script_fields', 'search_after', 'size', 'slice', 'sort', '_source', 'fields', 'suggest', 'terminate_after', 'timeout', 'track_scores', 'version', 'seq_no_primary_term', 'stored_fields', 'pit', 'runtime_mappings', 'stats'] + const { + path: acceptedPath, + body: acceptedBody, + query: acceptedQuery + } = acceptedParams.search + const userQuery = params?.querystring const querystring: Record<string, any> = userQuery != null ? { ...userQuery } : {} @@ -73,8 +173,14 @@ export default async function SearchApi<TDocument = unknown, TAggregations = Rec } else if (acceptedPath.includes(key)) { continue } else if (key !== 'body' && key !== 'querystring') { - // @ts-expect-error - querystring[key] = params[key] + if (acceptedQuery.includes(key) || commonQueryParams.includes(key)) { + // @ts-expect-error + querystring[key] = params[key] + } else { + body = body ?? {} + // @ts-expect-error + body[key] = params[key] + } } } diff --git a/src/api/api/search_application.ts b/src/api/api/search_application.ts index 71e583672..af33acfd3 100644 --- a/src/api/api/search_application.ts +++ b/src/api/api/search_application.ts @@ -35,12 +35,108 @@ import { TransportResult } from '@elastic/transport' import * as T from '../types' -interface That { transport: Transport } + +interface That { + transport: Transport + acceptedParams: Record<string, { path: string[], body: string[], query: string[] }> +} + +const commonQueryParams = ['error_trace', 'filter_path', 'human', 'pretty'] export default class SearchApplication { transport: Transport + acceptedParams: Record<string, { path: string[], body: string[], query: string[] }> constructor (transport: Transport) { this.transport = transport + this.acceptedParams = { + 'search_application.delete': { + path: [ + 'name' + ], + body: [], + query: [] + }, + 'search_application.delete_behavioral_analytics': { + path: [ + 'name' + ], + body: [], + query: [] + }, + 'search_application.get': { + path: [ + 'name' + ], + body: [], + query: [] + }, + 'search_application.get_behavioral_analytics': { + path: [ + 'name' + ], + body: [], + query: [] + }, + 'search_application.list': { + path: [], + body: [], + query: [ + 'q', + 'from', + 'size' + ] + }, + 'search_application.post_behavioral_analytics_event': { + path: [ + 'collection_name', + 'event_type' + ], + body: [ + 'payload' + ], + query: [ + 'debug' + ] + }, + 'search_application.put': { + path: [ + 'name' + ], + body: [ + 'search_application' + ], + query: [ + 'create' + ] + }, + 'search_application.put_behavioral_analytics': { + path: [ + 'name' + ], + body: [], + query: [] + }, + 'search_application.render_query': { + path: [ + 'name' + ], + body: [ + 'params' + ], + query: [] + }, + 'search_application.search': { + path: [ + 'name' + ], + body: [ + 'params' + ], + query: [ + 'typed_keys' + ] + } + } } /** @@ -51,7 +147,10 @@ export default class SearchApplication { async delete (this: That, params: T.SearchApplicationDeleteRequest, options?: TransportRequestOptionsWithMeta): Promise<TransportResult<T.SearchApplicationDeleteResponse, unknown>> async delete (this: That, params: T.SearchApplicationDeleteRequest, options?: TransportRequestOptions): Promise<T.SearchApplicationDeleteResponse> async delete (this: That, params: T.SearchApplicationDeleteRequest, options?: TransportRequestOptions): Promise<any> { - const acceptedPath: string[] = ['name'] + const { + path: acceptedPath + } = this.acceptedParams['search_application.delete'] + const userQuery = params?.querystring const querystring: Record<string, any> = userQuery != null ? { ...userQuery } : {} @@ -93,7 +192,10 @@ export default class SearchApplication { async deleteBehavioralAnalytics (this: That, params: T.SearchApplicationDeleteBehavioralAnalyticsRequest, options?: TransportRequestOptionsWithMeta): Promise<TransportResult<T.SearchApplicationDeleteBehavioralAnalyticsResponse, unknown>> async deleteBehavioralAnalytics (this: That, params: T.SearchApplicationDeleteBehavioralAnalyticsRequest, options?: TransportRequestOptions): Promise<T.SearchApplicationDeleteBehavioralAnalyticsResponse> async deleteBehavioralAnalytics (this: That, params: T.SearchApplicationDeleteBehavioralAnalyticsRequest, options?: TransportRequestOptions): Promise<any> { - const acceptedPath: string[] = ['name'] + const { + path: acceptedPath + } = this.acceptedParams['search_application.delete_behavioral_analytics'] + const userQuery = params?.querystring const querystring: Record<string, any> = userQuery != null ? { ...userQuery } : {} @@ -135,7 +237,10 @@ export default class SearchApplication { async get (this: That, params: T.SearchApplicationGetRequest, options?: TransportRequestOptionsWithMeta): Promise<TransportResult<T.SearchApplicationGetResponse, unknown>> async get (this: That, params: T.SearchApplicationGetRequest, options?: TransportRequestOptions): Promise<T.SearchApplicationGetResponse> async get (this: That, params: T.SearchApplicationGetRequest, options?: TransportRequestOptions): Promise<any> { - const acceptedPath: string[] = ['name'] + const { + path: acceptedPath + } = this.acceptedParams['search_application.get'] + const userQuery = params?.querystring const querystring: Record<string, any> = userQuery != null ? { ...userQuery } : {} @@ -177,7 +282,10 @@ export default class SearchApplication { async getBehavioralAnalytics (this: That, params?: T.SearchApplicationGetBehavioralAnalyticsRequest, options?: TransportRequestOptionsWithMeta): Promise<TransportResult<T.SearchApplicationGetBehavioralAnalyticsResponse, unknown>> async getBehavioralAnalytics (this: That, params?: T.SearchApplicationGetBehavioralAnalyticsRequest, options?: TransportRequestOptions): Promise<T.SearchApplicationGetBehavioralAnalyticsResponse> async getBehavioralAnalytics (this: That, params?: T.SearchApplicationGetBehavioralAnalyticsRequest, options?: TransportRequestOptions): Promise<any> { - const acceptedPath: string[] = ['name'] + const { + path: acceptedPath + } = this.acceptedParams['search_application.get_behavioral_analytics'] + const userQuery = params?.querystring const querystring: Record<string, any> = userQuery != null ? { ...userQuery } : {} @@ -227,7 +335,10 @@ export default class SearchApplication { async list (this: That, params?: T.SearchApplicationListRequest, options?: TransportRequestOptionsWithMeta): Promise<TransportResult<T.SearchApplicationListResponse, unknown>> async list (this: That, params?: T.SearchApplicationListRequest, options?: TransportRequestOptions): Promise<T.SearchApplicationListResponse> async list (this: That, params?: T.SearchApplicationListRequest, options?: TransportRequestOptions): Promise<any> { - const acceptedPath: string[] = [] + const { + path: acceptedPath + } = this.acceptedParams['search_application.list'] + const userQuery = params?.querystring const querystring: Record<string, any> = userQuery != null ? { ...userQuery } : {} @@ -267,8 +378,12 @@ export default class SearchApplication { async postBehavioralAnalyticsEvent (this: That, params: T.SearchApplicationPostBehavioralAnalyticsEventRequest, options?: TransportRequestOptionsWithMeta): Promise<TransportResult<T.SearchApplicationPostBehavioralAnalyticsEventResponse, unknown>> async postBehavioralAnalyticsEvent (this: That, params: T.SearchApplicationPostBehavioralAnalyticsEventRequest, options?: TransportRequestOptions): Promise<T.SearchApplicationPostBehavioralAnalyticsEventResponse> async postBehavioralAnalyticsEvent (this: That, params: T.SearchApplicationPostBehavioralAnalyticsEventRequest, options?: TransportRequestOptions): Promise<any> { - const acceptedPath: string[] = ['collection_name', 'event_type'] - const acceptedBody: string[] = ['payload'] + const { + path: acceptedPath, + body: acceptedBody, + query: acceptedQuery + } = this.acceptedParams['search_application.post_behavioral_analytics_event'] + const userQuery = params?.querystring const querystring: Record<string, any> = userQuery != null ? { ...userQuery } : {} @@ -280,8 +395,14 @@ export default class SearchApplication { } else if (acceptedPath.includes(key)) { continue } else if (key !== 'body' && key !== 'querystring') { - // @ts-expect-error - querystring[key] = params[key] + if (acceptedQuery.includes(key) || commonQueryParams.includes(key)) { + // @ts-expect-error + querystring[key] = params[key] + } else { + body = body ?? {} + // @ts-expect-error + body[key] = params[key] + } } } @@ -305,8 +426,12 @@ export default class SearchApplication { async put (this: That, params: T.SearchApplicationPutRequest, options?: TransportRequestOptionsWithMeta): Promise<TransportResult<T.SearchApplicationPutResponse, unknown>> async put (this: That, params: T.SearchApplicationPutRequest, options?: TransportRequestOptions): Promise<T.SearchApplicationPutResponse> async put (this: That, params: T.SearchApplicationPutRequest, options?: TransportRequestOptions): Promise<any> { - const acceptedPath: string[] = ['name'] - const acceptedBody: string[] = ['search_application'] + const { + path: acceptedPath, + body: acceptedBody, + query: acceptedQuery + } = this.acceptedParams['search_application.put'] + const userQuery = params?.querystring const querystring: Record<string, any> = userQuery != null ? { ...userQuery } : {} @@ -318,8 +443,14 @@ export default class SearchApplication { } else if (acceptedPath.includes(key)) { continue } else if (key !== 'body' && key !== 'querystring') { - // @ts-expect-error - querystring[key] = params[key] + if (acceptedQuery.includes(key) || commonQueryParams.includes(key)) { + // @ts-expect-error + querystring[key] = params[key] + } else { + body = body ?? {} + // @ts-expect-error + body[key] = params[key] + } } } @@ -342,7 +473,10 @@ export default class SearchApplication { async putBehavioralAnalytics (this: That, params: T.SearchApplicationPutBehavioralAnalyticsRequest, options?: TransportRequestOptionsWithMeta): Promise<TransportResult<T.SearchApplicationPutBehavioralAnalyticsResponse, unknown>> async putBehavioralAnalytics (this: That, params: T.SearchApplicationPutBehavioralAnalyticsRequest, options?: TransportRequestOptions): Promise<T.SearchApplicationPutBehavioralAnalyticsResponse> async putBehavioralAnalytics (this: That, params: T.SearchApplicationPutBehavioralAnalyticsRequest, options?: TransportRequestOptions): Promise<any> { - const acceptedPath: string[] = ['name'] + const { + path: acceptedPath + } = this.acceptedParams['search_application.put_behavioral_analytics'] + const userQuery = params?.querystring const querystring: Record<string, any> = userQuery != null ? { ...userQuery } : {} @@ -384,8 +518,12 @@ export default class SearchApplication { async renderQuery (this: That, params: T.SearchApplicationRenderQueryRequest, options?: TransportRequestOptionsWithMeta): Promise<TransportResult<T.SearchApplicationRenderQueryResponse, unknown>> async renderQuery (this: That, params: T.SearchApplicationRenderQueryRequest, options?: TransportRequestOptions): Promise<T.SearchApplicationRenderQueryResponse> async renderQuery (this: That, params: T.SearchApplicationRenderQueryRequest, options?: TransportRequestOptions): Promise<any> { - const acceptedPath: string[] = ['name'] - const acceptedBody: string[] = ['params'] + const { + path: acceptedPath, + body: acceptedBody, + query: acceptedQuery + } = this.acceptedParams['search_application.render_query'] + const userQuery = params?.querystring const querystring: Record<string, any> = userQuery != null ? { ...userQuery } : {} @@ -407,8 +545,14 @@ export default class SearchApplication { } else if (acceptedPath.includes(key)) { continue } else if (key !== 'body' && key !== 'querystring') { - // @ts-expect-error - querystring[key] = params[key] + if (acceptedQuery.includes(key) || commonQueryParams.includes(key)) { + // @ts-expect-error + querystring[key] = params[key] + } else { + body = body ?? {} + // @ts-expect-error + body[key] = params[key] + } } } @@ -431,8 +575,12 @@ export default class SearchApplication { async search<TDocument = unknown, TAggregations = Record<T.AggregateName, T.AggregationsAggregate>> (this: That, params: T.SearchApplicationSearchRequest, options?: TransportRequestOptionsWithMeta): Promise<TransportResult<T.SearchApplicationSearchResponse<TDocument, TAggregations>, unknown>> async search<TDocument = unknown, TAggregations = Record<T.AggregateName, T.AggregationsAggregate>> (this: That, params: T.SearchApplicationSearchRequest, options?: TransportRequestOptions): Promise<T.SearchApplicationSearchResponse<TDocument, TAggregations>> async search<TDocument = unknown, TAggregations = Record<T.AggregateName, T.AggregationsAggregate>> (this: That, params: T.SearchApplicationSearchRequest, options?: TransportRequestOptions): Promise<any> { - const acceptedPath: string[] = ['name'] - const acceptedBody: string[] = ['params'] + const { + path: acceptedPath, + body: acceptedBody, + query: acceptedQuery + } = this.acceptedParams['search_application.search'] + const userQuery = params?.querystring const querystring: Record<string, any> = userQuery != null ? { ...userQuery } : {} @@ -454,8 +602,14 @@ export default class SearchApplication { } else if (acceptedPath.includes(key)) { continue } else if (key !== 'body' && key !== 'querystring') { - // @ts-expect-error - querystring[key] = params[key] + if (acceptedQuery.includes(key) || commonQueryParams.includes(key)) { + // @ts-expect-error + querystring[key] = params[key] + } else { + body = body ?? {} + // @ts-expect-error + body[key] = params[key] + } } } diff --git a/src/api/api/search_mvt.ts b/src/api/api/search_mvt.ts index c9384a91e..34695497b 100644 --- a/src/api/api/search_mvt.ts +++ b/src/api/api/search_mvt.ts @@ -35,7 +35,49 @@ import { TransportResult } from '@elastic/transport' import * as T from '../types' -interface That { transport: Transport } + +interface That { + transport: Transport +} + +const commonQueryParams = ['error_trace', 'filter_path', 'human', 'pretty'] + +const acceptedParams: Record<string, { path: string[], body: string[], query: string[] }> = { + search_mvt: { + path: [ + 'index', + 'field', + 'zoom', + 'x', + 'y' + ], + body: [ + 'aggs', + 'buffer', + 'exact_bounds', + 'extent', + 'fields', + 'grid_agg', + 'grid_precision', + 'grid_type', + 'query', + 'runtime_mappings', + 'size', + 'sort', + 'track_total_hits', + 'with_labels' + ], + query: [ + 'exact_bounds', + 'extent', + 'grid_agg', + 'grid_precision', + 'grid_type', + 'size', + 'with_labels' + ] + } +} /** * Search a vector tile. Search a vector tile for geospatial values. Before using this API, you should be familiar with the Mapbox vector tile specification. The API returns results as a binary mapbox vector tile. Internally, Elasticsearch translates a vector tile search API request into a search containing: * A `geo_bounding_box` query on the `<field>`. The query uses the `<zoom>/<x>/<y>` tile as a bounding box. * A `geotile_grid` or `geohex_grid` aggregation on the `<field>`. The `grid_agg` parameter determines the aggregation type. The aggregation uses the `<zoom>/<x>/<y>` tile as a bounding box. * Optionally, a `geo_bounds` aggregation on the `<field>`. The search only includes this aggregation if the `exact_bounds` parameter is `true`. * If the optional parameter `with_labels` is `true`, the internal search will include a dynamic runtime field that calls the `getLabelPosition` function of the geometry doc value. This enables the generation of new point features containing suggested geometry labels, so that, for example, multi-polygons will have only one label. For example, Elasticsearch may translate a vector tile search API request with a `grid_agg` argument of `geotile` and an `exact_bounds` argument of `true` into the following search ``` GET my-index/_search { "size": 10000, "query": { "geo_bounding_box": { "my-geo-field": { "top_left": { "lat": -40.979898069620134, "lon": -45 }, "bottom_right": { "lat": -66.51326044311186, "lon": 0 } } } }, "aggregations": { "grid": { "geotile_grid": { "field": "my-geo-field", "precision": 11, "size": 65536, "bounds": { "top_left": { "lat": -40.979898069620134, "lon": -45 }, "bottom_right": { "lat": -66.51326044311186, "lon": 0 } } } }, "bounds": { "geo_bounds": { "field": "my-geo-field", "wrap_longitude": false } } } } ``` The API returns results as a binary Mapbox vector tile. Mapbox vector tiles are encoded as Google Protobufs (PBF). By default, the tile contains three layers: * A `hits` layer containing a feature for each `<field>` value matching the `geo_bounding_box` query. * An `aggs` layer containing a feature for each cell of the `geotile_grid` or `geohex_grid`. The layer only contains features for cells with matching data. * A meta layer containing: * A feature containing a bounding box. By default, this is the bounding box of the tile. * Value ranges for any sub-aggregations on the `geotile_grid` or `geohex_grid`. * Metadata for the search. The API only returns features that can display at its zoom level. For example, if a polygon feature has no area at its zoom level, the API omits it. The API returns errors as UTF-8 encoded JSON. IMPORTANT: You can specify several options for this API as either a query parameter or request body parameter. If you specify both parameters, the query parameter takes precedence. **Grid precision for geotile** For a `grid_agg` of `geotile`, you can use cells in the `aggs` layer as tiles for lower zoom levels. `grid_precision` represents the additional zoom levels available through these cells. The final precision is computed by as follows: `<zoom> + grid_precision`. For example, if `<zoom>` is 7 and `grid_precision` is 8, then the `geotile_grid` aggregation will use a precision of 15. The maximum final precision is 29. The `grid_precision` also determines the number of cells for the grid as follows: `(2^grid_precision) x (2^grid_precision)`. For example, a value of 8 divides the tile into a grid of 256 x 256 cells. The `aggs` layer only contains features for cells with matching data. **Grid precision for geohex** For a `grid_agg` of `geohex`, Elasticsearch uses `<zoom>` and `grid_precision` to calculate a final precision as follows: `<zoom> + grid_precision`. This precision determines the H3 resolution of the hexagonal cells produced by the `geohex` aggregation. The following table maps the H3 resolution for each precision. For example, if `<zoom>` is 3 and `grid_precision` is 3, the precision is 6. At a precision of 6, hexagonal cells have an H3 resolution of 2. If `<zoom>` is 3 and `grid_precision` is 4, the precision is 7. At a precision of 7, hexagonal cells have an H3 resolution of 3. | Precision | Unique tile bins | H3 resolution | Unique hex bins | Ratio | | --------- | ---------------- | ------------- | ----------------| ----- | | 1 | 4 | 0 | 122 | 30.5 | | 2 | 16 | 0 | 122 | 7.625 | | 3 | 64 | 1 | 842 | 13.15625 | | 4 | 256 | 1 | 842 | 3.2890625 | | 5 | 1024 | 2 | 5882 | 5.744140625 | | 6 | 4096 | 2 | 5882 | 1.436035156 | | 7 | 16384 | 3 | 41162 | 2.512329102 | | 8 | 65536 | 3 | 41162 | 0.6280822754 | | 9 | 262144 | 4 | 288122 | 1.099098206 | | 10 | 1048576 | 4 | 288122 | 0.2747745514 | | 11 | 4194304 | 5 | 2016842 | 0.4808526039 | | 12 | 16777216 | 6 | 14117882 | 0.8414913416 | | 13 | 67108864 | 6 | 14117882 | 0.2103728354 | | 14 | 268435456 | 7 | 98825162 | 0.3681524172 | | 15 | 1073741824 | 8 | 691776122 | 0.644266719 | | 16 | 4294967296 | 8 | 691776122 | 0.1610666797 | | 17 | 17179869184 | 9 | 4842432842 | 0.2818666889 | | 18 | 68719476736 | 10 | 33897029882 | 0.4932667053 | | 19 | 274877906944 | 11 | 237279209162 | 0.8632167343 | | 20 | 1099511627776 | 11 | 237279209162 | 0.2158041836 | | 21 | 4398046511104 | 12 | 1660954464122 | 0.3776573213 | | 22 | 17592186044416 | 13 | 11626681248842 | 0.6609003122 | | 23 | 70368744177664 | 13 | 11626681248842 | 0.165225078 | | 24 | 281474976710656 | 14 | 81386768741882 | 0.2891438866 | | 25 | 1125899906842620 | 15 | 569707381193162 | 0.5060018015 | | 26 | 4503599627370500 | 15 | 569707381193162 | 0.1265004504 | | 27 | 18014398509482000 | 15 | 569707381193162 | 0.03162511259 | | 28 | 72057594037927900 | 15 | 569707381193162 | 0.007906278149 | | 29 | 288230376151712000 | 15 | 569707381193162 | 0.001976569537 | Hexagonal cells don't align perfectly on a vector tile. Some cells may intersect more than one vector tile. To compute the H3 resolution for each precision, Elasticsearch compares the average density of hexagonal bins at each resolution with the average density of tile bins at each zoom level. Elasticsearch uses the H3 resolution that is closest to the corresponding geotile density. @@ -45,8 +87,12 @@ export default async function SearchMvtApi (this: That, params: T.SearchMvtReque export default async function SearchMvtApi (this: That, params: T.SearchMvtRequest, options?: TransportRequestOptionsWithMeta): Promise<TransportResult<T.SearchMvtResponse, unknown>> export default async function SearchMvtApi (this: That, params: T.SearchMvtRequest, options?: TransportRequestOptions): Promise<T.SearchMvtResponse> export default async function SearchMvtApi (this: That, params: T.SearchMvtRequest, options?: TransportRequestOptions): Promise<any> { - const acceptedPath: string[] = ['index', 'field', 'zoom', 'x', 'y'] - const acceptedBody: string[] = ['aggs', 'buffer', 'exact_bounds', 'extent', 'fields', 'grid_agg', 'grid_precision', 'grid_type', 'query', 'runtime_mappings', 'size', 'sort', 'track_total_hits', 'with_labels'] + const { + path: acceptedPath, + body: acceptedBody, + query: acceptedQuery + } = acceptedParams.search_mvt + const userQuery = params?.querystring const querystring: Record<string, any> = userQuery != null ? { ...userQuery } : {} @@ -68,8 +114,14 @@ export default async function SearchMvtApi (this: That, params: T.SearchMvtReque } else if (acceptedPath.includes(key)) { continue } else if (key !== 'body' && key !== 'querystring') { - // @ts-expect-error - querystring[key] = params[key] + if (acceptedQuery.includes(key) || commonQueryParams.includes(key)) { + // @ts-expect-error + querystring[key] = params[key] + } else { + body = body ?? {} + // @ts-expect-error + body[key] = params[key] + } } } diff --git a/src/api/api/search_shards.ts b/src/api/api/search_shards.ts index f2fff30a5..87a8ba52e 100644 --- a/src/api/api/search_shards.ts +++ b/src/api/api/search_shards.ts @@ -35,7 +35,28 @@ import { TransportResult } from '@elastic/transport' import * as T from '../types' -interface That { transport: Transport } + +interface That { + transport: Transport +} + +const acceptedParams: Record<string, { path: string[], body: string[], query: string[] }> = { + search_shards: { + path: [ + 'index' + ], + body: [], + query: [ + 'allow_no_indices', + 'expand_wildcards', + 'ignore_unavailable', + 'local', + 'master_timeout', + 'preference', + 'routing' + ] + } +} /** * Get the search shards. Get the indices and shards that a search request would be run against. This information can be useful for working out issues or planning optimizations with routing and shard preferences. When filtered aliases are used, the filter is returned as part of the `indices` section. If the Elasticsearch security features are enabled, you must have the `view_index_metadata` or `manage` index privilege for the target data stream, index, or alias. @@ -45,7 +66,10 @@ export default async function SearchShardsApi (this: That, params?: T.SearchShar export default async function SearchShardsApi (this: That, params?: T.SearchShardsRequest, options?: TransportRequestOptionsWithMeta): Promise<TransportResult<T.SearchShardsResponse, unknown>> export default async function SearchShardsApi (this: That, params?: T.SearchShardsRequest, options?: TransportRequestOptions): Promise<T.SearchShardsResponse> export default async function SearchShardsApi (this: That, params?: T.SearchShardsRequest, options?: TransportRequestOptions): Promise<any> { - const acceptedPath: string[] = ['index'] + const { + path: acceptedPath + } = acceptedParams.search_shards + const userQuery = params?.querystring const querystring: Record<string, any> = userQuery != null ? { ...userQuery } : {} diff --git a/src/api/api/search_template.ts b/src/api/api/search_template.ts index f63c77a45..0a47b171c 100644 --- a/src/api/api/search_template.ts +++ b/src/api/api/search_template.ts @@ -35,7 +35,42 @@ import { TransportResult } from '@elastic/transport' import * as T from '../types' -interface That { transport: Transport } + +interface That { + transport: Transport +} + +const commonQueryParams = ['error_trace', 'filter_path', 'human', 'pretty'] + +const acceptedParams: Record<string, { path: string[], body: string[], query: string[] }> = { + search_template: { + path: [ + 'index' + ], + body: [ + 'explain', + 'id', + 'params', + 'profile', + 'source' + ], + query: [ + 'allow_no_indices', + 'ccs_minimize_roundtrips', + 'expand_wildcards', + 'explain', + 'ignore_throttled', + 'ignore_unavailable', + 'preference', + 'profile', + 'routing', + 'scroll', + 'search_type', + 'rest_total_hits_as_int', + 'typed_keys' + ] + } +} /** * Run a search with a search template. @@ -45,8 +80,12 @@ export default async function SearchTemplateApi<TDocument = unknown> (this: That export default async function SearchTemplateApi<TDocument = unknown> (this: That, params?: T.SearchTemplateRequest, options?: TransportRequestOptionsWithMeta): Promise<TransportResult<T.SearchTemplateResponse<TDocument>, unknown>> export default async function SearchTemplateApi<TDocument = unknown> (this: That, params?: T.SearchTemplateRequest, options?: TransportRequestOptions): Promise<T.SearchTemplateResponse<TDocument>> export default async function SearchTemplateApi<TDocument = unknown> (this: That, params?: T.SearchTemplateRequest, options?: TransportRequestOptions): Promise<any> { - const acceptedPath: string[] = ['index'] - const acceptedBody: string[] = ['explain', 'id', 'params', 'profile', 'source'] + const { + path: acceptedPath, + body: acceptedBody, + query: acceptedQuery + } = acceptedParams.search_template + const userQuery = params?.querystring const querystring: Record<string, any> = userQuery != null ? { ...userQuery } : {} @@ -69,8 +108,14 @@ export default async function SearchTemplateApi<TDocument = unknown> (this: That } else if (acceptedPath.includes(key)) { continue } else if (key !== 'body' && key !== 'querystring') { - // @ts-expect-error - querystring[key] = params[key] + if (acceptedQuery.includes(key) || commonQueryParams.includes(key)) { + // @ts-expect-error + querystring[key] = params[key] + } else { + body = body ?? {} + // @ts-expect-error + body[key] = params[key] + } } } diff --git a/src/api/api/searchable_snapshots.ts b/src/api/api/searchable_snapshots.ts index 4c8af1dda..2d5f792ae 100644 --- a/src/api/api/searchable_snapshots.ts +++ b/src/api/api/searchable_snapshots.ts @@ -35,12 +35,67 @@ import { TransportResult } from '@elastic/transport' import * as T from '../types' -interface That { transport: Transport } + +interface That { + transport: Transport + acceptedParams: Record<string, { path: string[], body: string[], query: string[] }> +} + +const commonQueryParams = ['error_trace', 'filter_path', 'human', 'pretty'] export default class SearchableSnapshots { transport: Transport + acceptedParams: Record<string, { path: string[], body: string[], query: string[] }> constructor (transport: Transport) { this.transport = transport + this.acceptedParams = { + 'searchable_snapshots.cache_stats': { + path: [ + 'node_id' + ], + body: [], + query: [ + 'master_timeout' + ] + }, + 'searchable_snapshots.clear_cache': { + path: [ + 'index' + ], + body: [], + query: [ + 'expand_wildcards', + 'allow_no_indices', + 'ignore_unavailable' + ] + }, + 'searchable_snapshots.mount': { + path: [ + 'repository', + 'snapshot' + ], + body: [ + 'index', + 'renamed_index', + 'index_settings', + 'ignore_index_settings' + ], + query: [ + 'master_timeout', + 'wait_for_completion', + 'storage' + ] + }, + 'searchable_snapshots.stats': { + path: [ + 'index' + ], + body: [], + query: [ + 'level' + ] + } + } } /** @@ -51,7 +106,10 @@ export default class SearchableSnapshots { async cacheStats (this: That, params?: T.SearchableSnapshotsCacheStatsRequest, options?: TransportRequestOptionsWithMeta): Promise<TransportResult<T.SearchableSnapshotsCacheStatsResponse, unknown>> async cacheStats (this: That, params?: T.SearchableSnapshotsCacheStatsRequest, options?: TransportRequestOptions): Promise<T.SearchableSnapshotsCacheStatsResponse> async cacheStats (this: That, params?: T.SearchableSnapshotsCacheStatsRequest, options?: TransportRequestOptions): Promise<any> { - const acceptedPath: string[] = ['node_id'] + const { + path: acceptedPath + } = this.acceptedParams['searchable_snapshots.cache_stats'] + const userQuery = params?.querystring const querystring: Record<string, any> = userQuery != null ? { ...userQuery } : {} @@ -101,7 +159,10 @@ export default class SearchableSnapshots { async clearCache (this: That, params?: T.SearchableSnapshotsClearCacheRequest, options?: TransportRequestOptionsWithMeta): Promise<TransportResult<T.SearchableSnapshotsClearCacheResponse, unknown>> async clearCache (this: That, params?: T.SearchableSnapshotsClearCacheRequest, options?: TransportRequestOptions): Promise<T.SearchableSnapshotsClearCacheResponse> async clearCache (this: That, params?: T.SearchableSnapshotsClearCacheRequest, options?: TransportRequestOptions): Promise<any> { - const acceptedPath: string[] = ['index'] + const { + path: acceptedPath + } = this.acceptedParams['searchable_snapshots.clear_cache'] + const userQuery = params?.querystring const querystring: Record<string, any> = userQuery != null ? { ...userQuery } : {} @@ -151,8 +212,12 @@ export default class SearchableSnapshots { async mount (this: That, params: T.SearchableSnapshotsMountRequest, options?: TransportRequestOptionsWithMeta): Promise<TransportResult<T.SearchableSnapshotsMountResponse, unknown>> async mount (this: That, params: T.SearchableSnapshotsMountRequest, options?: TransportRequestOptions): Promise<T.SearchableSnapshotsMountResponse> async mount (this: That, params: T.SearchableSnapshotsMountRequest, options?: TransportRequestOptions): Promise<any> { - const acceptedPath: string[] = ['repository', 'snapshot'] - const acceptedBody: string[] = ['index', 'renamed_index', 'index_settings', 'ignore_index_settings'] + const { + path: acceptedPath, + body: acceptedBody, + query: acceptedQuery + } = this.acceptedParams['searchable_snapshots.mount'] + const userQuery = params?.querystring const querystring: Record<string, any> = userQuery != null ? { ...userQuery } : {} @@ -174,8 +239,14 @@ export default class SearchableSnapshots { } else if (acceptedPath.includes(key)) { continue } else if (key !== 'body' && key !== 'querystring') { - // @ts-expect-error - querystring[key] = params[key] + if (acceptedQuery.includes(key) || commonQueryParams.includes(key)) { + // @ts-expect-error + querystring[key] = params[key] + } else { + body = body ?? {} + // @ts-expect-error + body[key] = params[key] + } } } @@ -199,7 +270,10 @@ export default class SearchableSnapshots { async stats (this: That, params?: T.SearchableSnapshotsStatsRequest, options?: TransportRequestOptionsWithMeta): Promise<TransportResult<T.SearchableSnapshotsStatsResponse, unknown>> async stats (this: That, params?: T.SearchableSnapshotsStatsRequest, options?: TransportRequestOptions): Promise<T.SearchableSnapshotsStatsResponse> async stats (this: That, params?: T.SearchableSnapshotsStatsRequest, options?: TransportRequestOptions): Promise<any> { - const acceptedPath: string[] = ['index'] + const { + path: acceptedPath + } = this.acceptedParams['searchable_snapshots.stats'] + const userQuery = params?.querystring const querystring: Record<string, any> = userQuery != null ? { ...userQuery } : {} diff --git a/src/api/api/security.ts b/src/api/api/security.ts index 3484f5933..0f3021cc3 100644 --- a/src/api/api/security.ts +++ b/src/api/api/security.ts @@ -35,12 +35,648 @@ import { TransportResult } from '@elastic/transport' import * as T from '../types' -interface That { transport: Transport } + +interface That { + transport: Transport + acceptedParams: Record<string, { path: string[], body: string[], query: string[] }> +} + +const commonQueryParams = ['error_trace', 'filter_path', 'human', 'pretty'] export default class Security { transport: Transport + acceptedParams: Record<string, { path: string[], body: string[], query: string[] }> constructor (transport: Transport) { this.transport = transport + this.acceptedParams = { + 'security.activate_user_profile': { + path: [], + body: [ + 'access_token', + 'grant_type', + 'password', + 'username' + ], + query: [] + }, + 'security.authenticate': { + path: [], + body: [], + query: [] + }, + 'security.bulk_delete_role': { + path: [], + body: [ + 'names' + ], + query: [ + 'refresh' + ] + }, + 'security.bulk_put_role': { + path: [], + body: [ + 'roles' + ], + query: [ + 'refresh' + ] + }, + 'security.bulk_update_api_keys': { + path: [], + body: [ + 'expiration', + 'ids', + 'metadata', + 'role_descriptors' + ], + query: [] + }, + 'security.change_password': { + path: [ + 'username' + ], + body: [ + 'password', + 'password_hash' + ], + query: [ + 'refresh' + ] + }, + 'security.clear_api_key_cache': { + path: [ + 'ids' + ], + body: [], + query: [] + }, + 'security.clear_cached_privileges': { + path: [ + 'application' + ], + body: [], + query: [] + }, + 'security.clear_cached_realms': { + path: [ + 'realms' + ], + body: [], + query: [ + 'usernames' + ] + }, + 'security.clear_cached_roles': { + path: [ + 'name' + ], + body: [], + query: [] + }, + 'security.clear_cached_service_tokens': { + path: [ + 'namespace', + 'service', + 'name' + ], + body: [], + query: [] + }, + 'security.create_api_key': { + path: [], + body: [ + 'expiration', + 'name', + 'role_descriptors', + 'metadata' + ], + query: [ + 'refresh' + ] + }, + 'security.create_cross_cluster_api_key': { + path: [], + body: [ + 'access', + 'expiration', + 'metadata', + 'name' + ], + query: [] + }, + 'security.create_service_token': { + path: [ + 'namespace', + 'service', + 'name' + ], + body: [], + query: [ + 'refresh' + ] + }, + 'security.delegate_pki': { + path: [], + body: [ + 'x509_certificate_chain' + ], + query: [] + }, + 'security.delete_privileges': { + path: [ + 'application', + 'name' + ], + body: [], + query: [ + 'refresh' + ] + }, + 'security.delete_role': { + path: [ + 'name' + ], + body: [], + query: [ + 'refresh' + ] + }, + 'security.delete_role_mapping': { + path: [ + 'name' + ], + body: [], + query: [ + 'refresh' + ] + }, + 'security.delete_service_token': { + path: [ + 'namespace', + 'service', + 'name' + ], + body: [], + query: [ + 'refresh' + ] + }, + 'security.delete_user': { + path: [ + 'username' + ], + body: [], + query: [ + 'refresh' + ] + }, + 'security.disable_user': { + path: [ + 'username' + ], + body: [], + query: [ + 'refresh' + ] + }, + 'security.disable_user_profile': { + path: [ + 'uid' + ], + body: [], + query: [ + 'refresh' + ] + }, + 'security.enable_user': { + path: [ + 'username' + ], + body: [], + query: [ + 'refresh' + ] + }, + 'security.enable_user_profile': { + path: [ + 'uid' + ], + body: [], + query: [ + 'refresh' + ] + }, + 'security.enroll_kibana': { + path: [], + body: [], + query: [] + }, + 'security.enroll_node': { + path: [], + body: [], + query: [] + }, + 'security.get_api_key': { + path: [], + body: [], + query: [ + 'id', + 'name', + 'owner', + 'realm_name', + 'username', + 'with_limited_by', + 'active_only', + 'with_profile_uid' + ] + }, + 'security.get_builtin_privileges': { + path: [], + body: [], + query: [] + }, + 'security.get_privileges': { + path: [ + 'application', + 'name' + ], + body: [], + query: [] + }, + 'security.get_role': { + path: [ + 'name' + ], + body: [], + query: [] + }, + 'security.get_role_mapping': { + path: [ + 'name' + ], + body: [], + query: [] + }, + 'security.get_service_accounts': { + path: [ + 'namespace', + 'service' + ], + body: [], + query: [] + }, + 'security.get_service_credentials': { + path: [ + 'namespace', + 'service' + ], + body: [], + query: [] + }, + 'security.get_settings': { + path: [], + body: [], + query: [ + 'master_timeout' + ] + }, + 'security.get_token': { + path: [], + body: [ + 'grant_type', + 'scope', + 'password', + 'kerberos_ticket', + 'refresh_token', + 'username' + ], + query: [] + }, + 'security.get_user': { + path: [ + 'username' + ], + body: [], + query: [ + 'with_profile_uid' + ] + }, + 'security.get_user_privileges': { + path: [], + body: [], + query: [ + 'application', + 'priviledge', + 'username' + ] + }, + 'security.get_user_profile': { + path: [ + 'uid' + ], + body: [], + query: [ + 'data' + ] + }, + 'security.grant_api_key': { + path: [], + body: [ + 'api_key', + 'grant_type', + 'access_token', + 'username', + 'password', + 'run_as' + ], + query: [] + }, + 'security.has_privileges': { + path: [ + 'user' + ], + body: [ + 'application', + 'cluster', + 'index' + ], + query: [] + }, + 'security.has_privileges_user_profile': { + path: [], + body: [ + 'uids', + 'privileges' + ], + query: [] + }, + 'security.invalidate_api_key': { + path: [], + body: [ + 'id', + 'ids', + 'name', + 'owner', + 'realm_name', + 'username' + ], + query: [] + }, + 'security.invalidate_token': { + path: [], + body: [ + 'token', + 'refresh_token', + 'realm_name', + 'username' + ], + query: [] + }, + 'security.oidc_authenticate': { + path: [], + body: [ + 'nonce', + 'realm', + 'redirect_uri', + 'state' + ], + query: [] + }, + 'security.oidc_logout': { + path: [], + body: [ + 'access_token', + 'refresh_token' + ], + query: [] + }, + 'security.oidc_prepare_authentication': { + path: [], + body: [ + 'iss', + 'login_hint', + 'nonce', + 'realm', + 'state' + ], + query: [] + }, + 'security.put_privileges': { + path: [], + body: [ + 'privileges' + ], + query: [ + 'refresh' + ] + }, + 'security.put_role': { + path: [ + 'name' + ], + body: [ + 'applications', + 'cluster', + 'global', + 'indices', + 'remote_indices', + 'remote_cluster', + 'metadata', + 'run_as', + 'description', + 'transient_metadata' + ], + query: [ + 'refresh' + ] + }, + 'security.put_role_mapping': { + path: [ + 'name' + ], + body: [ + 'enabled', + 'metadata', + 'roles', + 'role_templates', + 'rules', + 'run_as' + ], + query: [ + 'refresh' + ] + }, + 'security.put_user': { + path: [], + body: [ + 'username', + 'email', + 'full_name', + 'metadata', + 'password', + 'password_hash', + 'roles', + 'enabled' + ], + query: [ + 'refresh' + ] + }, + 'security.query_api_keys': { + path: [], + body: [ + 'aggregations', + 'aggs', + 'query', + 'from', + 'sort', + 'size', + 'search_after' + ], + query: [ + 'with_limited_by', + 'with_profile_uid', + 'typed_keys' + ] + }, + 'security.query_role': { + path: [], + body: [ + 'query', + 'from', + 'sort', + 'size', + 'search_after' + ], + query: [] + }, + 'security.query_user': { + path: [], + body: [ + 'query', + 'from', + 'sort', + 'size', + 'search_after' + ], + query: [ + 'with_profile_uid' + ] + }, + 'security.saml_authenticate': { + path: [], + body: [ + 'content', + 'ids', + 'realm' + ], + query: [] + }, + 'security.saml_complete_logout': { + path: [], + body: [ + 'realm', + 'ids', + 'query_string', + 'content' + ], + query: [] + }, + 'security.saml_invalidate': { + path: [], + body: [ + 'acs', + 'query_string', + 'realm' + ], + query: [] + }, + 'security.saml_logout': { + path: [], + body: [ + 'token', + 'refresh_token' + ], + query: [] + }, + 'security.saml_prepare_authentication': { + path: [], + body: [ + 'acs', + 'realm', + 'relay_state' + ], + query: [] + }, + 'security.saml_service_provider_metadata': { + path: [ + 'realm_name' + ], + body: [], + query: [] + }, + 'security.suggest_user_profiles': { + path: [], + body: [ + 'name', + 'size', + 'data', + 'hint' + ], + query: [ + 'data' + ] + }, + 'security.update_api_key': { + path: [ + 'id' + ], + body: [ + 'role_descriptors', + 'metadata', + 'expiration' + ], + query: [] + }, + 'security.update_cross_cluster_api_key': { + path: [ + 'id' + ], + body: [ + 'access', + 'expiration', + 'metadata' + ], + query: [] + }, + 'security.update_settings': { + path: [], + body: [ + 'security', + 'security-profile', + 'security-tokens' + ], + query: [ + 'master_timeout', + 'timeout' + ] + }, + 'security.update_user_profile_data': { + path: [ + 'uid' + ], + body: [ + 'labels', + 'data' + ], + query: [ + 'if_seq_no', + 'if_primary_term', + 'refresh' + ] + } + } } /** @@ -51,8 +687,12 @@ export default class Security { async activateUserProfile (this: That, params: T.SecurityActivateUserProfileRequest, options?: TransportRequestOptionsWithMeta): Promise<TransportResult<T.SecurityActivateUserProfileResponse, unknown>> async activateUserProfile (this: That, params: T.SecurityActivateUserProfileRequest, options?: TransportRequestOptions): Promise<T.SecurityActivateUserProfileResponse> async activateUserProfile (this: That, params: T.SecurityActivateUserProfileRequest, options?: TransportRequestOptions): Promise<any> { - const acceptedPath: string[] = [] - const acceptedBody: string[] = ['access_token', 'grant_type', 'password', 'username'] + const { + path: acceptedPath, + body: acceptedBody, + query: acceptedQuery + } = this.acceptedParams['security.activate_user_profile'] + const userQuery = params?.querystring const querystring: Record<string, any> = userQuery != null ? { ...userQuery } : {} @@ -74,8 +714,14 @@ export default class Security { } else if (acceptedPath.includes(key)) { continue } else if (key !== 'body' && key !== 'querystring') { - // @ts-expect-error - querystring[key] = params[key] + if (acceptedQuery.includes(key) || commonQueryParams.includes(key)) { + // @ts-expect-error + querystring[key] = params[key] + } else { + body = body ?? {} + // @ts-expect-error + body[key] = params[key] + } } } @@ -95,7 +741,10 @@ export default class Security { async authenticate (this: That, params?: T.SecurityAuthenticateRequest, options?: TransportRequestOptionsWithMeta): Promise<TransportResult<T.SecurityAuthenticateResponse, unknown>> async authenticate (this: That, params?: T.SecurityAuthenticateRequest, options?: TransportRequestOptions): Promise<T.SecurityAuthenticateResponse> async authenticate (this: That, params?: T.SecurityAuthenticateRequest, options?: TransportRequestOptions): Promise<any> { - const acceptedPath: string[] = [] + const { + path: acceptedPath + } = this.acceptedParams['security.authenticate'] + const userQuery = params?.querystring const querystring: Record<string, any> = userQuery != null ? { ...userQuery } : {} @@ -135,8 +784,12 @@ export default class Security { async bulkDeleteRole (this: That, params: T.SecurityBulkDeleteRoleRequest, options?: TransportRequestOptionsWithMeta): Promise<TransportResult<T.SecurityBulkDeleteRoleResponse, unknown>> async bulkDeleteRole (this: That, params: T.SecurityBulkDeleteRoleRequest, options?: TransportRequestOptions): Promise<T.SecurityBulkDeleteRoleResponse> async bulkDeleteRole (this: That, params: T.SecurityBulkDeleteRoleRequest, options?: TransportRequestOptions): Promise<any> { - const acceptedPath: string[] = [] - const acceptedBody: string[] = ['names'] + const { + path: acceptedPath, + body: acceptedBody, + query: acceptedQuery + } = this.acceptedParams['security.bulk_delete_role'] + const userQuery = params?.querystring const querystring: Record<string, any> = userQuery != null ? { ...userQuery } : {} @@ -158,8 +811,14 @@ export default class Security { } else if (acceptedPath.includes(key)) { continue } else if (key !== 'body' && key !== 'querystring') { - // @ts-expect-error - querystring[key] = params[key] + if (acceptedQuery.includes(key) || commonQueryParams.includes(key)) { + // @ts-expect-error + querystring[key] = params[key] + } else { + body = body ?? {} + // @ts-expect-error + body[key] = params[key] + } } } @@ -179,8 +838,12 @@ export default class Security { async bulkPutRole (this: That, params: T.SecurityBulkPutRoleRequest, options?: TransportRequestOptionsWithMeta): Promise<TransportResult<T.SecurityBulkPutRoleResponse, unknown>> async bulkPutRole (this: That, params: T.SecurityBulkPutRoleRequest, options?: TransportRequestOptions): Promise<T.SecurityBulkPutRoleResponse> async bulkPutRole (this: That, params: T.SecurityBulkPutRoleRequest, options?: TransportRequestOptions): Promise<any> { - const acceptedPath: string[] = [] - const acceptedBody: string[] = ['roles'] + const { + path: acceptedPath, + body: acceptedBody, + query: acceptedQuery + } = this.acceptedParams['security.bulk_put_role'] + const userQuery = params?.querystring const querystring: Record<string, any> = userQuery != null ? { ...userQuery } : {} @@ -202,8 +865,14 @@ export default class Security { } else if (acceptedPath.includes(key)) { continue } else if (key !== 'body' && key !== 'querystring') { - // @ts-expect-error - querystring[key] = params[key] + if (acceptedQuery.includes(key) || commonQueryParams.includes(key)) { + // @ts-expect-error + querystring[key] = params[key] + } else { + body = body ?? {} + // @ts-expect-error + body[key] = params[key] + } } } @@ -223,8 +892,12 @@ export default class Security { async bulkUpdateApiKeys (this: That, params: T.SecurityBulkUpdateApiKeysRequest, options?: TransportRequestOptionsWithMeta): Promise<TransportResult<T.SecurityBulkUpdateApiKeysResponse, unknown>> async bulkUpdateApiKeys (this: That, params: T.SecurityBulkUpdateApiKeysRequest, options?: TransportRequestOptions): Promise<T.SecurityBulkUpdateApiKeysResponse> async bulkUpdateApiKeys (this: That, params: T.SecurityBulkUpdateApiKeysRequest, options?: TransportRequestOptions): Promise<any> { - const acceptedPath: string[] = [] - const acceptedBody: string[] = ['expiration', 'ids', 'metadata', 'role_descriptors'] + const { + path: acceptedPath, + body: acceptedBody, + query: acceptedQuery + } = this.acceptedParams['security.bulk_update_api_keys'] + const userQuery = params?.querystring const querystring: Record<string, any> = userQuery != null ? { ...userQuery } : {} @@ -246,8 +919,14 @@ export default class Security { } else if (acceptedPath.includes(key)) { continue } else if (key !== 'body' && key !== 'querystring') { - // @ts-expect-error - querystring[key] = params[key] + if (acceptedQuery.includes(key) || commonQueryParams.includes(key)) { + // @ts-expect-error + querystring[key] = params[key] + } else { + body = body ?? {} + // @ts-expect-error + body[key] = params[key] + } } } @@ -267,8 +946,12 @@ export default class Security { async changePassword (this: That, params?: T.SecurityChangePasswordRequest, options?: TransportRequestOptionsWithMeta): Promise<TransportResult<T.SecurityChangePasswordResponse, unknown>> async changePassword (this: That, params?: T.SecurityChangePasswordRequest, options?: TransportRequestOptions): Promise<T.SecurityChangePasswordResponse> async changePassword (this: That, params?: T.SecurityChangePasswordRequest, options?: TransportRequestOptions): Promise<any> { - const acceptedPath: string[] = ['username'] - const acceptedBody: string[] = ['password', 'password_hash'] + const { + path: acceptedPath, + body: acceptedBody, + query: acceptedQuery + } = this.acceptedParams['security.change_password'] + const userQuery = params?.querystring const querystring: Record<string, any> = userQuery != null ? { ...userQuery } : {} @@ -291,8 +974,14 @@ export default class Security { } else if (acceptedPath.includes(key)) { continue } else if (key !== 'body' && key !== 'querystring') { - // @ts-expect-error - querystring[key] = params[key] + if (acceptedQuery.includes(key) || commonQueryParams.includes(key)) { + // @ts-expect-error + querystring[key] = params[key] + } else { + body = body ?? {} + // @ts-expect-error + body[key] = params[key] + } } } @@ -322,7 +1011,10 @@ export default class Security { async clearApiKeyCache (this: That, params: T.SecurityClearApiKeyCacheRequest, options?: TransportRequestOptionsWithMeta): Promise<TransportResult<T.SecurityClearApiKeyCacheResponse, unknown>> async clearApiKeyCache (this: That, params: T.SecurityClearApiKeyCacheRequest, options?: TransportRequestOptions): Promise<T.SecurityClearApiKeyCacheResponse> async clearApiKeyCache (this: That, params: T.SecurityClearApiKeyCacheRequest, options?: TransportRequestOptions): Promise<any> { - const acceptedPath: string[] = ['ids'] + const { + path: acceptedPath + } = this.acceptedParams['security.clear_api_key_cache'] + const userQuery = params?.querystring const querystring: Record<string, any> = userQuery != null ? { ...userQuery } : {} @@ -364,7 +1056,10 @@ export default class Security { async clearCachedPrivileges (this: That, params: T.SecurityClearCachedPrivilegesRequest, options?: TransportRequestOptionsWithMeta): Promise<TransportResult<T.SecurityClearCachedPrivilegesResponse, unknown>> async clearCachedPrivileges (this: That, params: T.SecurityClearCachedPrivilegesRequest, options?: TransportRequestOptions): Promise<T.SecurityClearCachedPrivilegesResponse> async clearCachedPrivileges (this: That, params: T.SecurityClearCachedPrivilegesRequest, options?: TransportRequestOptions): Promise<any> { - const acceptedPath: string[] = ['application'] + const { + path: acceptedPath + } = this.acceptedParams['security.clear_cached_privileges'] + const userQuery = params?.querystring const querystring: Record<string, any> = userQuery != null ? { ...userQuery } : {} @@ -406,7 +1101,10 @@ export default class Security { async clearCachedRealms (this: That, params: T.SecurityClearCachedRealmsRequest, options?: TransportRequestOptionsWithMeta): Promise<TransportResult<T.SecurityClearCachedRealmsResponse, unknown>> async clearCachedRealms (this: That, params: T.SecurityClearCachedRealmsRequest, options?: TransportRequestOptions): Promise<T.SecurityClearCachedRealmsResponse> async clearCachedRealms (this: That, params: T.SecurityClearCachedRealmsRequest, options?: TransportRequestOptions): Promise<any> { - const acceptedPath: string[] = ['realms'] + const { + path: acceptedPath + } = this.acceptedParams['security.clear_cached_realms'] + const userQuery = params?.querystring const querystring: Record<string, any> = userQuery != null ? { ...userQuery } : {} @@ -448,7 +1146,10 @@ export default class Security { async clearCachedRoles (this: That, params: T.SecurityClearCachedRolesRequest, options?: TransportRequestOptionsWithMeta): Promise<TransportResult<T.SecurityClearCachedRolesResponse, unknown>> async clearCachedRoles (this: That, params: T.SecurityClearCachedRolesRequest, options?: TransportRequestOptions): Promise<T.SecurityClearCachedRolesResponse> async clearCachedRoles (this: That, params: T.SecurityClearCachedRolesRequest, options?: TransportRequestOptions): Promise<any> { - const acceptedPath: string[] = ['name'] + const { + path: acceptedPath + } = this.acceptedParams['security.clear_cached_roles'] + const userQuery = params?.querystring const querystring: Record<string, any> = userQuery != null ? { ...userQuery } : {} @@ -490,7 +1191,10 @@ export default class Security { async clearCachedServiceTokens (this: That, params: T.SecurityClearCachedServiceTokensRequest, options?: TransportRequestOptionsWithMeta): Promise<TransportResult<T.SecurityClearCachedServiceTokensResponse, unknown>> async clearCachedServiceTokens (this: That, params: T.SecurityClearCachedServiceTokensRequest, options?: TransportRequestOptions): Promise<T.SecurityClearCachedServiceTokensResponse> async clearCachedServiceTokens (this: That, params: T.SecurityClearCachedServiceTokensRequest, options?: TransportRequestOptions): Promise<any> { - const acceptedPath: string[] = ['namespace', 'service', 'name'] + const { + path: acceptedPath + } = this.acceptedParams['security.clear_cached_service_tokens'] + const userQuery = params?.querystring const querystring: Record<string, any> = userQuery != null ? { ...userQuery } : {} @@ -534,8 +1238,12 @@ export default class Security { async createApiKey (this: That, params?: T.SecurityCreateApiKeyRequest, options?: TransportRequestOptionsWithMeta): Promise<TransportResult<T.SecurityCreateApiKeyResponse, unknown>> async createApiKey (this: That, params?: T.SecurityCreateApiKeyRequest, options?: TransportRequestOptions): Promise<T.SecurityCreateApiKeyResponse> async createApiKey (this: That, params?: T.SecurityCreateApiKeyRequest, options?: TransportRequestOptions): Promise<any> { - const acceptedPath: string[] = [] - const acceptedBody: string[] = ['expiration', 'name', 'role_descriptors', 'metadata'] + const { + path: acceptedPath, + body: acceptedBody, + query: acceptedQuery + } = this.acceptedParams['security.create_api_key'] + const userQuery = params?.querystring const querystring: Record<string, any> = userQuery != null ? { ...userQuery } : {} @@ -558,8 +1266,14 @@ export default class Security { } else if (acceptedPath.includes(key)) { continue } else if (key !== 'body' && key !== 'querystring') { - // @ts-expect-error - querystring[key] = params[key] + if (acceptedQuery.includes(key) || commonQueryParams.includes(key)) { + // @ts-expect-error + querystring[key] = params[key] + } else { + body = body ?? {} + // @ts-expect-error + body[key] = params[key] + } } } @@ -579,8 +1293,12 @@ export default class Security { async createCrossClusterApiKey (this: That, params: T.SecurityCreateCrossClusterApiKeyRequest, options?: TransportRequestOptionsWithMeta): Promise<TransportResult<T.SecurityCreateCrossClusterApiKeyResponse, unknown>> async createCrossClusterApiKey (this: That, params: T.SecurityCreateCrossClusterApiKeyRequest, options?: TransportRequestOptions): Promise<T.SecurityCreateCrossClusterApiKeyResponse> async createCrossClusterApiKey (this: That, params: T.SecurityCreateCrossClusterApiKeyRequest, options?: TransportRequestOptions): Promise<any> { - const acceptedPath: string[] = [] - const acceptedBody: string[] = ['access', 'expiration', 'metadata', 'name'] + const { + path: acceptedPath, + body: acceptedBody, + query: acceptedQuery + } = this.acceptedParams['security.create_cross_cluster_api_key'] + const userQuery = params?.querystring const querystring: Record<string, any> = userQuery != null ? { ...userQuery } : {} @@ -602,8 +1320,14 @@ export default class Security { } else if (acceptedPath.includes(key)) { continue } else if (key !== 'body' && key !== 'querystring') { - // @ts-expect-error - querystring[key] = params[key] + if (acceptedQuery.includes(key) || commonQueryParams.includes(key)) { + // @ts-expect-error + querystring[key] = params[key] + } else { + body = body ?? {} + // @ts-expect-error + body[key] = params[key] + } } } @@ -623,7 +1347,10 @@ export default class Security { async createServiceToken (this: That, params: T.SecurityCreateServiceTokenRequest, options?: TransportRequestOptionsWithMeta): Promise<TransportResult<T.SecurityCreateServiceTokenResponse, unknown>> async createServiceToken (this: That, params: T.SecurityCreateServiceTokenRequest, options?: TransportRequestOptions): Promise<T.SecurityCreateServiceTokenResponse> async createServiceToken (this: That, params: T.SecurityCreateServiceTokenRequest, options?: TransportRequestOptions): Promise<any> { - const acceptedPath: string[] = ['namespace', 'service', 'name'] + const { + path: acceptedPath + } = this.acceptedParams['security.create_service_token'] + const userQuery = params?.querystring const querystring: Record<string, any> = userQuery != null ? { ...userQuery } : {} @@ -674,8 +1401,12 @@ export default class Security { async delegatePki (this: That, params: T.SecurityDelegatePkiRequest, options?: TransportRequestOptionsWithMeta): Promise<TransportResult<T.SecurityDelegatePkiResponse, unknown>> async delegatePki (this: That, params: T.SecurityDelegatePkiRequest, options?: TransportRequestOptions): Promise<T.SecurityDelegatePkiResponse> async delegatePki (this: That, params: T.SecurityDelegatePkiRequest, options?: TransportRequestOptions): Promise<any> { - const acceptedPath: string[] = [] - const acceptedBody: string[] = ['x509_certificate_chain'] + const { + path: acceptedPath, + body: acceptedBody, + query: acceptedQuery + } = this.acceptedParams['security.delegate_pki'] + const userQuery = params?.querystring const querystring: Record<string, any> = userQuery != null ? { ...userQuery } : {} @@ -697,8 +1428,14 @@ export default class Security { } else if (acceptedPath.includes(key)) { continue } else if (key !== 'body' && key !== 'querystring') { - // @ts-expect-error - querystring[key] = params[key] + if (acceptedQuery.includes(key) || commonQueryParams.includes(key)) { + // @ts-expect-error + querystring[key] = params[key] + } else { + body = body ?? {} + // @ts-expect-error + body[key] = params[key] + } } } @@ -718,7 +1455,10 @@ export default class Security { async deletePrivileges (this: That, params: T.SecurityDeletePrivilegesRequest, options?: TransportRequestOptionsWithMeta): Promise<TransportResult<T.SecurityDeletePrivilegesResponse, unknown>> async deletePrivileges (this: That, params: T.SecurityDeletePrivilegesRequest, options?: TransportRequestOptions): Promise<T.SecurityDeletePrivilegesResponse> async deletePrivileges (this: That, params: T.SecurityDeletePrivilegesRequest, options?: TransportRequestOptions): Promise<any> { - const acceptedPath: string[] = ['application', 'name'] + const { + path: acceptedPath + } = this.acceptedParams['security.delete_privileges'] + const userQuery = params?.querystring const querystring: Record<string, any> = userQuery != null ? { ...userQuery } : {} @@ -761,7 +1501,10 @@ export default class Security { async deleteRole (this: That, params: T.SecurityDeleteRoleRequest, options?: TransportRequestOptionsWithMeta): Promise<TransportResult<T.SecurityDeleteRoleResponse, unknown>> async deleteRole (this: That, params: T.SecurityDeleteRoleRequest, options?: TransportRequestOptions): Promise<T.SecurityDeleteRoleResponse> async deleteRole (this: That, params: T.SecurityDeleteRoleRequest, options?: TransportRequestOptions): Promise<any> { - const acceptedPath: string[] = ['name'] + const { + path: acceptedPath + } = this.acceptedParams['security.delete_role'] + const userQuery = params?.querystring const querystring: Record<string, any> = userQuery != null ? { ...userQuery } : {} @@ -803,7 +1546,10 @@ export default class Security { async deleteRoleMapping (this: That, params: T.SecurityDeleteRoleMappingRequest, options?: TransportRequestOptionsWithMeta): Promise<TransportResult<T.SecurityDeleteRoleMappingResponse, unknown>> async deleteRoleMapping (this: That, params: T.SecurityDeleteRoleMappingRequest, options?: TransportRequestOptions): Promise<T.SecurityDeleteRoleMappingResponse> async deleteRoleMapping (this: That, params: T.SecurityDeleteRoleMappingRequest, options?: TransportRequestOptions): Promise<any> { - const acceptedPath: string[] = ['name'] + const { + path: acceptedPath + } = this.acceptedParams['security.delete_role_mapping'] + const userQuery = params?.querystring const querystring: Record<string, any> = userQuery != null ? { ...userQuery } : {} @@ -845,7 +1591,10 @@ export default class Security { async deleteServiceToken (this: That, params: T.SecurityDeleteServiceTokenRequest, options?: TransportRequestOptionsWithMeta): Promise<TransportResult<T.SecurityDeleteServiceTokenResponse, unknown>> async deleteServiceToken (this: That, params: T.SecurityDeleteServiceTokenRequest, options?: TransportRequestOptions): Promise<T.SecurityDeleteServiceTokenResponse> async deleteServiceToken (this: That, params: T.SecurityDeleteServiceTokenRequest, options?: TransportRequestOptions): Promise<any> { - const acceptedPath: string[] = ['namespace', 'service', 'name'] + const { + path: acceptedPath + } = this.acceptedParams['security.delete_service_token'] + const userQuery = params?.querystring const querystring: Record<string, any> = userQuery != null ? { ...userQuery } : {} @@ -889,7 +1638,10 @@ export default class Security { async deleteUser (this: That, params: T.SecurityDeleteUserRequest, options?: TransportRequestOptionsWithMeta): Promise<TransportResult<T.SecurityDeleteUserResponse, unknown>> async deleteUser (this: That, params: T.SecurityDeleteUserRequest, options?: TransportRequestOptions): Promise<T.SecurityDeleteUserResponse> async deleteUser (this: That, params: T.SecurityDeleteUserRequest, options?: TransportRequestOptions): Promise<any> { - const acceptedPath: string[] = ['username'] + const { + path: acceptedPath + } = this.acceptedParams['security.delete_user'] + const userQuery = params?.querystring const querystring: Record<string, any> = userQuery != null ? { ...userQuery } : {} @@ -931,7 +1683,10 @@ export default class Security { async disableUser (this: That, params: T.SecurityDisableUserRequest, options?: TransportRequestOptionsWithMeta): Promise<TransportResult<T.SecurityDisableUserResponse, unknown>> async disableUser (this: That, params: T.SecurityDisableUserRequest, options?: TransportRequestOptions): Promise<T.SecurityDisableUserResponse> async disableUser (this: That, params: T.SecurityDisableUserRequest, options?: TransportRequestOptions): Promise<any> { - const acceptedPath: string[] = ['username'] + const { + path: acceptedPath + } = this.acceptedParams['security.disable_user'] + const userQuery = params?.querystring const querystring: Record<string, any> = userQuery != null ? { ...userQuery } : {} @@ -973,7 +1728,10 @@ export default class Security { async disableUserProfile (this: That, params: T.SecurityDisableUserProfileRequest, options?: TransportRequestOptionsWithMeta): Promise<TransportResult<T.SecurityDisableUserProfileResponse, unknown>> async disableUserProfile (this: That, params: T.SecurityDisableUserProfileRequest, options?: TransportRequestOptions): Promise<T.SecurityDisableUserProfileResponse> async disableUserProfile (this: That, params: T.SecurityDisableUserProfileRequest, options?: TransportRequestOptions): Promise<any> { - const acceptedPath: string[] = ['uid'] + const { + path: acceptedPath + } = this.acceptedParams['security.disable_user_profile'] + const userQuery = params?.querystring const querystring: Record<string, any> = userQuery != null ? { ...userQuery } : {} @@ -1015,7 +1773,10 @@ export default class Security { async enableUser (this: That, params: T.SecurityEnableUserRequest, options?: TransportRequestOptionsWithMeta): Promise<TransportResult<T.SecurityEnableUserResponse, unknown>> async enableUser (this: That, params: T.SecurityEnableUserRequest, options?: TransportRequestOptions): Promise<T.SecurityEnableUserResponse> async enableUser (this: That, params: T.SecurityEnableUserRequest, options?: TransportRequestOptions): Promise<any> { - const acceptedPath: string[] = ['username'] + const { + path: acceptedPath + } = this.acceptedParams['security.enable_user'] + const userQuery = params?.querystring const querystring: Record<string, any> = userQuery != null ? { ...userQuery } : {} @@ -1057,7 +1818,10 @@ export default class Security { async enableUserProfile (this: That, params: T.SecurityEnableUserProfileRequest, options?: TransportRequestOptionsWithMeta): Promise<TransportResult<T.SecurityEnableUserProfileResponse, unknown>> async enableUserProfile (this: That, params: T.SecurityEnableUserProfileRequest, options?: TransportRequestOptions): Promise<T.SecurityEnableUserProfileResponse> async enableUserProfile (this: That, params: T.SecurityEnableUserProfileRequest, options?: TransportRequestOptions): Promise<any> { - const acceptedPath: string[] = ['uid'] + const { + path: acceptedPath + } = this.acceptedParams['security.enable_user_profile'] + const userQuery = params?.querystring const querystring: Record<string, any> = userQuery != null ? { ...userQuery } : {} @@ -1099,7 +1863,10 @@ export default class Security { async enrollKibana (this: That, params?: T.SecurityEnrollKibanaRequest, options?: TransportRequestOptionsWithMeta): Promise<TransportResult<T.SecurityEnrollKibanaResponse, unknown>> async enrollKibana (this: That, params?: T.SecurityEnrollKibanaRequest, options?: TransportRequestOptions): Promise<T.SecurityEnrollKibanaResponse> async enrollKibana (this: That, params?: T.SecurityEnrollKibanaRequest, options?: TransportRequestOptions): Promise<any> { - const acceptedPath: string[] = [] + const { + path: acceptedPath + } = this.acceptedParams['security.enroll_kibana'] + const userQuery = params?.querystring const querystring: Record<string, any> = userQuery != null ? { ...userQuery } : {} @@ -1139,7 +1906,10 @@ export default class Security { async enrollNode (this: That, params?: T.SecurityEnrollNodeRequest, options?: TransportRequestOptionsWithMeta): Promise<TransportResult<T.SecurityEnrollNodeResponse, unknown>> async enrollNode (this: That, params?: T.SecurityEnrollNodeRequest, options?: TransportRequestOptions): Promise<T.SecurityEnrollNodeResponse> async enrollNode (this: That, params?: T.SecurityEnrollNodeRequest, options?: TransportRequestOptions): Promise<any> { - const acceptedPath: string[] = [] + const { + path: acceptedPath + } = this.acceptedParams['security.enroll_node'] + const userQuery = params?.querystring const querystring: Record<string, any> = userQuery != null ? { ...userQuery } : {} @@ -1179,7 +1949,10 @@ export default class Security { async getApiKey (this: That, params?: T.SecurityGetApiKeyRequest, options?: TransportRequestOptionsWithMeta): Promise<TransportResult<T.SecurityGetApiKeyResponse, unknown>> async getApiKey (this: That, params?: T.SecurityGetApiKeyRequest, options?: TransportRequestOptions): Promise<T.SecurityGetApiKeyResponse> async getApiKey (this: That, params?: T.SecurityGetApiKeyRequest, options?: TransportRequestOptions): Promise<any> { - const acceptedPath: string[] = [] + const { + path: acceptedPath + } = this.acceptedParams['security.get_api_key'] + const userQuery = params?.querystring const querystring: Record<string, any> = userQuery != null ? { ...userQuery } : {} @@ -1219,7 +1992,10 @@ export default class Security { async getBuiltinPrivileges (this: That, params?: T.SecurityGetBuiltinPrivilegesRequest, options?: TransportRequestOptionsWithMeta): Promise<TransportResult<T.SecurityGetBuiltinPrivilegesResponse, unknown>> async getBuiltinPrivileges (this: That, params?: T.SecurityGetBuiltinPrivilegesRequest, options?: TransportRequestOptions): Promise<T.SecurityGetBuiltinPrivilegesResponse> async getBuiltinPrivileges (this: That, params?: T.SecurityGetBuiltinPrivilegesRequest, options?: TransportRequestOptions): Promise<any> { - const acceptedPath: string[] = [] + const { + path: acceptedPath + } = this.acceptedParams['security.get_builtin_privileges'] + const userQuery = params?.querystring const querystring: Record<string, any> = userQuery != null ? { ...userQuery } : {} @@ -1259,7 +2035,10 @@ export default class Security { async getPrivileges (this: That, params?: T.SecurityGetPrivilegesRequest, options?: TransportRequestOptionsWithMeta): Promise<TransportResult<T.SecurityGetPrivilegesResponse, unknown>> async getPrivileges (this: That, params?: T.SecurityGetPrivilegesRequest, options?: TransportRequestOptions): Promise<T.SecurityGetPrivilegesResponse> async getPrivileges (this: That, params?: T.SecurityGetPrivilegesRequest, options?: TransportRequestOptions): Promise<any> { - const acceptedPath: string[] = ['application', 'name'] + const { + path: acceptedPath + } = this.acceptedParams['security.get_privileges'] + const userQuery = params?.querystring const querystring: Record<string, any> = userQuery != null ? { ...userQuery } : {} @@ -1313,7 +2092,10 @@ export default class Security { async getRole (this: That, params?: T.SecurityGetRoleRequest, options?: TransportRequestOptionsWithMeta): Promise<TransportResult<T.SecurityGetRoleResponse, unknown>> async getRole (this: That, params?: T.SecurityGetRoleRequest, options?: TransportRequestOptions): Promise<T.SecurityGetRoleResponse> async getRole (this: That, params?: T.SecurityGetRoleRequest, options?: TransportRequestOptions): Promise<any> { - const acceptedPath: string[] = ['name'] + const { + path: acceptedPath + } = this.acceptedParams['security.get_role'] + const userQuery = params?.querystring const querystring: Record<string, any> = userQuery != null ? { ...userQuery } : {} @@ -1363,7 +2145,10 @@ export default class Security { async getRoleMapping (this: That, params?: T.SecurityGetRoleMappingRequest, options?: TransportRequestOptionsWithMeta): Promise<TransportResult<T.SecurityGetRoleMappingResponse, unknown>> async getRoleMapping (this: That, params?: T.SecurityGetRoleMappingRequest, options?: TransportRequestOptions): Promise<T.SecurityGetRoleMappingResponse> async getRoleMapping (this: That, params?: T.SecurityGetRoleMappingRequest, options?: TransportRequestOptions): Promise<any> { - const acceptedPath: string[] = ['name'] + const { + path: acceptedPath + } = this.acceptedParams['security.get_role_mapping'] + const userQuery = params?.querystring const querystring: Record<string, any> = userQuery != null ? { ...userQuery } : {} @@ -1413,7 +2198,10 @@ export default class Security { async getServiceAccounts (this: That, params?: T.SecurityGetServiceAccountsRequest, options?: TransportRequestOptionsWithMeta): Promise<TransportResult<T.SecurityGetServiceAccountsResponse, unknown>> async getServiceAccounts (this: That, params?: T.SecurityGetServiceAccountsRequest, options?: TransportRequestOptions): Promise<T.SecurityGetServiceAccountsResponse> async getServiceAccounts (this: That, params?: T.SecurityGetServiceAccountsRequest, options?: TransportRequestOptions): Promise<any> { - const acceptedPath: string[] = ['namespace', 'service'] + const { + path: acceptedPath + } = this.acceptedParams['security.get_service_accounts'] + const userQuery = params?.querystring const querystring: Record<string, any> = userQuery != null ? { ...userQuery } : {} @@ -1467,7 +2255,10 @@ export default class Security { async getServiceCredentials (this: That, params: T.SecurityGetServiceCredentialsRequest, options?: TransportRequestOptionsWithMeta): Promise<TransportResult<T.SecurityGetServiceCredentialsResponse, unknown>> async getServiceCredentials (this: That, params: T.SecurityGetServiceCredentialsRequest, options?: TransportRequestOptions): Promise<T.SecurityGetServiceCredentialsResponse> async getServiceCredentials (this: That, params: T.SecurityGetServiceCredentialsRequest, options?: TransportRequestOptions): Promise<any> { - const acceptedPath: string[] = ['namespace', 'service'] + const { + path: acceptedPath + } = this.acceptedParams['security.get_service_credentials'] + const userQuery = params?.querystring const querystring: Record<string, any> = userQuery != null ? { ...userQuery } : {} @@ -1510,7 +2301,10 @@ export default class Security { async getSettings (this: That, params?: T.SecurityGetSettingsRequest, options?: TransportRequestOptionsWithMeta): Promise<TransportResult<T.SecurityGetSettingsResponse, unknown>> async getSettings (this: That, params?: T.SecurityGetSettingsRequest, options?: TransportRequestOptions): Promise<T.SecurityGetSettingsResponse> async getSettings (this: That, params?: T.SecurityGetSettingsRequest, options?: TransportRequestOptions): Promise<any> { - const acceptedPath: string[] = [] + const { + path: acceptedPath + } = this.acceptedParams['security.get_settings'] + const userQuery = params?.querystring const querystring: Record<string, any> = userQuery != null ? { ...userQuery } : {} @@ -1550,8 +2344,12 @@ export default class Security { async getToken (this: That, params?: T.SecurityGetTokenRequest, options?: TransportRequestOptionsWithMeta): Promise<TransportResult<T.SecurityGetTokenResponse, unknown>> async getToken (this: That, params?: T.SecurityGetTokenRequest, options?: TransportRequestOptions): Promise<T.SecurityGetTokenResponse> async getToken (this: That, params?: T.SecurityGetTokenRequest, options?: TransportRequestOptions): Promise<any> { - const acceptedPath: string[] = [] - const acceptedBody: string[] = ['grant_type', 'scope', 'password', 'kerberos_ticket', 'refresh_token', 'username'] + const { + path: acceptedPath, + body: acceptedBody, + query: acceptedQuery + } = this.acceptedParams['security.get_token'] + const userQuery = params?.querystring const querystring: Record<string, any> = userQuery != null ? { ...userQuery } : {} @@ -1574,8 +2372,14 @@ export default class Security { } else if (acceptedPath.includes(key)) { continue } else if (key !== 'body' && key !== 'querystring') { - // @ts-expect-error - querystring[key] = params[key] + if (acceptedQuery.includes(key) || commonQueryParams.includes(key)) { + // @ts-expect-error + querystring[key] = params[key] + } else { + body = body ?? {} + // @ts-expect-error + body[key] = params[key] + } } } @@ -1595,7 +2399,10 @@ export default class Security { async getUser (this: That, params?: T.SecurityGetUserRequest, options?: TransportRequestOptionsWithMeta): Promise<TransportResult<T.SecurityGetUserResponse, unknown>> async getUser (this: That, params?: T.SecurityGetUserRequest, options?: TransportRequestOptions): Promise<T.SecurityGetUserResponse> async getUser (this: That, params?: T.SecurityGetUserRequest, options?: TransportRequestOptions): Promise<any> { - const acceptedPath: string[] = ['username'] + const { + path: acceptedPath + } = this.acceptedParams['security.get_user'] + const userQuery = params?.querystring const querystring: Record<string, any> = userQuery != null ? { ...userQuery } : {} @@ -1645,7 +2452,10 @@ export default class Security { async getUserPrivileges (this: That, params?: T.SecurityGetUserPrivilegesRequest, options?: TransportRequestOptionsWithMeta): Promise<TransportResult<T.SecurityGetUserPrivilegesResponse, unknown>> async getUserPrivileges (this: That, params?: T.SecurityGetUserPrivilegesRequest, options?: TransportRequestOptions): Promise<T.SecurityGetUserPrivilegesResponse> async getUserPrivileges (this: That, params?: T.SecurityGetUserPrivilegesRequest, options?: TransportRequestOptions): Promise<any> { - const acceptedPath: string[] = [] + const { + path: acceptedPath + } = this.acceptedParams['security.get_user_privileges'] + const userQuery = params?.querystring const querystring: Record<string, any> = userQuery != null ? { ...userQuery } : {} @@ -1685,7 +2495,10 @@ export default class Security { async getUserProfile (this: That, params: T.SecurityGetUserProfileRequest, options?: TransportRequestOptionsWithMeta): Promise<TransportResult<T.SecurityGetUserProfileResponse, unknown>> async getUserProfile (this: That, params: T.SecurityGetUserProfileRequest, options?: TransportRequestOptions): Promise<T.SecurityGetUserProfileResponse> async getUserProfile (this: That, params: T.SecurityGetUserProfileRequest, options?: TransportRequestOptions): Promise<any> { - const acceptedPath: string[] = ['uid'] + const { + path: acceptedPath + } = this.acceptedParams['security.get_user_profile'] + const userQuery = params?.querystring const querystring: Record<string, any> = userQuery != null ? { ...userQuery } : {} @@ -1727,8 +2540,12 @@ export default class Security { async grantApiKey (this: That, params: T.SecurityGrantApiKeyRequest, options?: TransportRequestOptionsWithMeta): Promise<TransportResult<T.SecurityGrantApiKeyResponse, unknown>> async grantApiKey (this: That, params: T.SecurityGrantApiKeyRequest, options?: TransportRequestOptions): Promise<T.SecurityGrantApiKeyResponse> async grantApiKey (this: That, params: T.SecurityGrantApiKeyRequest, options?: TransportRequestOptions): Promise<any> { - const acceptedPath: string[] = [] - const acceptedBody: string[] = ['api_key', 'grant_type', 'access_token', 'username', 'password', 'run_as'] + const { + path: acceptedPath, + body: acceptedBody, + query: acceptedQuery + } = this.acceptedParams['security.grant_api_key'] + const userQuery = params?.querystring const querystring: Record<string, any> = userQuery != null ? { ...userQuery } : {} @@ -1750,8 +2567,14 @@ export default class Security { } else if (acceptedPath.includes(key)) { continue } else if (key !== 'body' && key !== 'querystring') { - // @ts-expect-error - querystring[key] = params[key] + if (acceptedQuery.includes(key) || commonQueryParams.includes(key)) { + // @ts-expect-error + querystring[key] = params[key] + } else { + body = body ?? {} + // @ts-expect-error + body[key] = params[key] + } } } @@ -1771,8 +2594,12 @@ export default class Security { async hasPrivileges (this: That, params?: T.SecurityHasPrivilegesRequest, options?: TransportRequestOptionsWithMeta): Promise<TransportResult<T.SecurityHasPrivilegesResponse, unknown>> async hasPrivileges (this: That, params?: T.SecurityHasPrivilegesRequest, options?: TransportRequestOptions): Promise<T.SecurityHasPrivilegesResponse> async hasPrivileges (this: That, params?: T.SecurityHasPrivilegesRequest, options?: TransportRequestOptions): Promise<any> { - const acceptedPath: string[] = ['user'] - const acceptedBody: string[] = ['application', 'cluster', 'index'] + const { + path: acceptedPath, + body: acceptedBody, + query: acceptedQuery + } = this.acceptedParams['security.has_privileges'] + const userQuery = params?.querystring const querystring: Record<string, any> = userQuery != null ? { ...userQuery } : {} @@ -1795,8 +2622,14 @@ export default class Security { } else if (acceptedPath.includes(key)) { continue } else if (key !== 'body' && key !== 'querystring') { - // @ts-expect-error - querystring[key] = params[key] + if (acceptedQuery.includes(key) || commonQueryParams.includes(key)) { + // @ts-expect-error + querystring[key] = params[key] + } else { + body = body ?? {} + // @ts-expect-error + body[key] = params[key] + } } } @@ -1826,8 +2659,12 @@ export default class Security { async hasPrivilegesUserProfile (this: That, params: T.SecurityHasPrivilegesUserProfileRequest, options?: TransportRequestOptionsWithMeta): Promise<TransportResult<T.SecurityHasPrivilegesUserProfileResponse, unknown>> async hasPrivilegesUserProfile (this: That, params: T.SecurityHasPrivilegesUserProfileRequest, options?: TransportRequestOptions): Promise<T.SecurityHasPrivilegesUserProfileResponse> async hasPrivilegesUserProfile (this: That, params: T.SecurityHasPrivilegesUserProfileRequest, options?: TransportRequestOptions): Promise<any> { - const acceptedPath: string[] = [] - const acceptedBody: string[] = ['uids', 'privileges'] + const { + path: acceptedPath, + body: acceptedBody, + query: acceptedQuery + } = this.acceptedParams['security.has_privileges_user_profile'] + const userQuery = params?.querystring const querystring: Record<string, any> = userQuery != null ? { ...userQuery } : {} @@ -1849,8 +2686,14 @@ export default class Security { } else if (acceptedPath.includes(key)) { continue } else if (key !== 'body' && key !== 'querystring') { - // @ts-expect-error - querystring[key] = params[key] + if (acceptedQuery.includes(key) || commonQueryParams.includes(key)) { + // @ts-expect-error + querystring[key] = params[key] + } else { + body = body ?? {} + // @ts-expect-error + body[key] = params[key] + } } } @@ -1870,8 +2713,12 @@ export default class Security { async invalidateApiKey (this: That, params?: T.SecurityInvalidateApiKeyRequest, options?: TransportRequestOptionsWithMeta): Promise<TransportResult<T.SecurityInvalidateApiKeyResponse, unknown>> async invalidateApiKey (this: That, params?: T.SecurityInvalidateApiKeyRequest, options?: TransportRequestOptions): Promise<T.SecurityInvalidateApiKeyResponse> async invalidateApiKey (this: That, params?: T.SecurityInvalidateApiKeyRequest, options?: TransportRequestOptions): Promise<any> { - const acceptedPath: string[] = [] - const acceptedBody: string[] = ['id', 'ids', 'name', 'owner', 'realm_name', 'username'] + const { + path: acceptedPath, + body: acceptedBody, + query: acceptedQuery + } = this.acceptedParams['security.invalidate_api_key'] + const userQuery = params?.querystring const querystring: Record<string, any> = userQuery != null ? { ...userQuery } : {} @@ -1894,8 +2741,14 @@ export default class Security { } else if (acceptedPath.includes(key)) { continue } else if (key !== 'body' && key !== 'querystring') { - // @ts-expect-error - querystring[key] = params[key] + if (acceptedQuery.includes(key) || commonQueryParams.includes(key)) { + // @ts-expect-error + querystring[key] = params[key] + } else { + body = body ?? {} + // @ts-expect-error + body[key] = params[key] + } } } @@ -1915,8 +2768,12 @@ export default class Security { async invalidateToken (this: That, params?: T.SecurityInvalidateTokenRequest, options?: TransportRequestOptionsWithMeta): Promise<TransportResult<T.SecurityInvalidateTokenResponse, unknown>> async invalidateToken (this: That, params?: T.SecurityInvalidateTokenRequest, options?: TransportRequestOptions): Promise<T.SecurityInvalidateTokenResponse> async invalidateToken (this: That, params?: T.SecurityInvalidateTokenRequest, options?: TransportRequestOptions): Promise<any> { - const acceptedPath: string[] = [] - const acceptedBody: string[] = ['token', 'refresh_token', 'realm_name', 'username'] + const { + path: acceptedPath, + body: acceptedBody, + query: acceptedQuery + } = this.acceptedParams['security.invalidate_token'] + const userQuery = params?.querystring const querystring: Record<string, any> = userQuery != null ? { ...userQuery } : {} @@ -1939,8 +2796,14 @@ export default class Security { } else if (acceptedPath.includes(key)) { continue } else if (key !== 'body' && key !== 'querystring') { - // @ts-expect-error - querystring[key] = params[key] + if (acceptedQuery.includes(key) || commonQueryParams.includes(key)) { + // @ts-expect-error + querystring[key] = params[key] + } else { + body = body ?? {} + // @ts-expect-error + body[key] = params[key] + } } } @@ -1960,8 +2823,12 @@ export default class Security { async oidcAuthenticate (this: That, params: T.SecurityOidcAuthenticateRequest, options?: TransportRequestOptionsWithMeta): Promise<TransportResult<T.SecurityOidcAuthenticateResponse, unknown>> async oidcAuthenticate (this: That, params: T.SecurityOidcAuthenticateRequest, options?: TransportRequestOptions): Promise<T.SecurityOidcAuthenticateResponse> async oidcAuthenticate (this: That, params: T.SecurityOidcAuthenticateRequest, options?: TransportRequestOptions): Promise<any> { - const acceptedPath: string[] = [] - const acceptedBody: string[] = ['nonce', 'realm', 'redirect_uri', 'state'] + const { + path: acceptedPath, + body: acceptedBody, + query: acceptedQuery + } = this.acceptedParams['security.oidc_authenticate'] + const userQuery = params?.querystring const querystring: Record<string, any> = userQuery != null ? { ...userQuery } : {} @@ -1983,8 +2850,14 @@ export default class Security { } else if (acceptedPath.includes(key)) { continue } else if (key !== 'body' && key !== 'querystring') { - // @ts-expect-error - querystring[key] = params[key] + if (acceptedQuery.includes(key) || commonQueryParams.includes(key)) { + // @ts-expect-error + querystring[key] = params[key] + } else { + body = body ?? {} + // @ts-expect-error + body[key] = params[key] + } } } @@ -2004,8 +2877,12 @@ export default class Security { async oidcLogout (this: That, params: T.SecurityOidcLogoutRequest, options?: TransportRequestOptionsWithMeta): Promise<TransportResult<T.SecurityOidcLogoutResponse, unknown>> async oidcLogout (this: That, params: T.SecurityOidcLogoutRequest, options?: TransportRequestOptions): Promise<T.SecurityOidcLogoutResponse> async oidcLogout (this: That, params: T.SecurityOidcLogoutRequest, options?: TransportRequestOptions): Promise<any> { - const acceptedPath: string[] = [] - const acceptedBody: string[] = ['access_token', 'refresh_token'] + const { + path: acceptedPath, + body: acceptedBody, + query: acceptedQuery + } = this.acceptedParams['security.oidc_logout'] + const userQuery = params?.querystring const querystring: Record<string, any> = userQuery != null ? { ...userQuery } : {} @@ -2027,8 +2904,14 @@ export default class Security { } else if (acceptedPath.includes(key)) { continue } else if (key !== 'body' && key !== 'querystring') { - // @ts-expect-error - querystring[key] = params[key] + if (acceptedQuery.includes(key) || commonQueryParams.includes(key)) { + // @ts-expect-error + querystring[key] = params[key] + } else { + body = body ?? {} + // @ts-expect-error + body[key] = params[key] + } } } @@ -2048,8 +2931,12 @@ export default class Security { async oidcPrepareAuthentication (this: That, params?: T.SecurityOidcPrepareAuthenticationRequest, options?: TransportRequestOptionsWithMeta): Promise<TransportResult<T.SecurityOidcPrepareAuthenticationResponse, unknown>> async oidcPrepareAuthentication (this: That, params?: T.SecurityOidcPrepareAuthenticationRequest, options?: TransportRequestOptions): Promise<T.SecurityOidcPrepareAuthenticationResponse> async oidcPrepareAuthentication (this: That, params?: T.SecurityOidcPrepareAuthenticationRequest, options?: TransportRequestOptions): Promise<any> { - const acceptedPath: string[] = [] - const acceptedBody: string[] = ['iss', 'login_hint', 'nonce', 'realm', 'state'] + const { + path: acceptedPath, + body: acceptedBody, + query: acceptedQuery + } = this.acceptedParams['security.oidc_prepare_authentication'] + const userQuery = params?.querystring const querystring: Record<string, any> = userQuery != null ? { ...userQuery } : {} @@ -2072,8 +2959,14 @@ export default class Security { } else if (acceptedPath.includes(key)) { continue } else if (key !== 'body' && key !== 'querystring') { - // @ts-expect-error - querystring[key] = params[key] + if (acceptedQuery.includes(key) || commonQueryParams.includes(key)) { + // @ts-expect-error + querystring[key] = params[key] + } else { + body = body ?? {} + // @ts-expect-error + body[key] = params[key] + } } } @@ -2093,8 +2986,12 @@ export default class Security { async putPrivileges (this: That, params: T.SecurityPutPrivilegesRequest, options?: TransportRequestOptionsWithMeta): Promise<TransportResult<T.SecurityPutPrivilegesResponse, unknown>> async putPrivileges (this: That, params: T.SecurityPutPrivilegesRequest, options?: TransportRequestOptions): Promise<T.SecurityPutPrivilegesResponse> async putPrivileges (this: That, params: T.SecurityPutPrivilegesRequest, options?: TransportRequestOptions): Promise<any> { - const acceptedPath: string[] = [] - const acceptedBody: string[] = ['privileges'] + const { + path: acceptedPath, + body: acceptedBody, + query: acceptedQuery + } = this.acceptedParams['security.put_privileges'] + const userQuery = params?.querystring const querystring: Record<string, any> = userQuery != null ? { ...userQuery } : {} @@ -2106,8 +3003,14 @@ export default class Security { } else if (acceptedPath.includes(key)) { continue } else if (key !== 'body' && key !== 'querystring') { - // @ts-expect-error - querystring[key] = params[key] + if (acceptedQuery.includes(key) || commonQueryParams.includes(key)) { + // @ts-expect-error + querystring[key] = params[key] + } else { + body = body ?? {} + // @ts-expect-error + body[key] = params[key] + } } } @@ -2127,8 +3030,12 @@ export default class Security { async putRole (this: That, params: T.SecurityPutRoleRequest, options?: TransportRequestOptionsWithMeta): Promise<TransportResult<T.SecurityPutRoleResponse, unknown>> async putRole (this: That, params: T.SecurityPutRoleRequest, options?: TransportRequestOptions): Promise<T.SecurityPutRoleResponse> async putRole (this: That, params: T.SecurityPutRoleRequest, options?: TransportRequestOptions): Promise<any> { - const acceptedPath: string[] = ['name'] - const acceptedBody: string[] = ['applications', 'cluster', 'global', 'indices', 'remote_indices', 'remote_cluster', 'metadata', 'run_as', 'description', 'transient_metadata'] + const { + path: acceptedPath, + body: acceptedBody, + query: acceptedQuery + } = this.acceptedParams['security.put_role'] + const userQuery = params?.querystring const querystring: Record<string, any> = userQuery != null ? { ...userQuery } : {} @@ -2150,8 +3057,14 @@ export default class Security { } else if (acceptedPath.includes(key)) { continue } else if (key !== 'body' && key !== 'querystring') { - // @ts-expect-error - querystring[key] = params[key] + if (acceptedQuery.includes(key) || commonQueryParams.includes(key)) { + // @ts-expect-error + querystring[key] = params[key] + } else { + body = body ?? {} + // @ts-expect-error + body[key] = params[key] + } } } @@ -2174,8 +3087,12 @@ export default class Security { async putRoleMapping (this: That, params: T.SecurityPutRoleMappingRequest, options?: TransportRequestOptionsWithMeta): Promise<TransportResult<T.SecurityPutRoleMappingResponse, unknown>> async putRoleMapping (this: That, params: T.SecurityPutRoleMappingRequest, options?: TransportRequestOptions): Promise<T.SecurityPutRoleMappingResponse> async putRoleMapping (this: That, params: T.SecurityPutRoleMappingRequest, options?: TransportRequestOptions): Promise<any> { - const acceptedPath: string[] = ['name'] - const acceptedBody: string[] = ['enabled', 'metadata', 'roles', 'role_templates', 'rules', 'run_as'] + const { + path: acceptedPath, + body: acceptedBody, + query: acceptedQuery + } = this.acceptedParams['security.put_role_mapping'] + const userQuery = params?.querystring const querystring: Record<string, any> = userQuery != null ? { ...userQuery } : {} @@ -2197,8 +3114,14 @@ export default class Security { } else if (acceptedPath.includes(key)) { continue } else if (key !== 'body' && key !== 'querystring') { - // @ts-expect-error - querystring[key] = params[key] + if (acceptedQuery.includes(key) || commonQueryParams.includes(key)) { + // @ts-expect-error + querystring[key] = params[key] + } else { + body = body ?? {} + // @ts-expect-error + body[key] = params[key] + } } } @@ -2221,8 +3144,12 @@ export default class Security { async putUser (this: That, params: T.SecurityPutUserRequest, options?: TransportRequestOptionsWithMeta): Promise<TransportResult<T.SecurityPutUserResponse, unknown>> async putUser (this: That, params: T.SecurityPutUserRequest, options?: TransportRequestOptions): Promise<T.SecurityPutUserResponse> async putUser (this: That, params: T.SecurityPutUserRequest, options?: TransportRequestOptions): Promise<any> { - const acceptedPath: string[] = [] - const acceptedBody: string[] = ['username', 'email', 'full_name', 'metadata', 'password', 'password_hash', 'roles', 'enabled'] + const { + path: acceptedPath, + body: acceptedBody, + query: acceptedQuery + } = this.acceptedParams['security.put_user'] + const userQuery = params?.querystring const querystring: Record<string, any> = userQuery != null ? { ...userQuery } : {} @@ -2244,8 +3171,14 @@ export default class Security { } else if (acceptedPath.includes(key)) { continue } else if (key !== 'body' && key !== 'querystring') { - // @ts-expect-error - querystring[key] = params[key] + if (acceptedQuery.includes(key) || commonQueryParams.includes(key)) { + // @ts-expect-error + querystring[key] = params[key] + } else { + body = body ?? {} + // @ts-expect-error + body[key] = params[key] + } } } @@ -2268,8 +3201,12 @@ export default class Security { async queryApiKeys (this: That, params?: T.SecurityQueryApiKeysRequest, options?: TransportRequestOptionsWithMeta): Promise<TransportResult<T.SecurityQueryApiKeysResponse, unknown>> async queryApiKeys (this: That, params?: T.SecurityQueryApiKeysRequest, options?: TransportRequestOptions): Promise<T.SecurityQueryApiKeysResponse> async queryApiKeys (this: That, params?: T.SecurityQueryApiKeysRequest, options?: TransportRequestOptions): Promise<any> { - const acceptedPath: string[] = [] - const acceptedBody: string[] = ['aggregations', 'aggs', 'query', 'from', 'sort', 'size', 'search_after'] + const { + path: acceptedPath, + body: acceptedBody, + query: acceptedQuery + } = this.acceptedParams['security.query_api_keys'] + const userQuery = params?.querystring const querystring: Record<string, any> = userQuery != null ? { ...userQuery } : {} @@ -2292,8 +3229,14 @@ export default class Security { } else if (acceptedPath.includes(key)) { continue } else if (key !== 'body' && key !== 'querystring') { - // @ts-expect-error - querystring[key] = params[key] + if (acceptedQuery.includes(key) || commonQueryParams.includes(key)) { + // @ts-expect-error + querystring[key] = params[key] + } else { + body = body ?? {} + // @ts-expect-error + body[key] = params[key] + } } } @@ -2313,8 +3256,12 @@ export default class Security { async queryRole (this: That, params?: T.SecurityQueryRoleRequest, options?: TransportRequestOptionsWithMeta): Promise<TransportResult<T.SecurityQueryRoleResponse, unknown>> async queryRole (this: That, params?: T.SecurityQueryRoleRequest, options?: TransportRequestOptions): Promise<T.SecurityQueryRoleResponse> async queryRole (this: That, params?: T.SecurityQueryRoleRequest, options?: TransportRequestOptions): Promise<any> { - const acceptedPath: string[] = [] - const acceptedBody: string[] = ['query', 'from', 'sort', 'size', 'search_after'] + const { + path: acceptedPath, + body: acceptedBody, + query: acceptedQuery + } = this.acceptedParams['security.query_role'] + const userQuery = params?.querystring const querystring: Record<string, any> = userQuery != null ? { ...userQuery } : {} @@ -2337,8 +3284,14 @@ export default class Security { } else if (acceptedPath.includes(key)) { continue } else if (key !== 'body' && key !== 'querystring') { - // @ts-expect-error - querystring[key] = params[key] + if (acceptedQuery.includes(key) || commonQueryParams.includes(key)) { + // @ts-expect-error + querystring[key] = params[key] + } else { + body = body ?? {} + // @ts-expect-error + body[key] = params[key] + } } } @@ -2358,8 +3311,12 @@ export default class Security { async queryUser (this: That, params?: T.SecurityQueryUserRequest, options?: TransportRequestOptionsWithMeta): Promise<TransportResult<T.SecurityQueryUserResponse, unknown>> async queryUser (this: That, params?: T.SecurityQueryUserRequest, options?: TransportRequestOptions): Promise<T.SecurityQueryUserResponse> async queryUser (this: That, params?: T.SecurityQueryUserRequest, options?: TransportRequestOptions): Promise<any> { - const acceptedPath: string[] = [] - const acceptedBody: string[] = ['query', 'from', 'sort', 'size', 'search_after'] + const { + path: acceptedPath, + body: acceptedBody, + query: acceptedQuery + } = this.acceptedParams['security.query_user'] + const userQuery = params?.querystring const querystring: Record<string, any> = userQuery != null ? { ...userQuery } : {} @@ -2382,8 +3339,14 @@ export default class Security { } else if (acceptedPath.includes(key)) { continue } else if (key !== 'body' && key !== 'querystring') { - // @ts-expect-error - querystring[key] = params[key] + if (acceptedQuery.includes(key) || commonQueryParams.includes(key)) { + // @ts-expect-error + querystring[key] = params[key] + } else { + body = body ?? {} + // @ts-expect-error + body[key] = params[key] + } } } @@ -2403,8 +3366,12 @@ export default class Security { async samlAuthenticate (this: That, params: T.SecuritySamlAuthenticateRequest, options?: TransportRequestOptionsWithMeta): Promise<TransportResult<T.SecuritySamlAuthenticateResponse, unknown>> async samlAuthenticate (this: That, params: T.SecuritySamlAuthenticateRequest, options?: TransportRequestOptions): Promise<T.SecuritySamlAuthenticateResponse> async samlAuthenticate (this: That, params: T.SecuritySamlAuthenticateRequest, options?: TransportRequestOptions): Promise<any> { - const acceptedPath: string[] = [] - const acceptedBody: string[] = ['content', 'ids', 'realm'] + const { + path: acceptedPath, + body: acceptedBody, + query: acceptedQuery + } = this.acceptedParams['security.saml_authenticate'] + const userQuery = params?.querystring const querystring: Record<string, any> = userQuery != null ? { ...userQuery } : {} @@ -2426,8 +3393,14 @@ export default class Security { } else if (acceptedPath.includes(key)) { continue } else if (key !== 'body' && key !== 'querystring') { - // @ts-expect-error - querystring[key] = params[key] + if (acceptedQuery.includes(key) || commonQueryParams.includes(key)) { + // @ts-expect-error + querystring[key] = params[key] + } else { + body = body ?? {} + // @ts-expect-error + body[key] = params[key] + } } } @@ -2447,8 +3420,12 @@ export default class Security { async samlCompleteLogout (this: That, params: T.SecuritySamlCompleteLogoutRequest, options?: TransportRequestOptionsWithMeta): Promise<TransportResult<T.SecuritySamlCompleteLogoutResponse, unknown>> async samlCompleteLogout (this: That, params: T.SecuritySamlCompleteLogoutRequest, options?: TransportRequestOptions): Promise<T.SecuritySamlCompleteLogoutResponse> async samlCompleteLogout (this: That, params: T.SecuritySamlCompleteLogoutRequest, options?: TransportRequestOptions): Promise<any> { - const acceptedPath: string[] = [] - const acceptedBody: string[] = ['realm', 'ids', 'query_string', 'content'] + const { + path: acceptedPath, + body: acceptedBody, + query: acceptedQuery + } = this.acceptedParams['security.saml_complete_logout'] + const userQuery = params?.querystring const querystring: Record<string, any> = userQuery != null ? { ...userQuery } : {} @@ -2470,8 +3447,14 @@ export default class Security { } else if (acceptedPath.includes(key)) { continue } else if (key !== 'body' && key !== 'querystring') { - // @ts-expect-error - querystring[key] = params[key] + if (acceptedQuery.includes(key) || commonQueryParams.includes(key)) { + // @ts-expect-error + querystring[key] = params[key] + } else { + body = body ?? {} + // @ts-expect-error + body[key] = params[key] + } } } @@ -2491,8 +3474,12 @@ export default class Security { async samlInvalidate (this: That, params: T.SecuritySamlInvalidateRequest, options?: TransportRequestOptionsWithMeta): Promise<TransportResult<T.SecuritySamlInvalidateResponse, unknown>> async samlInvalidate (this: That, params: T.SecuritySamlInvalidateRequest, options?: TransportRequestOptions): Promise<T.SecuritySamlInvalidateResponse> async samlInvalidate (this: That, params: T.SecuritySamlInvalidateRequest, options?: TransportRequestOptions): Promise<any> { - const acceptedPath: string[] = [] - const acceptedBody: string[] = ['acs', 'query_string', 'realm'] + const { + path: acceptedPath, + body: acceptedBody, + query: acceptedQuery + } = this.acceptedParams['security.saml_invalidate'] + const userQuery = params?.querystring const querystring: Record<string, any> = userQuery != null ? { ...userQuery } : {} @@ -2514,8 +3501,14 @@ export default class Security { } else if (acceptedPath.includes(key)) { continue } else if (key !== 'body' && key !== 'querystring') { - // @ts-expect-error - querystring[key] = params[key] + if (acceptedQuery.includes(key) || commonQueryParams.includes(key)) { + // @ts-expect-error + querystring[key] = params[key] + } else { + body = body ?? {} + // @ts-expect-error + body[key] = params[key] + } } } @@ -2535,8 +3528,12 @@ export default class Security { async samlLogout (this: That, params: T.SecuritySamlLogoutRequest, options?: TransportRequestOptionsWithMeta): Promise<TransportResult<T.SecuritySamlLogoutResponse, unknown>> async samlLogout (this: That, params: T.SecuritySamlLogoutRequest, options?: TransportRequestOptions): Promise<T.SecuritySamlLogoutResponse> async samlLogout (this: That, params: T.SecuritySamlLogoutRequest, options?: TransportRequestOptions): Promise<any> { - const acceptedPath: string[] = [] - const acceptedBody: string[] = ['token', 'refresh_token'] + const { + path: acceptedPath, + body: acceptedBody, + query: acceptedQuery + } = this.acceptedParams['security.saml_logout'] + const userQuery = params?.querystring const querystring: Record<string, any> = userQuery != null ? { ...userQuery } : {} @@ -2558,8 +3555,14 @@ export default class Security { } else if (acceptedPath.includes(key)) { continue } else if (key !== 'body' && key !== 'querystring') { - // @ts-expect-error - querystring[key] = params[key] + if (acceptedQuery.includes(key) || commonQueryParams.includes(key)) { + // @ts-expect-error + querystring[key] = params[key] + } else { + body = body ?? {} + // @ts-expect-error + body[key] = params[key] + } } } @@ -2579,8 +3582,12 @@ export default class Security { async samlPrepareAuthentication (this: That, params?: T.SecuritySamlPrepareAuthenticationRequest, options?: TransportRequestOptionsWithMeta): Promise<TransportResult<T.SecuritySamlPrepareAuthenticationResponse, unknown>> async samlPrepareAuthentication (this: That, params?: T.SecuritySamlPrepareAuthenticationRequest, options?: TransportRequestOptions): Promise<T.SecuritySamlPrepareAuthenticationResponse> async samlPrepareAuthentication (this: That, params?: T.SecuritySamlPrepareAuthenticationRequest, options?: TransportRequestOptions): Promise<any> { - const acceptedPath: string[] = [] - const acceptedBody: string[] = ['acs', 'realm', 'relay_state'] + const { + path: acceptedPath, + body: acceptedBody, + query: acceptedQuery + } = this.acceptedParams['security.saml_prepare_authentication'] + const userQuery = params?.querystring const querystring: Record<string, any> = userQuery != null ? { ...userQuery } : {} @@ -2603,8 +3610,14 @@ export default class Security { } else if (acceptedPath.includes(key)) { continue } else if (key !== 'body' && key !== 'querystring') { - // @ts-expect-error - querystring[key] = params[key] + if (acceptedQuery.includes(key) || commonQueryParams.includes(key)) { + // @ts-expect-error + querystring[key] = params[key] + } else { + body = body ?? {} + // @ts-expect-error + body[key] = params[key] + } } } @@ -2624,7 +3637,10 @@ export default class Security { async samlServiceProviderMetadata (this: That, params: T.SecuritySamlServiceProviderMetadataRequest, options?: TransportRequestOptionsWithMeta): Promise<TransportResult<T.SecuritySamlServiceProviderMetadataResponse, unknown>> async samlServiceProviderMetadata (this: That, params: T.SecuritySamlServiceProviderMetadataRequest, options?: TransportRequestOptions): Promise<T.SecuritySamlServiceProviderMetadataResponse> async samlServiceProviderMetadata (this: That, params: T.SecuritySamlServiceProviderMetadataRequest, options?: TransportRequestOptions): Promise<any> { - const acceptedPath: string[] = ['realm_name'] + const { + path: acceptedPath + } = this.acceptedParams['security.saml_service_provider_metadata'] + const userQuery = params?.querystring const querystring: Record<string, any> = userQuery != null ? { ...userQuery } : {} @@ -2666,8 +3682,12 @@ export default class Security { async suggestUserProfiles (this: That, params?: T.SecuritySuggestUserProfilesRequest, options?: TransportRequestOptionsWithMeta): Promise<TransportResult<T.SecuritySuggestUserProfilesResponse, unknown>> async suggestUserProfiles (this: That, params?: T.SecuritySuggestUserProfilesRequest, options?: TransportRequestOptions): Promise<T.SecuritySuggestUserProfilesResponse> async suggestUserProfiles (this: That, params?: T.SecuritySuggestUserProfilesRequest, options?: TransportRequestOptions): Promise<any> { - const acceptedPath: string[] = [] - const acceptedBody: string[] = ['name', 'size', 'data', 'hint'] + const { + path: acceptedPath, + body: acceptedBody, + query: acceptedQuery + } = this.acceptedParams['security.suggest_user_profiles'] + const userQuery = params?.querystring const querystring: Record<string, any> = userQuery != null ? { ...userQuery } : {} @@ -2690,8 +3710,14 @@ export default class Security { } else if (acceptedPath.includes(key)) { continue } else if (key !== 'body' && key !== 'querystring') { - // @ts-expect-error - querystring[key] = params[key] + if (acceptedQuery.includes(key) || commonQueryParams.includes(key)) { + // @ts-expect-error + querystring[key] = params[key] + } else { + body = body ?? {} + // @ts-expect-error + body[key] = params[key] + } } } @@ -2711,8 +3737,12 @@ export default class Security { async updateApiKey (this: That, params: T.SecurityUpdateApiKeyRequest, options?: TransportRequestOptionsWithMeta): Promise<TransportResult<T.SecurityUpdateApiKeyResponse, unknown>> async updateApiKey (this: That, params: T.SecurityUpdateApiKeyRequest, options?: TransportRequestOptions): Promise<T.SecurityUpdateApiKeyResponse> async updateApiKey (this: That, params: T.SecurityUpdateApiKeyRequest, options?: TransportRequestOptions): Promise<any> { - const acceptedPath: string[] = ['id'] - const acceptedBody: string[] = ['role_descriptors', 'metadata', 'expiration'] + const { + path: acceptedPath, + body: acceptedBody, + query: acceptedQuery + } = this.acceptedParams['security.update_api_key'] + const userQuery = params?.querystring const querystring: Record<string, any> = userQuery != null ? { ...userQuery } : {} @@ -2734,8 +3764,14 @@ export default class Security { } else if (acceptedPath.includes(key)) { continue } else if (key !== 'body' && key !== 'querystring') { - // @ts-expect-error - querystring[key] = params[key] + if (acceptedQuery.includes(key) || commonQueryParams.includes(key)) { + // @ts-expect-error + querystring[key] = params[key] + } else { + body = body ?? {} + // @ts-expect-error + body[key] = params[key] + } } } @@ -2758,8 +3794,12 @@ export default class Security { async updateCrossClusterApiKey (this: That, params: T.SecurityUpdateCrossClusterApiKeyRequest, options?: TransportRequestOptionsWithMeta): Promise<TransportResult<T.SecurityUpdateCrossClusterApiKeyResponse, unknown>> async updateCrossClusterApiKey (this: That, params: T.SecurityUpdateCrossClusterApiKeyRequest, options?: TransportRequestOptions): Promise<T.SecurityUpdateCrossClusterApiKeyResponse> async updateCrossClusterApiKey (this: That, params: T.SecurityUpdateCrossClusterApiKeyRequest, options?: TransportRequestOptions): Promise<any> { - const acceptedPath: string[] = ['id'] - const acceptedBody: string[] = ['access', 'expiration', 'metadata'] + const { + path: acceptedPath, + body: acceptedBody, + query: acceptedQuery + } = this.acceptedParams['security.update_cross_cluster_api_key'] + const userQuery = params?.querystring const querystring: Record<string, any> = userQuery != null ? { ...userQuery } : {} @@ -2781,8 +3821,14 @@ export default class Security { } else if (acceptedPath.includes(key)) { continue } else if (key !== 'body' && key !== 'querystring') { - // @ts-expect-error - querystring[key] = params[key] + if (acceptedQuery.includes(key) || commonQueryParams.includes(key)) { + // @ts-expect-error + querystring[key] = params[key] + } else { + body = body ?? {} + // @ts-expect-error + body[key] = params[key] + } } } @@ -2805,8 +3851,12 @@ export default class Security { async updateSettings (this: That, params?: T.SecurityUpdateSettingsRequest, options?: TransportRequestOptionsWithMeta): Promise<TransportResult<T.SecurityUpdateSettingsResponse, unknown>> async updateSettings (this: That, params?: T.SecurityUpdateSettingsRequest, options?: TransportRequestOptions): Promise<T.SecurityUpdateSettingsResponse> async updateSettings (this: That, params?: T.SecurityUpdateSettingsRequest, options?: TransportRequestOptions): Promise<any> { - const acceptedPath: string[] = [] - const acceptedBody: string[] = ['security', 'security-profile', 'security-tokens'] + const { + path: acceptedPath, + body: acceptedBody, + query: acceptedQuery + } = this.acceptedParams['security.update_settings'] + const userQuery = params?.querystring const querystring: Record<string, any> = userQuery != null ? { ...userQuery } : {} @@ -2829,8 +3879,14 @@ export default class Security { } else if (acceptedPath.includes(key)) { continue } else if (key !== 'body' && key !== 'querystring') { - // @ts-expect-error - querystring[key] = params[key] + if (acceptedQuery.includes(key) || commonQueryParams.includes(key)) { + // @ts-expect-error + querystring[key] = params[key] + } else { + body = body ?? {} + // @ts-expect-error + body[key] = params[key] + } } } @@ -2850,8 +3906,12 @@ export default class Security { async updateUserProfileData (this: That, params: T.SecurityUpdateUserProfileDataRequest, options?: TransportRequestOptionsWithMeta): Promise<TransportResult<T.SecurityUpdateUserProfileDataResponse, unknown>> async updateUserProfileData (this: That, params: T.SecurityUpdateUserProfileDataRequest, options?: TransportRequestOptions): Promise<T.SecurityUpdateUserProfileDataResponse> async updateUserProfileData (this: That, params: T.SecurityUpdateUserProfileDataRequest, options?: TransportRequestOptions): Promise<any> { - const acceptedPath: string[] = ['uid'] - const acceptedBody: string[] = ['labels', 'data'] + const { + path: acceptedPath, + body: acceptedBody, + query: acceptedQuery + } = this.acceptedParams['security.update_user_profile_data'] + const userQuery = params?.querystring const querystring: Record<string, any> = userQuery != null ? { ...userQuery } : {} @@ -2873,8 +3933,14 @@ export default class Security { } else if (acceptedPath.includes(key)) { continue } else if (key !== 'body' && key !== 'querystring') { - // @ts-expect-error - querystring[key] = params[key] + if (acceptedQuery.includes(key) || commonQueryParams.includes(key)) { + // @ts-expect-error + querystring[key] = params[key] + } else { + body = body ?? {} + // @ts-expect-error + body[key] = params[key] + } } } diff --git a/src/api/api/shutdown.ts b/src/api/api/shutdown.ts index ffa3b9c39..1cac3a03b 100644 --- a/src/api/api/shutdown.ts +++ b/src/api/api/shutdown.ts @@ -35,12 +35,55 @@ import { TransportResult } from '@elastic/transport' import * as T from '../types' -interface That { transport: Transport } + +interface That { + transport: Transport + acceptedParams: Record<string, { path: string[], body: string[], query: string[] }> +} + +const commonQueryParams = ['error_trace', 'filter_path', 'human', 'pretty'] export default class Shutdown { transport: Transport + acceptedParams: Record<string, { path: string[], body: string[], query: string[] }> constructor (transport: Transport) { this.transport = transport + this.acceptedParams = { + 'shutdown.delete_node': { + path: [ + 'node_id' + ], + body: [], + query: [ + 'master_timeout', + 'timeout' + ] + }, + 'shutdown.get_node': { + path: [ + 'node_id' + ], + body: [], + query: [ + 'master_timeout' + ] + }, + 'shutdown.put_node': { + path: [ + 'node_id' + ], + body: [ + 'type', + 'reason', + 'allocation_delay', + 'target_node_name' + ], + query: [ + 'master_timeout', + 'timeout' + ] + } + } } /** @@ -51,7 +94,10 @@ export default class Shutdown { async deleteNode (this: That, params: T.ShutdownDeleteNodeRequest, options?: TransportRequestOptionsWithMeta): Promise<TransportResult<T.ShutdownDeleteNodeResponse, unknown>> async deleteNode (this: That, params: T.ShutdownDeleteNodeRequest, options?: TransportRequestOptions): Promise<T.ShutdownDeleteNodeResponse> async deleteNode (this: That, params: T.ShutdownDeleteNodeRequest, options?: TransportRequestOptions): Promise<any> { - const acceptedPath: string[] = ['node_id'] + const { + path: acceptedPath + } = this.acceptedParams['shutdown.delete_node'] + const userQuery = params?.querystring const querystring: Record<string, any> = userQuery != null ? { ...userQuery } : {} @@ -93,7 +139,10 @@ export default class Shutdown { async getNode (this: That, params?: T.ShutdownGetNodeRequest, options?: TransportRequestOptionsWithMeta): Promise<TransportResult<T.ShutdownGetNodeResponse, unknown>> async getNode (this: That, params?: T.ShutdownGetNodeRequest, options?: TransportRequestOptions): Promise<T.ShutdownGetNodeResponse> async getNode (this: That, params?: T.ShutdownGetNodeRequest, options?: TransportRequestOptions): Promise<any> { - const acceptedPath: string[] = ['node_id'] + const { + path: acceptedPath + } = this.acceptedParams['shutdown.get_node'] + const userQuery = params?.querystring const querystring: Record<string, any> = userQuery != null ? { ...userQuery } : {} @@ -143,8 +192,12 @@ export default class Shutdown { async putNode (this: That, params: T.ShutdownPutNodeRequest, options?: TransportRequestOptionsWithMeta): Promise<TransportResult<T.ShutdownPutNodeResponse, unknown>> async putNode (this: That, params: T.ShutdownPutNodeRequest, options?: TransportRequestOptions): Promise<T.ShutdownPutNodeResponse> async putNode (this: That, params: T.ShutdownPutNodeRequest, options?: TransportRequestOptions): Promise<any> { - const acceptedPath: string[] = ['node_id'] - const acceptedBody: string[] = ['type', 'reason', 'allocation_delay', 'target_node_name'] + const { + path: acceptedPath, + body: acceptedBody, + query: acceptedQuery + } = this.acceptedParams['shutdown.put_node'] + const userQuery = params?.querystring const querystring: Record<string, any> = userQuery != null ? { ...userQuery } : {} @@ -166,8 +219,14 @@ export default class Shutdown { } else if (acceptedPath.includes(key)) { continue } else if (key !== 'body' && key !== 'querystring') { - // @ts-expect-error - querystring[key] = params[key] + if (acceptedQuery.includes(key) || commonQueryParams.includes(key)) { + // @ts-expect-error + querystring[key] = params[key] + } else { + body = body ?? {} + // @ts-expect-error + body[key] = params[key] + } } } diff --git a/src/api/api/simulate.ts b/src/api/api/simulate.ts index ba1689505..c1b3fc539 100644 --- a/src/api/api/simulate.ts +++ b/src/api/api/simulate.ts @@ -35,12 +35,36 @@ import { TransportResult } from '@elastic/transport' import * as T from '../types' -interface That { transport: Transport } + +interface That { + transport: Transport + acceptedParams: Record<string, { path: string[], body: string[], query: string[] }> +} + +const commonQueryParams = ['error_trace', 'filter_path', 'human', 'pretty'] export default class Simulate { transport: Transport + acceptedParams: Record<string, { path: string[], body: string[], query: string[] }> constructor (transport: Transport) { this.transport = transport + this.acceptedParams = { + 'simulate.ingest': { + path: [ + 'index' + ], + body: [ + 'docs', + 'component_template_substitutions', + 'index_template_subtitutions', + 'mapping_addition', + 'pipeline_substitutions' + ], + query: [ + 'pipeline' + ] + } + } } /** @@ -51,8 +75,12 @@ export default class Simulate { async ingest (this: That, params: T.SimulateIngestRequest, options?: TransportRequestOptionsWithMeta): Promise<TransportResult<T.SimulateIngestResponse, unknown>> async ingest (this: That, params: T.SimulateIngestRequest, options?: TransportRequestOptions): Promise<T.SimulateIngestResponse> async ingest (this: That, params: T.SimulateIngestRequest, options?: TransportRequestOptions): Promise<any> { - const acceptedPath: string[] = ['index'] - const acceptedBody: string[] = ['docs', 'component_template_substitutions', 'index_template_subtitutions', 'mapping_addition', 'pipeline_substitutions'] + const { + path: acceptedPath, + body: acceptedBody, + query: acceptedQuery + } = this.acceptedParams['simulate.ingest'] + const userQuery = params?.querystring const querystring: Record<string, any> = userQuery != null ? { ...userQuery } : {} @@ -74,8 +102,14 @@ export default class Simulate { } else if (acceptedPath.includes(key)) { continue } else if (key !== 'body' && key !== 'querystring') { - // @ts-expect-error - querystring[key] = params[key] + if (acceptedQuery.includes(key) || commonQueryParams.includes(key)) { + // @ts-expect-error + querystring[key] = params[key] + } else { + body = body ?? {} + // @ts-expect-error + body[key] = params[key] + } } } diff --git a/src/api/api/slm.ts b/src/api/api/slm.ts index 9e6a856f9..79a2f6f20 100644 --- a/src/api/api/slm.ts +++ b/src/api/api/slm.ts @@ -35,12 +35,107 @@ import { TransportResult } from '@elastic/transport' import * as T from '../types' -interface That { transport: Transport } + +interface That { + transport: Transport + acceptedParams: Record<string, { path: string[], body: string[], query: string[] }> +} + +const commonQueryParams = ['error_trace', 'filter_path', 'human', 'pretty'] export default class Slm { transport: Transport + acceptedParams: Record<string, { path: string[], body: string[], query: string[] }> constructor (transport: Transport) { this.transport = transport + this.acceptedParams = { + 'slm.delete_lifecycle': { + path: [ + 'policy_id' + ], + body: [], + query: [ + 'master_timeout', + 'timeout' + ] + }, + 'slm.execute_lifecycle': { + path: [ + 'policy_id' + ], + body: [], + query: [ + 'master_timeout', + 'timeout' + ] + }, + 'slm.execute_retention': { + path: [], + body: [], + query: [ + 'master_timeout', + 'timeout' + ] + }, + 'slm.get_lifecycle': { + path: [ + 'policy_id' + ], + body: [], + query: [ + 'master_timeout', + 'timeout' + ] + }, + 'slm.get_stats': { + path: [], + body: [], + query: [ + 'master_timeout', + 'timeout' + ] + }, + 'slm.get_status': { + path: [], + body: [], + query: [ + 'master_timeout', + 'timeout' + ] + }, + 'slm.put_lifecycle': { + path: [ + 'policy_id' + ], + body: [ + 'config', + 'name', + 'repository', + 'retention', + 'schedule' + ], + query: [ + 'master_timeout', + 'timeout' + ] + }, + 'slm.start': { + path: [], + body: [], + query: [ + 'master_timeout', + 'timeout' + ] + }, + 'slm.stop': { + path: [], + body: [], + query: [ + 'master_timeout', + 'timeout' + ] + } + } } /** @@ -51,7 +146,10 @@ export default class Slm { async deleteLifecycle (this: That, params: T.SlmDeleteLifecycleRequest, options?: TransportRequestOptionsWithMeta): Promise<TransportResult<T.SlmDeleteLifecycleResponse, unknown>> async deleteLifecycle (this: That, params: T.SlmDeleteLifecycleRequest, options?: TransportRequestOptions): Promise<T.SlmDeleteLifecycleResponse> async deleteLifecycle (this: That, params: T.SlmDeleteLifecycleRequest, options?: TransportRequestOptions): Promise<any> { - const acceptedPath: string[] = ['policy_id'] + const { + path: acceptedPath + } = this.acceptedParams['slm.delete_lifecycle'] + const userQuery = params?.querystring const querystring: Record<string, any> = userQuery != null ? { ...userQuery } : {} @@ -93,7 +191,10 @@ export default class Slm { async executeLifecycle (this: That, params: T.SlmExecuteLifecycleRequest, options?: TransportRequestOptionsWithMeta): Promise<TransportResult<T.SlmExecuteLifecycleResponse, unknown>> async executeLifecycle (this: That, params: T.SlmExecuteLifecycleRequest, options?: TransportRequestOptions): Promise<T.SlmExecuteLifecycleResponse> async executeLifecycle (this: That, params: T.SlmExecuteLifecycleRequest, options?: TransportRequestOptions): Promise<any> { - const acceptedPath: string[] = ['policy_id'] + const { + path: acceptedPath + } = this.acceptedParams['slm.execute_lifecycle'] + const userQuery = params?.querystring const querystring: Record<string, any> = userQuery != null ? { ...userQuery } : {} @@ -135,7 +236,10 @@ export default class Slm { async executeRetention (this: That, params?: T.SlmExecuteRetentionRequest, options?: TransportRequestOptionsWithMeta): Promise<TransportResult<T.SlmExecuteRetentionResponse, unknown>> async executeRetention (this: That, params?: T.SlmExecuteRetentionRequest, options?: TransportRequestOptions): Promise<T.SlmExecuteRetentionResponse> async executeRetention (this: That, params?: T.SlmExecuteRetentionRequest, options?: TransportRequestOptions): Promise<any> { - const acceptedPath: string[] = [] + const { + path: acceptedPath + } = this.acceptedParams['slm.execute_retention'] + const userQuery = params?.querystring const querystring: Record<string, any> = userQuery != null ? { ...userQuery } : {} @@ -175,7 +279,10 @@ export default class Slm { async getLifecycle (this: That, params?: T.SlmGetLifecycleRequest, options?: TransportRequestOptionsWithMeta): Promise<TransportResult<T.SlmGetLifecycleResponse, unknown>> async getLifecycle (this: That, params?: T.SlmGetLifecycleRequest, options?: TransportRequestOptions): Promise<T.SlmGetLifecycleResponse> async getLifecycle (this: That, params?: T.SlmGetLifecycleRequest, options?: TransportRequestOptions): Promise<any> { - const acceptedPath: string[] = ['policy_id'] + const { + path: acceptedPath + } = this.acceptedParams['slm.get_lifecycle'] + const userQuery = params?.querystring const querystring: Record<string, any> = userQuery != null ? { ...userQuery } : {} @@ -225,7 +332,10 @@ export default class Slm { async getStats (this: That, params?: T.SlmGetStatsRequest, options?: TransportRequestOptionsWithMeta): Promise<TransportResult<T.SlmGetStatsResponse, unknown>> async getStats (this: That, params?: T.SlmGetStatsRequest, options?: TransportRequestOptions): Promise<T.SlmGetStatsResponse> async getStats (this: That, params?: T.SlmGetStatsRequest, options?: TransportRequestOptions): Promise<any> { - const acceptedPath: string[] = [] + const { + path: acceptedPath + } = this.acceptedParams['slm.get_stats'] + const userQuery = params?.querystring const querystring: Record<string, any> = userQuery != null ? { ...userQuery } : {} @@ -265,7 +375,10 @@ export default class Slm { async getStatus (this: That, params?: T.SlmGetStatusRequest, options?: TransportRequestOptionsWithMeta): Promise<TransportResult<T.SlmGetStatusResponse, unknown>> async getStatus (this: That, params?: T.SlmGetStatusRequest, options?: TransportRequestOptions): Promise<T.SlmGetStatusResponse> async getStatus (this: That, params?: T.SlmGetStatusRequest, options?: TransportRequestOptions): Promise<any> { - const acceptedPath: string[] = [] + const { + path: acceptedPath + } = this.acceptedParams['slm.get_status'] + const userQuery = params?.querystring const querystring: Record<string, any> = userQuery != null ? { ...userQuery } : {} @@ -305,8 +418,12 @@ export default class Slm { async putLifecycle (this: That, params: T.SlmPutLifecycleRequest, options?: TransportRequestOptionsWithMeta): Promise<TransportResult<T.SlmPutLifecycleResponse, unknown>> async putLifecycle (this: That, params: T.SlmPutLifecycleRequest, options?: TransportRequestOptions): Promise<T.SlmPutLifecycleResponse> async putLifecycle (this: That, params: T.SlmPutLifecycleRequest, options?: TransportRequestOptions): Promise<any> { - const acceptedPath: string[] = ['policy_id'] - const acceptedBody: string[] = ['config', 'name', 'repository', 'retention', 'schedule'] + const { + path: acceptedPath, + body: acceptedBody, + query: acceptedQuery + } = this.acceptedParams['slm.put_lifecycle'] + const userQuery = params?.querystring const querystring: Record<string, any> = userQuery != null ? { ...userQuery } : {} @@ -328,8 +445,14 @@ export default class Slm { } else if (acceptedPath.includes(key)) { continue } else if (key !== 'body' && key !== 'querystring') { - // @ts-expect-error - querystring[key] = params[key] + if (acceptedQuery.includes(key) || commonQueryParams.includes(key)) { + // @ts-expect-error + querystring[key] = params[key] + } else { + body = body ?? {} + // @ts-expect-error + body[key] = params[key] + } } } @@ -352,7 +475,10 @@ export default class Slm { async start (this: That, params?: T.SlmStartRequest, options?: TransportRequestOptionsWithMeta): Promise<TransportResult<T.SlmStartResponse, unknown>> async start (this: That, params?: T.SlmStartRequest, options?: TransportRequestOptions): Promise<T.SlmStartResponse> async start (this: That, params?: T.SlmStartRequest, options?: TransportRequestOptions): Promise<any> { - const acceptedPath: string[] = [] + const { + path: acceptedPath + } = this.acceptedParams['slm.start'] + const userQuery = params?.querystring const querystring: Record<string, any> = userQuery != null ? { ...userQuery } : {} @@ -392,7 +518,10 @@ export default class Slm { async stop (this: That, params?: T.SlmStopRequest, options?: TransportRequestOptionsWithMeta): Promise<TransportResult<T.SlmStopResponse, unknown>> async stop (this: That, params?: T.SlmStopRequest, options?: TransportRequestOptions): Promise<T.SlmStopResponse> async stop (this: That, params?: T.SlmStopRequest, options?: TransportRequestOptions): Promise<any> { - const acceptedPath: string[] = [] + const { + path: acceptedPath + } = this.acceptedParams['slm.stop'] + const userQuery = params?.querystring const querystring: Record<string, any> = userQuery != null ? { ...userQuery } : {} diff --git a/src/api/api/snapshot.ts b/src/api/api/snapshot.ts index 3b37c9bdb..6b5ea2848 100644 --- a/src/api/api/snapshot.ts +++ b/src/api/api/snapshot.ts @@ -35,12 +35,208 @@ import { TransportResult } from '@elastic/transport' import * as T from '../types' -interface That { transport: Transport } + +interface That { + transport: Transport + acceptedParams: Record<string, { path: string[], body: string[], query: string[] }> +} + +const commonQueryParams = ['error_trace', 'filter_path', 'human', 'pretty'] export default class Snapshot { transport: Transport + acceptedParams: Record<string, { path: string[], body: string[], query: string[] }> constructor (transport: Transport) { this.transport = transport + this.acceptedParams = { + 'snapshot.cleanup_repository': { + path: [ + 'name' + ], + body: [], + query: [ + 'master_timeout', + 'timeout' + ] + }, + 'snapshot.clone': { + path: [ + 'repository', + 'snapshot', + 'target_snapshot' + ], + body: [ + 'indices' + ], + query: [ + 'master_timeout', + 'timeout' + ] + }, + 'snapshot.create': { + path: [ + 'repository', + 'snapshot' + ], + body: [ + 'expand_wildcards', + 'feature_states', + 'ignore_unavailable', + 'include_global_state', + 'indices', + 'metadata', + 'partial' + ], + query: [ + 'master_timeout', + 'wait_for_completion' + ] + }, + 'snapshot.create_repository': { + path: [ + 'name' + ], + body: [ + 'repository' + ], + query: [ + 'master_timeout', + 'timeout', + 'verify' + ] + }, + 'snapshot.delete': { + path: [ + 'repository', + 'snapshot' + ], + body: [], + query: [ + 'master_timeout' + ] + }, + 'snapshot.delete_repository': { + path: [ + 'name' + ], + body: [], + query: [ + 'master_timeout', + 'timeout' + ] + }, + 'snapshot.get': { + path: [ + 'repository', + 'snapshot' + ], + body: [], + query: [ + 'after', + 'from_sort_value', + 'ignore_unavailable', + 'index_details', + 'index_names', + 'include_repository', + 'master_timeout', + 'order', + 'offset', + 'size', + 'slm_policy_filter', + 'sort', + 'verbose' + ] + }, + 'snapshot.get_repository': { + path: [ + 'name' + ], + body: [], + query: [ + 'local', + 'master_timeout' + ] + }, + 'snapshot.repository_analyze': { + path: [ + 'name' + ], + body: [], + query: [ + 'blob_count', + 'concurrency', + 'detailed', + 'early_read_node_count', + 'max_blob_size', + 'max_total_data_size', + 'rare_action_probability', + 'rarely_abort_writes', + 'read_node_count', + 'register_operation_count', + 'seed', + 'timeout' + ] + }, + 'snapshot.repository_verify_integrity': { + path: [ + 'name' + ], + body: [], + query: [ + 'blob_thread_pool_concurrency', + 'index_snapshot_verification_concurrency', + 'index_verification_concurrency', + 'max_bytes_per_sec', + 'max_failed_shard_snapshots', + 'meta_thread_pool_concurrency', + 'snapshot_verification_concurrency', + 'verify_blob_contents' + ] + }, + 'snapshot.restore': { + path: [ + 'repository', + 'snapshot' + ], + body: [ + 'feature_states', + 'ignore_index_settings', + 'ignore_unavailable', + 'include_aliases', + 'include_global_state', + 'index_settings', + 'indices', + 'partial', + 'rename_pattern', + 'rename_replacement' + ], + query: [ + 'master_timeout', + 'wait_for_completion' + ] + }, + 'snapshot.status': { + path: [ + 'repository', + 'snapshot' + ], + body: [], + query: [ + 'ignore_unavailable', + 'master_timeout' + ] + }, + 'snapshot.verify_repository': { + path: [ + 'name' + ], + body: [], + query: [ + 'master_timeout', + 'timeout' + ] + } + } } /** @@ -51,7 +247,10 @@ export default class Snapshot { async cleanupRepository (this: That, params: T.SnapshotCleanupRepositoryRequest, options?: TransportRequestOptionsWithMeta): Promise<TransportResult<T.SnapshotCleanupRepositoryResponse, unknown>> async cleanupRepository (this: That, params: T.SnapshotCleanupRepositoryRequest, options?: TransportRequestOptions): Promise<T.SnapshotCleanupRepositoryResponse> async cleanupRepository (this: That, params: T.SnapshotCleanupRepositoryRequest, options?: TransportRequestOptions): Promise<any> { - const acceptedPath: string[] = ['name'] + const { + path: acceptedPath + } = this.acceptedParams['snapshot.cleanup_repository'] + const userQuery = params?.querystring const querystring: Record<string, any> = userQuery != null ? { ...userQuery } : {} @@ -93,8 +292,12 @@ export default class Snapshot { async clone (this: That, params: T.SnapshotCloneRequest, options?: TransportRequestOptionsWithMeta): Promise<TransportResult<T.SnapshotCloneResponse, unknown>> async clone (this: That, params: T.SnapshotCloneRequest, options?: TransportRequestOptions): Promise<T.SnapshotCloneResponse> async clone (this: That, params: T.SnapshotCloneRequest, options?: TransportRequestOptions): Promise<any> { - const acceptedPath: string[] = ['repository', 'snapshot', 'target_snapshot'] - const acceptedBody: string[] = ['indices'] + const { + path: acceptedPath, + body: acceptedBody, + query: acceptedQuery + } = this.acceptedParams['snapshot.clone'] + const userQuery = params?.querystring const querystring: Record<string, any> = userQuery != null ? { ...userQuery } : {} @@ -116,8 +319,14 @@ export default class Snapshot { } else if (acceptedPath.includes(key)) { continue } else if (key !== 'body' && key !== 'querystring') { - // @ts-expect-error - querystring[key] = params[key] + if (acceptedQuery.includes(key) || commonQueryParams.includes(key)) { + // @ts-expect-error + querystring[key] = params[key] + } else { + body = body ?? {} + // @ts-expect-error + body[key] = params[key] + } } } @@ -142,8 +351,12 @@ export default class Snapshot { async create (this: That, params: T.SnapshotCreateRequest, options?: TransportRequestOptionsWithMeta): Promise<TransportResult<T.SnapshotCreateResponse, unknown>> async create (this: That, params: T.SnapshotCreateRequest, options?: TransportRequestOptions): Promise<T.SnapshotCreateResponse> async create (this: That, params: T.SnapshotCreateRequest, options?: TransportRequestOptions): Promise<any> { - const acceptedPath: string[] = ['repository', 'snapshot'] - const acceptedBody: string[] = ['expand_wildcards', 'feature_states', 'ignore_unavailable', 'include_global_state', 'indices', 'metadata', 'partial'] + const { + path: acceptedPath, + body: acceptedBody, + query: acceptedQuery + } = this.acceptedParams['snapshot.create'] + const userQuery = params?.querystring const querystring: Record<string, any> = userQuery != null ? { ...userQuery } : {} @@ -165,8 +378,14 @@ export default class Snapshot { } else if (acceptedPath.includes(key)) { continue } else if (key !== 'body' && key !== 'querystring') { - // @ts-expect-error - querystring[key] = params[key] + if (acceptedQuery.includes(key) || commonQueryParams.includes(key)) { + // @ts-expect-error + querystring[key] = params[key] + } else { + body = body ?? {} + // @ts-expect-error + body[key] = params[key] + } } } @@ -190,8 +409,12 @@ export default class Snapshot { async createRepository (this: That, params: T.SnapshotCreateRepositoryRequest, options?: TransportRequestOptionsWithMeta): Promise<TransportResult<T.SnapshotCreateRepositoryResponse, unknown>> async createRepository (this: That, params: T.SnapshotCreateRepositoryRequest, options?: TransportRequestOptions): Promise<T.SnapshotCreateRepositoryResponse> async createRepository (this: That, params: T.SnapshotCreateRepositoryRequest, options?: TransportRequestOptions): Promise<any> { - const acceptedPath: string[] = ['name'] - const acceptedBody: string[] = ['repository'] + const { + path: acceptedPath, + body: acceptedBody, + query: acceptedQuery + } = this.acceptedParams['snapshot.create_repository'] + const userQuery = params?.querystring const querystring: Record<string, any> = userQuery != null ? { ...userQuery } : {} @@ -203,8 +426,14 @@ export default class Snapshot { } else if (acceptedPath.includes(key)) { continue } else if (key !== 'body' && key !== 'querystring') { - // @ts-expect-error - querystring[key] = params[key] + if (acceptedQuery.includes(key) || commonQueryParams.includes(key)) { + // @ts-expect-error + querystring[key] = params[key] + } else { + body = body ?? {} + // @ts-expect-error + body[key] = params[key] + } } } @@ -227,7 +456,10 @@ export default class Snapshot { async delete (this: That, params: T.SnapshotDeleteRequest, options?: TransportRequestOptionsWithMeta): Promise<TransportResult<T.SnapshotDeleteResponse, unknown>> async delete (this: That, params: T.SnapshotDeleteRequest, options?: TransportRequestOptions): Promise<T.SnapshotDeleteResponse> async delete (this: That, params: T.SnapshotDeleteRequest, options?: TransportRequestOptions): Promise<any> { - const acceptedPath: string[] = ['repository', 'snapshot'] + const { + path: acceptedPath + } = this.acceptedParams['snapshot.delete'] + const userQuery = params?.querystring const querystring: Record<string, any> = userQuery != null ? { ...userQuery } : {} @@ -270,7 +502,10 @@ export default class Snapshot { async deleteRepository (this: That, params: T.SnapshotDeleteRepositoryRequest, options?: TransportRequestOptionsWithMeta): Promise<TransportResult<T.SnapshotDeleteRepositoryResponse, unknown>> async deleteRepository (this: That, params: T.SnapshotDeleteRepositoryRequest, options?: TransportRequestOptions): Promise<T.SnapshotDeleteRepositoryResponse> async deleteRepository (this: That, params: T.SnapshotDeleteRepositoryRequest, options?: TransportRequestOptions): Promise<any> { - const acceptedPath: string[] = ['name'] + const { + path: acceptedPath + } = this.acceptedParams['snapshot.delete_repository'] + const userQuery = params?.querystring const querystring: Record<string, any> = userQuery != null ? { ...userQuery } : {} @@ -312,7 +547,10 @@ export default class Snapshot { async get (this: That, params: T.SnapshotGetRequest, options?: TransportRequestOptionsWithMeta): Promise<TransportResult<T.SnapshotGetResponse, unknown>> async get (this: That, params: T.SnapshotGetRequest, options?: TransportRequestOptions): Promise<T.SnapshotGetResponse> async get (this: That, params: T.SnapshotGetRequest, options?: TransportRequestOptions): Promise<any> { - const acceptedPath: string[] = ['repository', 'snapshot'] + const { + path: acceptedPath + } = this.acceptedParams['snapshot.get'] + const userQuery = params?.querystring const querystring: Record<string, any> = userQuery != null ? { ...userQuery } : {} @@ -355,7 +593,10 @@ export default class Snapshot { async getRepository (this: That, params?: T.SnapshotGetRepositoryRequest, options?: TransportRequestOptionsWithMeta): Promise<TransportResult<T.SnapshotGetRepositoryResponse, unknown>> async getRepository (this: That, params?: T.SnapshotGetRepositoryRequest, options?: TransportRequestOptions): Promise<T.SnapshotGetRepositoryResponse> async getRepository (this: That, params?: T.SnapshotGetRepositoryRequest, options?: TransportRequestOptions): Promise<any> { - const acceptedPath: string[] = ['name'] + const { + path: acceptedPath + } = this.acceptedParams['snapshot.get_repository'] + const userQuery = params?.querystring const querystring: Record<string, any> = userQuery != null ? { ...userQuery } : {} @@ -405,7 +646,10 @@ export default class Snapshot { async repositoryAnalyze (this: That, params: T.SnapshotRepositoryAnalyzeRequest, options?: TransportRequestOptionsWithMeta): Promise<TransportResult<T.SnapshotRepositoryAnalyzeResponse, unknown>> async repositoryAnalyze (this: That, params: T.SnapshotRepositoryAnalyzeRequest, options?: TransportRequestOptions): Promise<T.SnapshotRepositoryAnalyzeResponse> async repositoryAnalyze (this: That, params: T.SnapshotRepositoryAnalyzeRequest, options?: TransportRequestOptions): Promise<any> { - const acceptedPath: string[] = ['name'] + const { + path: acceptedPath + } = this.acceptedParams['snapshot.repository_analyze'] + const userQuery = params?.querystring const querystring: Record<string, any> = userQuery != null ? { ...userQuery } : {} @@ -447,7 +691,10 @@ export default class Snapshot { async repositoryVerifyIntegrity (this: That, params: T.SnapshotRepositoryVerifyIntegrityRequest, options?: TransportRequestOptionsWithMeta): Promise<TransportResult<T.SnapshotRepositoryVerifyIntegrityResponse, unknown>> async repositoryVerifyIntegrity (this: That, params: T.SnapshotRepositoryVerifyIntegrityRequest, options?: TransportRequestOptions): Promise<T.SnapshotRepositoryVerifyIntegrityResponse> async repositoryVerifyIntegrity (this: That, params: T.SnapshotRepositoryVerifyIntegrityRequest, options?: TransportRequestOptions): Promise<any> { - const acceptedPath: string[] = ['name'] + const { + path: acceptedPath + } = this.acceptedParams['snapshot.repository_verify_integrity'] + const userQuery = params?.querystring const querystring: Record<string, any> = userQuery != null ? { ...userQuery } : {} @@ -489,8 +736,12 @@ export default class Snapshot { async restore (this: That, params: T.SnapshotRestoreRequest, options?: TransportRequestOptionsWithMeta): Promise<TransportResult<T.SnapshotRestoreResponse, unknown>> async restore (this: That, params: T.SnapshotRestoreRequest, options?: TransportRequestOptions): Promise<T.SnapshotRestoreResponse> async restore (this: That, params: T.SnapshotRestoreRequest, options?: TransportRequestOptions): Promise<any> { - const acceptedPath: string[] = ['repository', 'snapshot'] - const acceptedBody: string[] = ['feature_states', 'ignore_index_settings', 'ignore_unavailable', 'include_aliases', 'include_global_state', 'index_settings', 'indices', 'partial', 'rename_pattern', 'rename_replacement'] + const { + path: acceptedPath, + body: acceptedBody, + query: acceptedQuery + } = this.acceptedParams['snapshot.restore'] + const userQuery = params?.querystring const querystring: Record<string, any> = userQuery != null ? { ...userQuery } : {} @@ -512,8 +763,14 @@ export default class Snapshot { } else if (acceptedPath.includes(key)) { continue } else if (key !== 'body' && key !== 'querystring') { - // @ts-expect-error - querystring[key] = params[key] + if (acceptedQuery.includes(key) || commonQueryParams.includes(key)) { + // @ts-expect-error + querystring[key] = params[key] + } else { + body = body ?? {} + // @ts-expect-error + body[key] = params[key] + } } } @@ -537,7 +794,10 @@ export default class Snapshot { async status (this: That, params?: T.SnapshotStatusRequest, options?: TransportRequestOptionsWithMeta): Promise<TransportResult<T.SnapshotStatusResponse, unknown>> async status (this: That, params?: T.SnapshotStatusRequest, options?: TransportRequestOptions): Promise<T.SnapshotStatusResponse> async status (this: That, params?: T.SnapshotStatusRequest, options?: TransportRequestOptions): Promise<any> { - const acceptedPath: string[] = ['repository', 'snapshot'] + const { + path: acceptedPath + } = this.acceptedParams['snapshot.status'] + const userQuery = params?.querystring const querystring: Record<string, any> = userQuery != null ? { ...userQuery } : {} @@ -591,7 +851,10 @@ export default class Snapshot { async verifyRepository (this: That, params: T.SnapshotVerifyRepositoryRequest, options?: TransportRequestOptionsWithMeta): Promise<TransportResult<T.SnapshotVerifyRepositoryResponse, unknown>> async verifyRepository (this: That, params: T.SnapshotVerifyRepositoryRequest, options?: TransportRequestOptions): Promise<T.SnapshotVerifyRepositoryResponse> async verifyRepository (this: That, params: T.SnapshotVerifyRepositoryRequest, options?: TransportRequestOptions): Promise<any> { - const acceptedPath: string[] = ['name'] + const { + path: acceptedPath + } = this.acceptedParams['snapshot.verify_repository'] + const userQuery = params?.querystring const querystring: Record<string, any> = userQuery != null ? { ...userQuery } : {} diff --git a/src/api/api/sql.ts b/src/api/api/sql.ts index 871cb7139..60478c7f7 100644 --- a/src/api/api/sql.ts +++ b/src/api/api/sql.ts @@ -35,12 +35,89 @@ import { TransportResult } from '@elastic/transport' import * as T from '../types' -interface That { transport: Transport } + +interface That { + transport: Transport + acceptedParams: Record<string, { path: string[], body: string[], query: string[] }> +} + +const commonQueryParams = ['error_trace', 'filter_path', 'human', 'pretty'] export default class Sql { transport: Transport + acceptedParams: Record<string, { path: string[], body: string[], query: string[] }> constructor (transport: Transport) { this.transport = transport + this.acceptedParams = { + 'sql.clear_cursor': { + path: [], + body: [ + 'cursor' + ], + query: [] + }, + 'sql.delete_async': { + path: [ + 'id' + ], + body: [], + query: [] + }, + 'sql.get_async': { + path: [ + 'id' + ], + body: [], + query: [ + 'delimiter', + 'format', + 'keep_alive', + 'wait_for_completion_timeout' + ] + }, + 'sql.get_async_status': { + path: [ + 'id' + ], + body: [], + query: [] + }, + 'sql.query': { + path: [], + body: [ + 'allow_partial_search_results', + 'catalog', + 'columnar', + 'cursor', + 'fetch_size', + 'field_multi_value_leniency', + 'filter', + 'index_using_frozen', + 'keep_alive', + 'keep_on_completion', + 'page_timeout', + 'params', + 'query', + 'request_timeout', + 'runtime_mappings', + 'time_zone', + 'wait_for_completion_timeout' + ], + query: [ + 'format' + ] + }, + 'sql.translate': { + path: [], + body: [ + 'fetch_size', + 'filter', + 'query', + 'time_zone' + ], + query: [] + } + } } /** @@ -51,8 +128,12 @@ export default class Sql { async clearCursor (this: That, params: T.SqlClearCursorRequest, options?: TransportRequestOptionsWithMeta): Promise<TransportResult<T.SqlClearCursorResponse, unknown>> async clearCursor (this: That, params: T.SqlClearCursorRequest, options?: TransportRequestOptions): Promise<T.SqlClearCursorResponse> async clearCursor (this: That, params: T.SqlClearCursorRequest, options?: TransportRequestOptions): Promise<any> { - const acceptedPath: string[] = [] - const acceptedBody: string[] = ['cursor'] + const { + path: acceptedPath, + body: acceptedBody, + query: acceptedQuery + } = this.acceptedParams['sql.clear_cursor'] + const userQuery = params?.querystring const querystring: Record<string, any> = userQuery != null ? { ...userQuery } : {} @@ -74,8 +155,14 @@ export default class Sql { } else if (acceptedPath.includes(key)) { continue } else if (key !== 'body' && key !== 'querystring') { - // @ts-expect-error - querystring[key] = params[key] + if (acceptedQuery.includes(key) || commonQueryParams.includes(key)) { + // @ts-expect-error + querystring[key] = params[key] + } else { + body = body ?? {} + // @ts-expect-error + body[key] = params[key] + } } } @@ -95,7 +182,10 @@ export default class Sql { async deleteAsync (this: That, params: T.SqlDeleteAsyncRequest, options?: TransportRequestOptionsWithMeta): Promise<TransportResult<T.SqlDeleteAsyncResponse, unknown>> async deleteAsync (this: That, params: T.SqlDeleteAsyncRequest, options?: TransportRequestOptions): Promise<T.SqlDeleteAsyncResponse> async deleteAsync (this: That, params: T.SqlDeleteAsyncRequest, options?: TransportRequestOptions): Promise<any> { - const acceptedPath: string[] = ['id'] + const { + path: acceptedPath + } = this.acceptedParams['sql.delete_async'] + const userQuery = params?.querystring const querystring: Record<string, any> = userQuery != null ? { ...userQuery } : {} @@ -137,7 +227,10 @@ export default class Sql { async getAsync (this: That, params: T.SqlGetAsyncRequest, options?: TransportRequestOptionsWithMeta): Promise<TransportResult<T.SqlGetAsyncResponse, unknown>> async getAsync (this: That, params: T.SqlGetAsyncRequest, options?: TransportRequestOptions): Promise<T.SqlGetAsyncResponse> async getAsync (this: That, params: T.SqlGetAsyncRequest, options?: TransportRequestOptions): Promise<any> { - const acceptedPath: string[] = ['id'] + const { + path: acceptedPath + } = this.acceptedParams['sql.get_async'] + const userQuery = params?.querystring const querystring: Record<string, any> = userQuery != null ? { ...userQuery } : {} @@ -179,7 +272,10 @@ export default class Sql { async getAsyncStatus (this: That, params: T.SqlGetAsyncStatusRequest, options?: TransportRequestOptionsWithMeta): Promise<TransportResult<T.SqlGetAsyncStatusResponse, unknown>> async getAsyncStatus (this: That, params: T.SqlGetAsyncStatusRequest, options?: TransportRequestOptions): Promise<T.SqlGetAsyncStatusResponse> async getAsyncStatus (this: That, params: T.SqlGetAsyncStatusRequest, options?: TransportRequestOptions): Promise<any> { - const acceptedPath: string[] = ['id'] + const { + path: acceptedPath + } = this.acceptedParams['sql.get_async_status'] + const userQuery = params?.querystring const querystring: Record<string, any> = userQuery != null ? { ...userQuery } : {} @@ -221,8 +317,12 @@ export default class Sql { async query (this: That, params?: T.SqlQueryRequest, options?: TransportRequestOptionsWithMeta): Promise<TransportResult<T.SqlQueryResponse, unknown>> async query (this: That, params?: T.SqlQueryRequest, options?: TransportRequestOptions): Promise<T.SqlQueryResponse> async query (this: That, params?: T.SqlQueryRequest, options?: TransportRequestOptions): Promise<any> { - const acceptedPath: string[] = [] - const acceptedBody: string[] = ['allow_partial_search_results', 'catalog', 'columnar', 'cursor', 'fetch_size', 'field_multi_value_leniency', 'filter', 'index_using_frozen', 'keep_alive', 'keep_on_completion', 'page_timeout', 'params', 'query', 'request_timeout', 'runtime_mappings', 'time_zone', 'wait_for_completion_timeout'] + const { + path: acceptedPath, + body: acceptedBody, + query: acceptedQuery + } = this.acceptedParams['sql.query'] + const userQuery = params?.querystring const querystring: Record<string, any> = userQuery != null ? { ...userQuery } : {} @@ -245,8 +345,14 @@ export default class Sql { } else if (acceptedPath.includes(key)) { continue } else if (key !== 'body' && key !== 'querystring') { - // @ts-expect-error - querystring[key] = params[key] + if (acceptedQuery.includes(key) || commonQueryParams.includes(key)) { + // @ts-expect-error + querystring[key] = params[key] + } else { + body = body ?? {} + // @ts-expect-error + body[key] = params[key] + } } } @@ -266,8 +372,12 @@ export default class Sql { async translate (this: That, params: T.SqlTranslateRequest, options?: TransportRequestOptionsWithMeta): Promise<TransportResult<T.SqlTranslateResponse, unknown>> async translate (this: That, params: T.SqlTranslateRequest, options?: TransportRequestOptions): Promise<T.SqlTranslateResponse> async translate (this: That, params: T.SqlTranslateRequest, options?: TransportRequestOptions): Promise<any> { - const acceptedPath: string[] = [] - const acceptedBody: string[] = ['fetch_size', 'filter', 'query', 'time_zone'] + const { + path: acceptedPath, + body: acceptedBody, + query: acceptedQuery + } = this.acceptedParams['sql.translate'] + const userQuery = params?.querystring const querystring: Record<string, any> = userQuery != null ? { ...userQuery } : {} @@ -289,8 +399,14 @@ export default class Sql { } else if (acceptedPath.includes(key)) { continue } else if (key !== 'body' && key !== 'querystring') { - // @ts-expect-error - querystring[key] = params[key] + if (acceptedQuery.includes(key) || commonQueryParams.includes(key)) { + // @ts-expect-error + querystring[key] = params[key] + } else { + body = body ?? {} + // @ts-expect-error + body[key] = params[key] + } } } diff --git a/src/api/api/ssl.ts b/src/api/api/ssl.ts index 29f25f090..6197e6805 100644 --- a/src/api/api/ssl.ts +++ b/src/api/api/ssl.ts @@ -35,12 +35,24 @@ import { TransportResult } from '@elastic/transport' import * as T from '../types' -interface That { transport: Transport } + +interface That { + transport: Transport + acceptedParams: Record<string, { path: string[], body: string[], query: string[] }> +} export default class Ssl { transport: Transport + acceptedParams: Record<string, { path: string[], body: string[], query: string[] }> constructor (transport: Transport) { this.transport = transport + this.acceptedParams = { + 'ssl.certificates': { + path: [], + body: [], + query: [] + } + } } /** @@ -51,7 +63,10 @@ export default class Ssl { async certificates (this: That, params?: T.SslCertificatesRequest, options?: TransportRequestOptionsWithMeta): Promise<TransportResult<T.SslCertificatesResponse, unknown>> async certificates (this: That, params?: T.SslCertificatesRequest, options?: TransportRequestOptions): Promise<T.SslCertificatesResponse> async certificates (this: That, params?: T.SslCertificatesRequest, options?: TransportRequestOptions): Promise<any> { - const acceptedPath: string[] = [] + const { + path: acceptedPath + } = this.acceptedParams['ssl.certificates'] + const userQuery = params?.querystring const querystring: Record<string, any> = userQuery != null ? { ...userQuery } : {} diff --git a/src/api/api/synonyms.ts b/src/api/api/synonyms.ts index 379510816..125d5301f 100644 --- a/src/api/api/synonyms.ts +++ b/src/api/api/synonyms.ts @@ -35,12 +35,81 @@ import { TransportResult } from '@elastic/transport' import * as T from '../types' -interface That { transport: Transport } + +interface That { + transport: Transport + acceptedParams: Record<string, { path: string[], body: string[], query: string[] }> +} + +const commonQueryParams = ['error_trace', 'filter_path', 'human', 'pretty'] export default class Synonyms { transport: Transport + acceptedParams: Record<string, { path: string[], body: string[], query: string[] }> constructor (transport: Transport) { this.transport = transport + this.acceptedParams = { + 'synonyms.delete_synonym': { + path: [ + 'id' + ], + body: [], + query: [] + }, + 'synonyms.delete_synonym_rule': { + path: [ + 'set_id', + 'rule_id' + ], + body: [], + query: [] + }, + 'synonyms.get_synonym': { + path: [ + 'id' + ], + body: [], + query: [ + 'from', + 'size' + ] + }, + 'synonyms.get_synonym_rule': { + path: [ + 'set_id', + 'rule_id' + ], + body: [], + query: [] + }, + 'synonyms.get_synonyms_sets': { + path: [], + body: [], + query: [ + 'from', + 'size' + ] + }, + 'synonyms.put_synonym': { + path: [ + 'id' + ], + body: [ + 'synonyms_set' + ], + query: [] + }, + 'synonyms.put_synonym_rule': { + path: [ + 'set_id', + 'rule_id' + ], + body: [ + 'synonyms' + ], + query: [] + } + } } /** @@ -51,7 +120,10 @@ export default class Synonyms { async deleteSynonym (this: That, params: T.SynonymsDeleteSynonymRequest, options?: TransportRequestOptionsWithMeta): Promise<TransportResult<T.SynonymsDeleteSynonymResponse, unknown>> async deleteSynonym (this: That, params: T.SynonymsDeleteSynonymRequest, options?: TransportRequestOptions): Promise<T.SynonymsDeleteSynonymResponse> async deleteSynonym (this: That, params: T.SynonymsDeleteSynonymRequest, options?: TransportRequestOptions): Promise<any> { - const acceptedPath: string[] = ['id'] + const { + path: acceptedPath + } = this.acceptedParams['synonyms.delete_synonym'] + const userQuery = params?.querystring const querystring: Record<string, any> = userQuery != null ? { ...userQuery } : {} @@ -93,7 +165,10 @@ export default class Synonyms { async deleteSynonymRule (this: That, params: T.SynonymsDeleteSynonymRuleRequest, options?: TransportRequestOptionsWithMeta): Promise<TransportResult<T.SynonymsDeleteSynonymRuleResponse, unknown>> async deleteSynonymRule (this: That, params: T.SynonymsDeleteSynonymRuleRequest, options?: TransportRequestOptions): Promise<T.SynonymsDeleteSynonymRuleResponse> async deleteSynonymRule (this: That, params: T.SynonymsDeleteSynonymRuleRequest, options?: TransportRequestOptions): Promise<any> { - const acceptedPath: string[] = ['set_id', 'rule_id'] + const { + path: acceptedPath + } = this.acceptedParams['synonyms.delete_synonym_rule'] + const userQuery = params?.querystring const querystring: Record<string, any> = userQuery != null ? { ...userQuery } : {} @@ -136,7 +211,10 @@ export default class Synonyms { async getSynonym (this: That, params: T.SynonymsGetSynonymRequest, options?: TransportRequestOptionsWithMeta): Promise<TransportResult<T.SynonymsGetSynonymResponse, unknown>> async getSynonym (this: That, params: T.SynonymsGetSynonymRequest, options?: TransportRequestOptions): Promise<T.SynonymsGetSynonymResponse> async getSynonym (this: That, params: T.SynonymsGetSynonymRequest, options?: TransportRequestOptions): Promise<any> { - const acceptedPath: string[] = ['id'] + const { + path: acceptedPath + } = this.acceptedParams['synonyms.get_synonym'] + const userQuery = params?.querystring const querystring: Record<string, any> = userQuery != null ? { ...userQuery } : {} @@ -178,7 +256,10 @@ export default class Synonyms { async getSynonymRule (this: That, params: T.SynonymsGetSynonymRuleRequest, options?: TransportRequestOptionsWithMeta): Promise<TransportResult<T.SynonymsGetSynonymRuleResponse, unknown>> async getSynonymRule (this: That, params: T.SynonymsGetSynonymRuleRequest, options?: TransportRequestOptions): Promise<T.SynonymsGetSynonymRuleResponse> async getSynonymRule (this: That, params: T.SynonymsGetSynonymRuleRequest, options?: TransportRequestOptions): Promise<any> { - const acceptedPath: string[] = ['set_id', 'rule_id'] + const { + path: acceptedPath + } = this.acceptedParams['synonyms.get_synonym_rule'] + const userQuery = params?.querystring const querystring: Record<string, any> = userQuery != null ? { ...userQuery } : {} @@ -221,7 +302,10 @@ export default class Synonyms { async getSynonymsSets (this: That, params?: T.SynonymsGetSynonymsSetsRequest, options?: TransportRequestOptionsWithMeta): Promise<TransportResult<T.SynonymsGetSynonymsSetsResponse, unknown>> async getSynonymsSets (this: That, params?: T.SynonymsGetSynonymsSetsRequest, options?: TransportRequestOptions): Promise<T.SynonymsGetSynonymsSetsResponse> async getSynonymsSets (this: That, params?: T.SynonymsGetSynonymsSetsRequest, options?: TransportRequestOptions): Promise<any> { - const acceptedPath: string[] = [] + const { + path: acceptedPath + } = this.acceptedParams['synonyms.get_synonyms_sets'] + const userQuery = params?.querystring const querystring: Record<string, any> = userQuery != null ? { ...userQuery } : {} @@ -261,8 +345,12 @@ export default class Synonyms { async putSynonym (this: That, params: T.SynonymsPutSynonymRequest, options?: TransportRequestOptionsWithMeta): Promise<TransportResult<T.SynonymsPutSynonymResponse, unknown>> async putSynonym (this: That, params: T.SynonymsPutSynonymRequest, options?: TransportRequestOptions): Promise<T.SynonymsPutSynonymResponse> async putSynonym (this: That, params: T.SynonymsPutSynonymRequest, options?: TransportRequestOptions): Promise<any> { - const acceptedPath: string[] = ['id'] - const acceptedBody: string[] = ['synonyms_set'] + const { + path: acceptedPath, + body: acceptedBody, + query: acceptedQuery + } = this.acceptedParams['synonyms.put_synonym'] + const userQuery = params?.querystring const querystring: Record<string, any> = userQuery != null ? { ...userQuery } : {} @@ -284,8 +372,14 @@ export default class Synonyms { } else if (acceptedPath.includes(key)) { continue } else if (key !== 'body' && key !== 'querystring') { - // @ts-expect-error - querystring[key] = params[key] + if (acceptedQuery.includes(key) || commonQueryParams.includes(key)) { + // @ts-expect-error + querystring[key] = params[key] + } else { + body = body ?? {} + // @ts-expect-error + body[key] = params[key] + } } } @@ -308,8 +402,12 @@ export default class Synonyms { async putSynonymRule (this: That, params: T.SynonymsPutSynonymRuleRequest, options?: TransportRequestOptionsWithMeta): Promise<TransportResult<T.SynonymsPutSynonymRuleResponse, unknown>> async putSynonymRule (this: That, params: T.SynonymsPutSynonymRuleRequest, options?: TransportRequestOptions): Promise<T.SynonymsPutSynonymRuleResponse> async putSynonymRule (this: That, params: T.SynonymsPutSynonymRuleRequest, options?: TransportRequestOptions): Promise<any> { - const acceptedPath: string[] = ['set_id', 'rule_id'] - const acceptedBody: string[] = ['synonyms'] + const { + path: acceptedPath, + body: acceptedBody, + query: acceptedQuery + } = this.acceptedParams['synonyms.put_synonym_rule'] + const userQuery = params?.querystring const querystring: Record<string, any> = userQuery != null ? { ...userQuery } : {} @@ -331,8 +429,14 @@ export default class Synonyms { } else if (acceptedPath.includes(key)) { continue } else if (key !== 'body' && key !== 'querystring') { - // @ts-expect-error - querystring[key] = params[key] + if (acceptedQuery.includes(key) || commonQueryParams.includes(key)) { + // @ts-expect-error + querystring[key] = params[key] + } else { + body = body ?? {} + // @ts-expect-error + body[key] = params[key] + } } } diff --git a/src/api/api/tasks.ts b/src/api/api/tasks.ts index a8f7ccf20..c5da070be 100644 --- a/src/api/api/tasks.ts +++ b/src/api/api/tasks.ts @@ -35,12 +35,54 @@ import { TransportResult } from '@elastic/transport' import * as T from '../types' -interface That { transport: Transport } + +interface That { + transport: Transport + acceptedParams: Record<string, { path: string[], body: string[], query: string[] }> +} export default class Tasks { transport: Transport + acceptedParams: Record<string, { path: string[], body: string[], query: string[] }> constructor (transport: Transport) { this.transport = transport + this.acceptedParams = { + 'tasks.cancel': { + path: [ + 'task_id' + ], + body: [], + query: [ + 'actions', + 'nodes', + 'parent_task_id', + 'wait_for_completion' + ] + }, + 'tasks.get': { + path: [ + 'task_id' + ], + body: [], + query: [ + 'timeout', + 'wait_for_completion' + ] + }, + 'tasks.list': { + path: [], + body: [], + query: [ + 'actions', + 'detailed', + 'group_by', + 'nodes', + 'parent_task_id', + 'timeout', + 'wait_for_completion' + ] + } + } } /** @@ -51,7 +93,10 @@ export default class Tasks { async cancel (this: That, params?: T.TasksCancelRequest, options?: TransportRequestOptionsWithMeta): Promise<TransportResult<T.TasksCancelResponse, unknown>> async cancel (this: That, params?: T.TasksCancelRequest, options?: TransportRequestOptions): Promise<T.TasksCancelResponse> async cancel (this: That, params?: T.TasksCancelRequest, options?: TransportRequestOptions): Promise<any> { - const acceptedPath: string[] = ['task_id'] + const { + path: acceptedPath + } = this.acceptedParams['tasks.cancel'] + const userQuery = params?.querystring const querystring: Record<string, any> = userQuery != null ? { ...userQuery } : {} @@ -101,7 +146,10 @@ export default class Tasks { async get (this: That, params: T.TasksGetRequest, options?: TransportRequestOptionsWithMeta): Promise<TransportResult<T.TasksGetResponse, unknown>> async get (this: That, params: T.TasksGetRequest, options?: TransportRequestOptions): Promise<T.TasksGetResponse> async get (this: That, params: T.TasksGetRequest, options?: TransportRequestOptions): Promise<any> { - const acceptedPath: string[] = ['task_id'] + const { + path: acceptedPath + } = this.acceptedParams['tasks.get'] + const userQuery = params?.querystring const querystring: Record<string, any> = userQuery != null ? { ...userQuery } : {} @@ -143,7 +191,10 @@ export default class Tasks { async list (this: That, params?: T.TasksListRequest, options?: TransportRequestOptionsWithMeta): Promise<TransportResult<T.TasksListResponse, unknown>> async list (this: That, params?: T.TasksListRequest, options?: TransportRequestOptions): Promise<T.TasksListResponse> async list (this: That, params?: T.TasksListRequest, options?: TransportRequestOptions): Promise<any> { - const acceptedPath: string[] = [] + const { + path: acceptedPath + } = this.acceptedParams['tasks.list'] + const userQuery = params?.querystring const querystring: Record<string, any> = userQuery != null ? { ...userQuery } : {} diff --git a/src/api/api/terms_enum.ts b/src/api/api/terms_enum.ts index ad9fa1e0e..38a264ef8 100644 --- a/src/api/api/terms_enum.ts +++ b/src/api/api/terms_enum.ts @@ -35,7 +35,30 @@ import { TransportResult } from '@elastic/transport' import * as T from '../types' -interface That { transport: Transport } + +interface That { + transport: Transport +} + +const commonQueryParams = ['error_trace', 'filter_path', 'human', 'pretty'] + +const acceptedParams: Record<string, { path: string[], body: string[], query: string[] }> = { + terms_enum: { + path: [ + 'index' + ], + body: [ + 'field', + 'size', + 'timeout', + 'case_insensitive', + 'index_filter', + 'string', + 'search_after' + ], + query: [] + } +} /** * Get terms in an index. Discover terms that match a partial string in an index. This API is designed for low-latency look-ups used in auto-complete scenarios. > info > The terms enum API may return terms from deleted documents. Deleted documents are initially only marked as deleted. It is not until their segments are merged that documents are actually deleted. Until that happens, the terms enum API will return terms from these documents. @@ -45,8 +68,12 @@ export default async function TermsEnumApi (this: That, params: T.TermsEnumReque export default async function TermsEnumApi (this: That, params: T.TermsEnumRequest, options?: TransportRequestOptionsWithMeta): Promise<TransportResult<T.TermsEnumResponse, unknown>> export default async function TermsEnumApi (this: That, params: T.TermsEnumRequest, options?: TransportRequestOptions): Promise<T.TermsEnumResponse> export default async function TermsEnumApi (this: That, params: T.TermsEnumRequest, options?: TransportRequestOptions): Promise<any> { - const acceptedPath: string[] = ['index'] - const acceptedBody: string[] = ['field', 'size', 'timeout', 'case_insensitive', 'index_filter', 'string', 'search_after'] + const { + path: acceptedPath, + body: acceptedBody, + query: acceptedQuery + } = acceptedParams.terms_enum + const userQuery = params?.querystring const querystring: Record<string, any> = userQuery != null ? { ...userQuery } : {} @@ -68,8 +95,14 @@ export default async function TermsEnumApi (this: That, params: T.TermsEnumReque } else if (acceptedPath.includes(key)) { continue } else if (key !== 'body' && key !== 'querystring') { - // @ts-expect-error - querystring[key] = params[key] + if (acceptedQuery.includes(key) || commonQueryParams.includes(key)) { + // @ts-expect-error + querystring[key] = params[key] + } else { + body = body ?? {} + // @ts-expect-error + body[key] = params[key] + } } } diff --git a/src/api/api/termvectors.ts b/src/api/api/termvectors.ts index c3f461487..331e9fe69 100644 --- a/src/api/api/termvectors.ts +++ b/src/api/api/termvectors.ts @@ -35,7 +35,39 @@ import { TransportResult } from '@elastic/transport' import * as T from '../types' -interface That { transport: Transport } + +interface That { + transport: Transport +} + +const commonQueryParams = ['error_trace', 'filter_path', 'human', 'pretty'] + +const acceptedParams: Record<string, { path: string[], body: string[], query: string[] }> = { + termvectors: { + path: [ + 'index', + 'id' + ], + body: [ + 'doc', + 'filter', + 'per_field_analyzer' + ], + query: [ + 'fields', + 'field_statistics', + 'offsets', + 'payloads', + 'positions', + 'preference', + 'realtime', + 'routing', + 'term_statistics', + 'version', + 'version_type' + ] + } +} /** * Get term vector information. Get information and statistics about terms in the fields of a particular document. You can retrieve term vectors for documents stored in the index or for artificial documents passed in the body of the request. You can specify the fields you are interested in through the `fields` parameter or by adding the fields to the request body. For example: ``` GET /my-index-000001/_termvectors/1?fields=message ``` Fields can be specified using wildcards, similar to the multi match query. Term vectors are real-time by default, not near real-time. This can be changed by setting `realtime` parameter to `false`. You can request three types of values: _term information_, _term statistics_, and _field statistics_. By default, all term information and field statistics are returned for all fields but term statistics are excluded. **Term information** * term frequency in the field (always returned) * term positions (`positions: true`) * start and end offsets (`offsets: true`) * term payloads (`payloads: true`), as base64 encoded bytes If the requested information wasn't stored in the index, it will be computed on the fly if possible. Additionally, term vectors could be computed for documents not even existing in the index, but instead provided by the user. > warn > Start and end offsets assume UTF-16 encoding is being used. If you want to use these offsets in order to get the original text that produced this token, you should make sure that the string you are taking a sub-string of is also encoded using UTF-16. **Behaviour** The term and field statistics are not accurate. Deleted documents are not taken into account. The information is only retrieved for the shard the requested document resides in. The term and field statistics are therefore only useful as relative measures whereas the absolute numbers have no meaning in this context. By default, when requesting term vectors of artificial documents, a shard to get the statistics from is randomly selected. Use `routing` only to hit a particular shard. @@ -45,8 +77,12 @@ export default async function TermvectorsApi<TDocument = unknown> (this: That, p export default async function TermvectorsApi<TDocument = unknown> (this: That, params: T.TermvectorsRequest<TDocument>, options?: TransportRequestOptionsWithMeta): Promise<TransportResult<T.TermvectorsResponse, unknown>> export default async function TermvectorsApi<TDocument = unknown> (this: That, params: T.TermvectorsRequest<TDocument>, options?: TransportRequestOptions): Promise<T.TermvectorsResponse> export default async function TermvectorsApi<TDocument = unknown> (this: That, params: T.TermvectorsRequest<TDocument>, options?: TransportRequestOptions): Promise<any> { - const acceptedPath: string[] = ['index', 'id'] - const acceptedBody: string[] = ['doc', 'filter', 'per_field_analyzer'] + const { + path: acceptedPath, + body: acceptedBody, + query: acceptedQuery + } = acceptedParams.termvectors + const userQuery = params?.querystring const querystring: Record<string, any> = userQuery != null ? { ...userQuery } : {} @@ -68,8 +104,14 @@ export default async function TermvectorsApi<TDocument = unknown> (this: That, p } else if (acceptedPath.includes(key)) { continue } else if (key !== 'body' && key !== 'querystring') { - // @ts-expect-error - querystring[key] = params[key] + if (acceptedQuery.includes(key) || commonQueryParams.includes(key)) { + // @ts-expect-error + querystring[key] = params[key] + } else { + body = body ?? {} + // @ts-expect-error + body[key] = params[key] + } } } diff --git a/src/api/api/text_structure.ts b/src/api/api/text_structure.ts index fd245e577..7d18c5f3b 100644 --- a/src/api/api/text_structure.ts +++ b/src/api/api/text_structure.ts @@ -35,12 +35,93 @@ import { TransportResult } from '@elastic/transport' import * as T from '../types' -interface That { transport: Transport } + +interface That { + transport: Transport + acceptedParams: Record<string, { path: string[], body: string[], query: string[] }> +} + +const commonQueryParams = ['error_trace', 'filter_path', 'human', 'pretty'] export default class TextStructure { transport: Transport + acceptedParams: Record<string, { path: string[], body: string[], query: string[] }> constructor (transport: Transport) { this.transport = transport + this.acceptedParams = { + 'text_structure.find_field_structure': { + path: [], + body: [], + query: [ + 'column_names', + 'delimiter', + 'documents_to_sample', + 'ecs_compatibility', + 'explain', + 'field', + 'format', + 'grok_pattern', + 'index', + 'quote', + 'should_trim_fields', + 'timeout', + 'timestamp_field', + 'timestamp_format' + ] + }, + 'text_structure.find_message_structure': { + path: [], + body: [ + 'messages' + ], + query: [ + 'column_names', + 'delimiter', + 'ecs_compatibility', + 'explain', + 'format', + 'grok_pattern', + 'quote', + 'should_trim_fields', + 'timeout', + 'timestamp_field', + 'timestamp_format' + ] + }, + 'text_structure.find_structure': { + path: [], + body: [ + 'text_files' + ], + query: [ + 'charset', + 'column_names', + 'delimiter', + 'ecs_compatibility', + 'explain', + 'format', + 'grok_pattern', + 'has_header_row', + 'line_merge_size_limit', + 'lines_to_sample', + 'quote', + 'should_trim_fields', + 'timeout', + 'timestamp_field', + 'timestamp_format' + ] + }, + 'text_structure.test_grok_pattern': { + path: [], + body: [ + 'grok_pattern', + 'text' + ], + query: [ + 'ecs_compatibility' + ] + } + } } /** @@ -51,7 +132,10 @@ export default class TextStructure { async findFieldStructure (this: That, params: T.TextStructureFindFieldStructureRequest, options?: TransportRequestOptionsWithMeta): Promise<TransportResult<T.TextStructureFindFieldStructureResponse, unknown>> async findFieldStructure (this: That, params: T.TextStructureFindFieldStructureRequest, options?: TransportRequestOptions): Promise<T.TextStructureFindFieldStructureResponse> async findFieldStructure (this: That, params: T.TextStructureFindFieldStructureRequest, options?: TransportRequestOptions): Promise<any> { - const acceptedPath: string[] = [] + const { + path: acceptedPath + } = this.acceptedParams['text_structure.find_field_structure'] + const userQuery = params?.querystring const querystring: Record<string, any> = userQuery != null ? { ...userQuery } : {} @@ -90,8 +174,12 @@ export default class TextStructure { async findMessageStructure (this: That, params: T.TextStructureFindMessageStructureRequest, options?: TransportRequestOptionsWithMeta): Promise<TransportResult<T.TextStructureFindMessageStructureResponse, unknown>> async findMessageStructure (this: That, params: T.TextStructureFindMessageStructureRequest, options?: TransportRequestOptions): Promise<T.TextStructureFindMessageStructureResponse> async findMessageStructure (this: That, params: T.TextStructureFindMessageStructureRequest, options?: TransportRequestOptions): Promise<any> { - const acceptedPath: string[] = [] - const acceptedBody: string[] = ['messages'] + const { + path: acceptedPath, + body: acceptedBody, + query: acceptedQuery + } = this.acceptedParams['text_structure.find_message_structure'] + const userQuery = params?.querystring const querystring: Record<string, any> = userQuery != null ? { ...userQuery } : {} @@ -113,8 +201,14 @@ export default class TextStructure { } else if (acceptedPath.includes(key)) { continue } else if (key !== 'body' && key !== 'querystring') { - // @ts-expect-error - querystring[key] = params[key] + if (acceptedQuery.includes(key) || commonQueryParams.includes(key)) { + // @ts-expect-error + querystring[key] = params[key] + } else { + body = body ?? {} + // @ts-expect-error + body[key] = params[key] + } } } @@ -134,8 +228,12 @@ export default class TextStructure { async findStructure<TJsonDocument = unknown> (this: That, params: T.TextStructureFindStructureRequest<TJsonDocument>, options?: TransportRequestOptionsWithMeta): Promise<TransportResult<T.TextStructureFindStructureResponse, unknown>> async findStructure<TJsonDocument = unknown> (this: That, params: T.TextStructureFindStructureRequest<TJsonDocument>, options?: TransportRequestOptions): Promise<T.TextStructureFindStructureResponse> async findStructure<TJsonDocument = unknown> (this: That, params: T.TextStructureFindStructureRequest<TJsonDocument>, options?: TransportRequestOptions): Promise<any> { - const acceptedPath: string[] = [] - const acceptedBody: string[] = ['text_files'] + const { + path: acceptedPath, + body: acceptedBody, + query: acceptedQuery + } = this.acceptedParams['text_structure.find_structure'] + const userQuery = params?.querystring const querystring: Record<string, any> = userQuery != null ? { ...userQuery } : {} @@ -147,8 +245,14 @@ export default class TextStructure { } else if (acceptedPath.includes(key)) { continue } else if (key !== 'body' && key !== 'querystring') { - // @ts-expect-error - querystring[key] = params[key] + if (acceptedQuery.includes(key) || commonQueryParams.includes(key)) { + // @ts-expect-error + querystring[key] = params[key] + } else { + body = body ?? {} + // @ts-expect-error + body[key] = params[key] + } } } @@ -168,8 +272,12 @@ export default class TextStructure { async testGrokPattern (this: That, params: T.TextStructureTestGrokPatternRequest, options?: TransportRequestOptionsWithMeta): Promise<TransportResult<T.TextStructureTestGrokPatternResponse, unknown>> async testGrokPattern (this: That, params: T.TextStructureTestGrokPatternRequest, options?: TransportRequestOptions): Promise<T.TextStructureTestGrokPatternResponse> async testGrokPattern (this: That, params: T.TextStructureTestGrokPatternRequest, options?: TransportRequestOptions): Promise<any> { - const acceptedPath: string[] = [] - const acceptedBody: string[] = ['grok_pattern', 'text'] + const { + path: acceptedPath, + body: acceptedBody, + query: acceptedQuery + } = this.acceptedParams['text_structure.test_grok_pattern'] + const userQuery = params?.querystring const querystring: Record<string, any> = userQuery != null ? { ...userQuery } : {} @@ -191,8 +299,14 @@ export default class TextStructure { } else if (acceptedPath.includes(key)) { continue } else if (key !== 'body' && key !== 'querystring') { - // @ts-expect-error - querystring[key] = params[key] + if (acceptedQuery.includes(key) || commonQueryParams.includes(key)) { + // @ts-expect-error + querystring[key] = params[key] + } else { + body = body ?? {} + // @ts-expect-error + body[key] = params[key] + } } } diff --git a/src/api/api/transform.ts b/src/api/api/transform.ts index 4872de3e1..4e168f30b 100644 --- a/src/api/api/transform.ts +++ b/src/api/api/transform.ts @@ -35,12 +35,170 @@ import { TransportResult } from '@elastic/transport' import * as T from '../types' -interface That { transport: Transport } + +interface That { + transport: Transport + acceptedParams: Record<string, { path: string[], body: string[], query: string[] }> +} + +const commonQueryParams = ['error_trace', 'filter_path', 'human', 'pretty'] export default class Transform { transport: Transport + acceptedParams: Record<string, { path: string[], body: string[], query: string[] }> constructor (transport: Transport) { this.transport = transport + this.acceptedParams = { + 'transform.delete_transform': { + path: [ + 'transform_id' + ], + body: [], + query: [ + 'force', + 'delete_dest_index', + 'timeout' + ] + }, + 'transform.get_node_stats': { + path: [], + body: [], + query: [] + }, + 'transform.get_transform': { + path: [ + 'transform_id' + ], + body: [], + query: [ + 'allow_no_match', + 'from', + 'size', + 'exclude_generated' + ] + }, + 'transform.get_transform_stats': { + path: [ + 'transform_id' + ], + body: [], + query: [ + 'allow_no_match', + 'from', + 'size', + 'timeout' + ] + }, + 'transform.preview_transform': { + path: [ + 'transform_id' + ], + body: [ + 'dest', + 'description', + 'frequency', + 'pivot', + 'source', + 'settings', + 'sync', + 'retention_policy', + 'latest' + ], + query: [ + 'timeout' + ] + }, + 'transform.put_transform': { + path: [ + 'transform_id' + ], + body: [ + 'dest', + 'description', + 'frequency', + 'latest', + '_meta', + 'pivot', + 'retention_policy', + 'settings', + 'source', + 'sync' + ], + query: [ + 'defer_validation', + 'timeout' + ] + }, + 'transform.reset_transform': { + path: [ + 'transform_id' + ], + body: [], + query: [ + 'force', + 'timeout' + ] + }, + 'transform.schedule_now_transform': { + path: [ + 'transform_id' + ], + body: [], + query: [ + 'timeout' + ] + }, + 'transform.start_transform': { + path: [ + 'transform_id' + ], + body: [], + query: [ + 'timeout', + 'from' + ] + }, + 'transform.stop_transform': { + path: [ + 'transform_id' + ], + body: [], + query: [ + 'allow_no_match', + 'force', + 'timeout', + 'wait_for_checkpoint', + 'wait_for_completion' + ] + }, + 'transform.update_transform': { + path: [ + 'transform_id' + ], + body: [ + 'dest', + 'description', + 'frequency', + '_meta', + 'source', + 'settings', + 'sync', + 'retention_policy' + ], + query: [ + 'defer_validation', + 'timeout' + ] + }, + 'transform.upgrade_transforms': { + path: [], + body: [], + query: [ + 'dry_run', + 'timeout' + ] + } + } } /** @@ -51,7 +209,10 @@ export default class Transform { async deleteTransform (this: That, params: T.TransformDeleteTransformRequest, options?: TransportRequestOptionsWithMeta): Promise<TransportResult<T.TransformDeleteTransformResponse, unknown>> async deleteTransform (this: That, params: T.TransformDeleteTransformRequest, options?: TransportRequestOptions): Promise<T.TransformDeleteTransformResponse> async deleteTransform (this: That, params: T.TransformDeleteTransformRequest, options?: TransportRequestOptions): Promise<any> { - const acceptedPath: string[] = ['transform_id'] + const { + path: acceptedPath + } = this.acceptedParams['transform.delete_transform'] + const userQuery = params?.querystring const querystring: Record<string, any> = userQuery != null ? { ...userQuery } : {} @@ -93,7 +254,10 @@ export default class Transform { async getNodeStats (this: That, params?: T.TODO, options?: TransportRequestOptionsWithMeta): Promise<TransportResult<T.TODO, unknown>> async getNodeStats (this: That, params?: T.TODO, options?: TransportRequestOptions): Promise<T.TODO> async getNodeStats (this: That, params?: T.TODO, options?: TransportRequestOptions): Promise<any> { - const acceptedPath: string[] = [] + const { + path: acceptedPath + } = this.acceptedParams['transform.get_node_stats'] + const userQuery = params?.querystring const querystring: Record<string, any> = userQuery != null ? { ...userQuery } : {} @@ -132,7 +296,10 @@ export default class Transform { async getTransform (this: That, params?: T.TransformGetTransformRequest, options?: TransportRequestOptionsWithMeta): Promise<TransportResult<T.TransformGetTransformResponse, unknown>> async getTransform (this: That, params?: T.TransformGetTransformRequest, options?: TransportRequestOptions): Promise<T.TransformGetTransformResponse> async getTransform (this: That, params?: T.TransformGetTransformRequest, options?: TransportRequestOptions): Promise<any> { - const acceptedPath: string[] = ['transform_id'] + const { + path: acceptedPath + } = this.acceptedParams['transform.get_transform'] + const userQuery = params?.querystring const querystring: Record<string, any> = userQuery != null ? { ...userQuery } : {} @@ -182,7 +349,10 @@ export default class Transform { async getTransformStats (this: That, params: T.TransformGetTransformStatsRequest, options?: TransportRequestOptionsWithMeta): Promise<TransportResult<T.TransformGetTransformStatsResponse, unknown>> async getTransformStats (this: That, params: T.TransformGetTransformStatsRequest, options?: TransportRequestOptions): Promise<T.TransformGetTransformStatsResponse> async getTransformStats (this: That, params: T.TransformGetTransformStatsRequest, options?: TransportRequestOptions): Promise<any> { - const acceptedPath: string[] = ['transform_id'] + const { + path: acceptedPath + } = this.acceptedParams['transform.get_transform_stats'] + const userQuery = params?.querystring const querystring: Record<string, any> = userQuery != null ? { ...userQuery } : {} @@ -224,8 +394,12 @@ export default class Transform { async previewTransform<TTransform = unknown> (this: That, params?: T.TransformPreviewTransformRequest, options?: TransportRequestOptionsWithMeta): Promise<TransportResult<T.TransformPreviewTransformResponse<TTransform>, unknown>> async previewTransform<TTransform = unknown> (this: That, params?: T.TransformPreviewTransformRequest, options?: TransportRequestOptions): Promise<T.TransformPreviewTransformResponse<TTransform>> async previewTransform<TTransform = unknown> (this: That, params?: T.TransformPreviewTransformRequest, options?: TransportRequestOptions): Promise<any> { - const acceptedPath: string[] = ['transform_id'] - const acceptedBody: string[] = ['dest', 'description', 'frequency', 'pivot', 'source', 'settings', 'sync', 'retention_policy', 'latest'] + const { + path: acceptedPath, + body: acceptedBody, + query: acceptedQuery + } = this.acceptedParams['transform.preview_transform'] + const userQuery = params?.querystring const querystring: Record<string, any> = userQuery != null ? { ...userQuery } : {} @@ -248,8 +422,14 @@ export default class Transform { } else if (acceptedPath.includes(key)) { continue } else if (key !== 'body' && key !== 'querystring') { - // @ts-expect-error - querystring[key] = params[key] + if (acceptedQuery.includes(key) || commonQueryParams.includes(key)) { + // @ts-expect-error + querystring[key] = params[key] + } else { + body = body ?? {} + // @ts-expect-error + body[key] = params[key] + } } } @@ -279,8 +459,12 @@ export default class Transform { async putTransform (this: That, params: T.TransformPutTransformRequest, options?: TransportRequestOptionsWithMeta): Promise<TransportResult<T.TransformPutTransformResponse, unknown>> async putTransform (this: That, params: T.TransformPutTransformRequest, options?: TransportRequestOptions): Promise<T.TransformPutTransformResponse> async putTransform (this: That, params: T.TransformPutTransformRequest, options?: TransportRequestOptions): Promise<any> { - const acceptedPath: string[] = ['transform_id'] - const acceptedBody: string[] = ['dest', 'description', 'frequency', 'latest', '_meta', 'pivot', 'retention_policy', 'settings', 'source', 'sync'] + const { + path: acceptedPath, + body: acceptedBody, + query: acceptedQuery + } = this.acceptedParams['transform.put_transform'] + const userQuery = params?.querystring const querystring: Record<string, any> = userQuery != null ? { ...userQuery } : {} @@ -302,8 +486,14 @@ export default class Transform { } else if (acceptedPath.includes(key)) { continue } else if (key !== 'body' && key !== 'querystring') { - // @ts-expect-error - querystring[key] = params[key] + if (acceptedQuery.includes(key) || commonQueryParams.includes(key)) { + // @ts-expect-error + querystring[key] = params[key] + } else { + body = body ?? {} + // @ts-expect-error + body[key] = params[key] + } } } @@ -326,7 +516,10 @@ export default class Transform { async resetTransform (this: That, params: T.TransformResetTransformRequest, options?: TransportRequestOptionsWithMeta): Promise<TransportResult<T.TransformResetTransformResponse, unknown>> async resetTransform (this: That, params: T.TransformResetTransformRequest, options?: TransportRequestOptions): Promise<T.TransformResetTransformResponse> async resetTransform (this: That, params: T.TransformResetTransformRequest, options?: TransportRequestOptions): Promise<any> { - const acceptedPath: string[] = ['transform_id'] + const { + path: acceptedPath + } = this.acceptedParams['transform.reset_transform'] + const userQuery = params?.querystring const querystring: Record<string, any> = userQuery != null ? { ...userQuery } : {} @@ -368,7 +561,10 @@ export default class Transform { async scheduleNowTransform (this: That, params: T.TransformScheduleNowTransformRequest, options?: TransportRequestOptionsWithMeta): Promise<TransportResult<T.TransformScheduleNowTransformResponse, unknown>> async scheduleNowTransform (this: That, params: T.TransformScheduleNowTransformRequest, options?: TransportRequestOptions): Promise<T.TransformScheduleNowTransformResponse> async scheduleNowTransform (this: That, params: T.TransformScheduleNowTransformRequest, options?: TransportRequestOptions): Promise<any> { - const acceptedPath: string[] = ['transform_id'] + const { + path: acceptedPath + } = this.acceptedParams['transform.schedule_now_transform'] + const userQuery = params?.querystring const querystring: Record<string, any> = userQuery != null ? { ...userQuery } : {} @@ -410,7 +606,10 @@ export default class Transform { async startTransform (this: That, params: T.TransformStartTransformRequest, options?: TransportRequestOptionsWithMeta): Promise<TransportResult<T.TransformStartTransformResponse, unknown>> async startTransform (this: That, params: T.TransformStartTransformRequest, options?: TransportRequestOptions): Promise<T.TransformStartTransformResponse> async startTransform (this: That, params: T.TransformStartTransformRequest, options?: TransportRequestOptions): Promise<any> { - const acceptedPath: string[] = ['transform_id'] + const { + path: acceptedPath + } = this.acceptedParams['transform.start_transform'] + const userQuery = params?.querystring const querystring: Record<string, any> = userQuery != null ? { ...userQuery } : {} @@ -452,7 +651,10 @@ export default class Transform { async stopTransform (this: That, params: T.TransformStopTransformRequest, options?: TransportRequestOptionsWithMeta): Promise<TransportResult<T.TransformStopTransformResponse, unknown>> async stopTransform (this: That, params: T.TransformStopTransformRequest, options?: TransportRequestOptions): Promise<T.TransformStopTransformResponse> async stopTransform (this: That, params: T.TransformStopTransformRequest, options?: TransportRequestOptions): Promise<any> { - const acceptedPath: string[] = ['transform_id'] + const { + path: acceptedPath + } = this.acceptedParams['transform.stop_transform'] + const userQuery = params?.querystring const querystring: Record<string, any> = userQuery != null ? { ...userQuery } : {} @@ -494,8 +696,12 @@ export default class Transform { async updateTransform (this: That, params: T.TransformUpdateTransformRequest, options?: TransportRequestOptionsWithMeta): Promise<TransportResult<T.TransformUpdateTransformResponse, unknown>> async updateTransform (this: That, params: T.TransformUpdateTransformRequest, options?: TransportRequestOptions): Promise<T.TransformUpdateTransformResponse> async updateTransform (this: That, params: T.TransformUpdateTransformRequest, options?: TransportRequestOptions): Promise<any> { - const acceptedPath: string[] = ['transform_id'] - const acceptedBody: string[] = ['dest', 'description', 'frequency', '_meta', 'source', 'settings', 'sync', 'retention_policy'] + const { + path: acceptedPath, + body: acceptedBody, + query: acceptedQuery + } = this.acceptedParams['transform.update_transform'] + const userQuery = params?.querystring const querystring: Record<string, any> = userQuery != null ? { ...userQuery } : {} @@ -517,8 +723,14 @@ export default class Transform { } else if (acceptedPath.includes(key)) { continue } else if (key !== 'body' && key !== 'querystring') { - // @ts-expect-error - querystring[key] = params[key] + if (acceptedQuery.includes(key) || commonQueryParams.includes(key)) { + // @ts-expect-error + querystring[key] = params[key] + } else { + body = body ?? {} + // @ts-expect-error + body[key] = params[key] + } } } @@ -541,7 +753,10 @@ export default class Transform { async upgradeTransforms (this: That, params?: T.TransformUpgradeTransformsRequest, options?: TransportRequestOptionsWithMeta): Promise<TransportResult<T.TransformUpgradeTransformsResponse, unknown>> async upgradeTransforms (this: That, params?: T.TransformUpgradeTransformsRequest, options?: TransportRequestOptions): Promise<T.TransformUpgradeTransformsResponse> async upgradeTransforms (this: That, params?: T.TransformUpgradeTransformsRequest, options?: TransportRequestOptions): Promise<any> { - const acceptedPath: string[] = [] + const { + path: acceptedPath + } = this.acceptedParams['transform.upgrade_transforms'] + const userQuery = params?.querystring const querystring: Record<string, any> = userQuery != null ? { ...userQuery } : {} diff --git a/src/api/api/update.ts b/src/api/api/update.ts index 06d06ae63..64419582a 100644 --- a/src/api/api/update.ts +++ b/src/api/api/update.ts @@ -35,7 +35,45 @@ import { TransportResult } from '@elastic/transport' import * as T from '../types' -interface That { transport: Transport } + +interface That { + transport: Transport +} + +const commonQueryParams = ['error_trace', 'filter_path', 'human', 'pretty'] + +const acceptedParams: Record<string, { path: string[], body: string[], query: string[] }> = { + update: { + path: [ + 'id', + 'index' + ], + body: [ + 'detect_noop', + 'doc', + 'doc_as_upsert', + 'script', + 'scripted_upsert', + '_source', + 'upsert' + ], + query: [ + 'if_primary_term', + 'if_seq_no', + 'include_source_on_error', + 'lang', + 'refresh', + 'require_alias', + 'retry_on_conflict', + 'routing', + 'timeout', + 'wait_for_active_shards', + '_source', + '_source_excludes', + '_source_includes' + ] + } +} /** * Update a document. Update a document by running a script or passing a partial document. If the Elasticsearch security features are enabled, you must have the `index` or `write` index privilege for the target index or index alias. The script can update, delete, or skip modifying the document. The API also supports passing a partial document, which is merged into the existing document. To fully replace an existing document, use the index API. This operation: * Gets the document (collocated with the shard) from the index. * Runs the specified script. * Indexes the result. The document must still be reindexed, but using this API removes some network roundtrips and reduces chances of version conflicts between the GET and the index operation. The `_source` field must be enabled to use this API. In addition to `_source`, you can access the following variables through the `ctx` map: `_index`, `_type`, `_id`, `_version`, `_routing`, and `_now` (the current timestamp). @@ -45,8 +83,12 @@ export default async function UpdateApi<TDocument = unknown, TPartialDocument = export default async function UpdateApi<TDocument = unknown, TPartialDocument = unknown, TDocumentR = unknown> (this: That, params: T.UpdateRequest<TDocument, TPartialDocument>, options?: TransportRequestOptionsWithMeta): Promise<TransportResult<T.UpdateResponse<TDocumentR>, unknown>> export default async function UpdateApi<TDocument = unknown, TPartialDocument = unknown, TDocumentR = unknown> (this: That, params: T.UpdateRequest<TDocument, TPartialDocument>, options?: TransportRequestOptions): Promise<T.UpdateResponse<TDocumentR>> export default async function UpdateApi<TDocument = unknown, TPartialDocument = unknown, TDocumentR = unknown> (this: That, params: T.UpdateRequest<TDocument, TPartialDocument>, options?: TransportRequestOptions): Promise<any> { - const acceptedPath: string[] = ['id', 'index'] - const acceptedBody: string[] = ['detect_noop', 'doc', 'doc_as_upsert', 'script', 'scripted_upsert', '_source', 'upsert'] + const { + path: acceptedPath, + body: acceptedBody, + query: acceptedQuery + } = acceptedParams.update + const userQuery = params?.querystring const querystring: Record<string, any> = userQuery != null ? { ...userQuery } : {} @@ -68,8 +110,14 @@ export default async function UpdateApi<TDocument = unknown, TPartialDocument = } else if (acceptedPath.includes(key)) { continue } else if (key !== 'body' && key !== 'querystring') { - // @ts-expect-error - querystring[key] = params[key] + if (acceptedQuery.includes(key) || commonQueryParams.includes(key)) { + // @ts-expect-error + querystring[key] = params[key] + } else { + body = body ?? {} + // @ts-expect-error + body[key] = params[key] + } } } diff --git a/src/api/api/update_by_query.ts b/src/api/api/update_by_query.ts index 38acf4531..c25f27fd0 100644 --- a/src/api/api/update_by_query.ts +++ b/src/api/api/update_by_query.ts @@ -35,7 +35,60 @@ import { TransportResult } from '@elastic/transport' import * as T from '../types' -interface That { transport: Transport } + +interface That { + transport: Transport +} + +const commonQueryParams = ['error_trace', 'filter_path', 'human', 'pretty'] + +const acceptedParams: Record<string, { path: string[], body: string[], query: string[] }> = { + update_by_query: { + path: [ + 'index' + ], + body: [ + 'max_docs', + 'query', + 'script', + 'slice', + 'conflicts' + ], + query: [ + 'allow_no_indices', + 'analyzer', + 'analyze_wildcard', + 'conflicts', + 'default_operator', + 'df', + 'expand_wildcards', + 'from', + 'ignore_unavailable', + 'lenient', + 'max_docs', + 'pipeline', + 'preference', + 'q', + 'refresh', + 'request_cache', + 'requests_per_second', + 'routing', + 'scroll', + 'scroll_size', + 'search_timeout', + 'search_type', + 'slices', + 'sort', + 'stats', + 'terminate_after', + 'timeout', + 'version', + 'version_type', + 'wait_for_active_shards', + 'wait_for_completion' + ] + } +} /** * Update documents. Updates documents that match the specified query. If no query is specified, performs an update on every document in the data stream or index without modifying the source, which is useful for picking up mapping changes. If the Elasticsearch security features are enabled, you must have the following index privileges for the target data stream, index, or alias: * `read` * `index` or `write` You can specify the query criteria in the request URI or the request body using the same syntax as the search API. When you submit an update by query request, Elasticsearch gets a snapshot of the data stream or index when it begins processing the request and updates matching documents using internal versioning. When the versions match, the document is updated and the version number is incremented. If a document changes between the time that the snapshot is taken and the update operation is processed, it results in a version conflict and the operation fails. You can opt to count version conflicts instead of halting and returning by setting `conflicts` to `proceed`. Note that if you opt to count version conflicts, the operation could attempt to update more documents from the source than `max_docs` until it has successfully updated `max_docs` documents or it has gone through every document in the source query. NOTE: Documents with a version equal to 0 cannot be updated using update by query because internal versioning does not support 0 as a valid version number. While processing an update by query request, Elasticsearch performs multiple search requests sequentially to find all of the matching documents. A bulk update request is performed for each batch of matching documents. Any query or update failures cause the update by query request to fail and the failures are shown in the response. Any update requests that completed successfully still stick, they are not rolled back. **Throttling update requests** To control the rate at which update by query issues batches of update operations, you can set `requests_per_second` to any positive decimal number. This pads each batch with a wait time to throttle the rate. Set `requests_per_second` to `-1` to turn off throttling. Throttling uses a wait time between batches so that the internal scroll requests can be given a timeout that takes the request padding into account. The padding time is the difference between the batch size divided by the `requests_per_second` and the time spent writing. By default the batch size is 1000, so if `requests_per_second` is set to `500`: ``` target_time = 1000 / 500 per second = 2 seconds wait_time = target_time - write_time = 2 seconds - .5 seconds = 1.5 seconds ``` Since the batch is issued as a single _bulk request, large batch sizes cause Elasticsearch to create many requests and wait before starting the next set. This is "bursty" instead of "smooth". **Slicing** Update by query supports sliced scroll to parallelize the update process. This can improve efficiency and provide a convenient way to break the request down into smaller parts. Setting `slices` to `auto` chooses a reasonable number for most data streams and indices. This setting will use one slice per shard, up to a certain limit. If there are multiple source data streams or indices, it will choose the number of slices based on the index or backing index with the smallest number of shards. Adding `slices` to `_update_by_query` just automates the manual process of creating sub-requests, which means it has some quirks: * You can see these requests in the tasks APIs. These sub-requests are "child" tasks of the task for the request with slices. * Fetching the status of the task for the request with `slices` only contains the status of completed slices. * These sub-requests are individually addressable for things like cancellation and rethrottling. * Rethrottling the request with `slices` will rethrottle the unfinished sub-request proportionally. * Canceling the request with slices will cancel each sub-request. * Due to the nature of slices each sub-request won't get a perfectly even portion of the documents. All documents will be addressed, but some slices may be larger than others. Expect larger slices to have a more even distribution. * Parameters like `requests_per_second` and `max_docs` on a request with slices are distributed proportionally to each sub-request. Combine that with the point above about distribution being uneven and you should conclude that using `max_docs` with `slices` might not result in exactly `max_docs` documents being updated. * Each sub-request gets a slightly different snapshot of the source data stream or index though these are all taken at approximately the same time. If you're slicing manually or otherwise tuning automatic slicing, keep in mind that: * Query performance is most efficient when the number of slices is equal to the number of shards in the index or backing index. If that number is large (for example, 500), choose a lower number as too many slices hurts performance. Setting slices higher than the number of shards generally does not improve efficiency and adds overhead. * Update performance scales linearly across available resources with the number of slices. Whether query or update performance dominates the runtime depends on the documents being reindexed and cluster resources. **Update the document source** Update by query supports scripts to update the document source. As with the update API, you can set `ctx.op` to change the operation that is performed. Set `ctx.op = "noop"` if your script decides that it doesn't have to make any changes. The update by query operation skips updating the document and increments the `noop` counter. Set `ctx.op = "delete"` if your script decides that the document should be deleted. The update by query operation deletes the document and increments the `deleted` counter. Update by query supports only `index`, `noop`, and `delete`. Setting `ctx.op` to anything else is an error. Setting any other field in `ctx` is an error. This API enables you to only modify the source of matching documents; you cannot move them. @@ -45,8 +98,12 @@ export default async function UpdateByQueryApi (this: That, params: T.UpdateByQu export default async function UpdateByQueryApi (this: That, params: T.UpdateByQueryRequest, options?: TransportRequestOptionsWithMeta): Promise<TransportResult<T.UpdateByQueryResponse, unknown>> export default async function UpdateByQueryApi (this: That, params: T.UpdateByQueryRequest, options?: TransportRequestOptions): Promise<T.UpdateByQueryResponse> export default async function UpdateByQueryApi (this: That, params: T.UpdateByQueryRequest, options?: TransportRequestOptions): Promise<any> { - const acceptedPath: string[] = ['index'] - const acceptedBody: string[] = ['max_docs', 'query', 'script', 'slice', 'conflicts'] + const { + path: acceptedPath, + body: acceptedBody, + query: acceptedQuery + } = acceptedParams.update_by_query + const userQuery = params?.querystring const querystring: Record<string, any> = userQuery != null ? { ...userQuery } : {} @@ -68,8 +125,14 @@ export default async function UpdateByQueryApi (this: That, params: T.UpdateByQu } else if (acceptedPath.includes(key)) { continue } else if (key !== 'body' && key !== 'querystring') { - // @ts-expect-error - querystring[key] = params[key] + if (acceptedQuery.includes(key) || commonQueryParams.includes(key)) { + // @ts-expect-error + querystring[key] = params[key] + } else { + body = body ?? {} + // @ts-expect-error + body[key] = params[key] + } } } diff --git a/src/api/api/update_by_query_rethrottle.ts b/src/api/api/update_by_query_rethrottle.ts index eb96ad0ed..9572be0f7 100644 --- a/src/api/api/update_by_query_rethrottle.ts +++ b/src/api/api/update_by_query_rethrottle.ts @@ -35,7 +35,22 @@ import { TransportResult } from '@elastic/transport' import * as T from '../types' -interface That { transport: Transport } + +interface That { + transport: Transport +} + +const acceptedParams: Record<string, { path: string[], body: string[], query: string[] }> = { + update_by_query_rethrottle: { + path: [ + 'task_id' + ], + body: [], + query: [ + 'requests_per_second' + ] + } +} /** * Throttle an update by query operation. Change the number of requests per second for a particular update by query operation. Rethrottling that speeds up the query takes effect immediately but rethrotting that slows down the query takes effect after completing the current batch to prevent scroll timeouts. @@ -45,7 +60,10 @@ export default async function UpdateByQueryRethrottleApi (this: That, params: T. export default async function UpdateByQueryRethrottleApi (this: That, params: T.UpdateByQueryRethrottleRequest, options?: TransportRequestOptionsWithMeta): Promise<TransportResult<T.UpdateByQueryRethrottleResponse, unknown>> export default async function UpdateByQueryRethrottleApi (this: That, params: T.UpdateByQueryRethrottleRequest, options?: TransportRequestOptions): Promise<T.UpdateByQueryRethrottleResponse> export default async function UpdateByQueryRethrottleApi (this: That, params: T.UpdateByQueryRethrottleRequest, options?: TransportRequestOptions): Promise<any> { - const acceptedPath: string[] = ['task_id'] + const { + path: acceptedPath + } = acceptedParams.update_by_query_rethrottle + const userQuery = params?.querystring const querystring: Record<string, any> = userQuery != null ? { ...userQuery } : {} diff --git a/src/api/api/watcher.ts b/src/api/api/watcher.ts index 7e795d62b..b1956dfce 100644 --- a/src/api/api/watcher.ts +++ b/src/api/api/watcher.ts @@ -35,12 +35,148 @@ import { TransportResult } from '@elastic/transport' import * as T from '../types' -interface That { transport: Transport } + +interface That { + transport: Transport + acceptedParams: Record<string, { path: string[], body: string[], query: string[] }> +} + +const commonQueryParams = ['error_trace', 'filter_path', 'human', 'pretty'] export default class Watcher { transport: Transport + acceptedParams: Record<string, { path: string[], body: string[], query: string[] }> constructor (transport: Transport) { this.transport = transport + this.acceptedParams = { + 'watcher.ack_watch': { + path: [ + 'watch_id', + 'action_id' + ], + body: [], + query: [] + }, + 'watcher.activate_watch': { + path: [ + 'watch_id' + ], + body: [], + query: [] + }, + 'watcher.deactivate_watch': { + path: [ + 'watch_id' + ], + body: [], + query: [] + }, + 'watcher.delete_watch': { + path: [ + 'id' + ], + body: [], + query: [] + }, + 'watcher.execute_watch': { + path: [ + 'id' + ], + body: [ + 'action_modes', + 'alternative_input', + 'ignore_condition', + 'record_execution', + 'simulated_actions', + 'trigger_data', + 'watch' + ], + query: [ + 'debug' + ] + }, + 'watcher.get_settings': { + path: [], + body: [], + query: [ + 'master_timeout' + ] + }, + 'watcher.get_watch': { + path: [ + 'id' + ], + body: [], + query: [] + }, + 'watcher.put_watch': { + path: [ + 'id' + ], + body: [ + 'actions', + 'condition', + 'input', + 'metadata', + 'throttle_period', + 'throttle_period_in_millis', + 'transform', + 'trigger' + ], + query: [ + 'active', + 'if_primary_term', + 'if_seq_no', + 'version' + ] + }, + 'watcher.query_watches': { + path: [], + body: [ + 'from', + 'size', + 'query', + 'sort', + 'search_after' + ], + query: [] + }, + 'watcher.start': { + path: [], + body: [], + query: [ + 'master_timeout' + ] + }, + 'watcher.stats': { + path: [ + 'metric' + ], + body: [], + query: [ + 'emit_stacktraces', + 'metric' + ] + }, + 'watcher.stop': { + path: [], + body: [], + query: [ + 'master_timeout' + ] + }, + 'watcher.update_settings': { + path: [], + body: [ + 'index.auto_expand_replicas', + 'index.number_of_replicas' + ], + query: [ + 'master_timeout', + 'timeout' + ] + } + } } /** @@ -51,7 +187,10 @@ export default class Watcher { async ackWatch (this: That, params: T.WatcherAckWatchRequest, options?: TransportRequestOptionsWithMeta): Promise<TransportResult<T.WatcherAckWatchResponse, unknown>> async ackWatch (this: That, params: T.WatcherAckWatchRequest, options?: TransportRequestOptions): Promise<T.WatcherAckWatchResponse> async ackWatch (this: That, params: T.WatcherAckWatchRequest, options?: TransportRequestOptions): Promise<any> { - const acceptedPath: string[] = ['watch_id', 'action_id'] + const { + path: acceptedPath + } = this.acceptedParams['watcher.ack_watch'] + const userQuery = params?.querystring const querystring: Record<string, any> = userQuery != null ? { ...userQuery } : {} @@ -101,7 +240,10 @@ export default class Watcher { async activateWatch (this: That, params: T.WatcherActivateWatchRequest, options?: TransportRequestOptionsWithMeta): Promise<TransportResult<T.WatcherActivateWatchResponse, unknown>> async activateWatch (this: That, params: T.WatcherActivateWatchRequest, options?: TransportRequestOptions): Promise<T.WatcherActivateWatchResponse> async activateWatch (this: That, params: T.WatcherActivateWatchRequest, options?: TransportRequestOptions): Promise<any> { - const acceptedPath: string[] = ['watch_id'] + const { + path: acceptedPath + } = this.acceptedParams['watcher.activate_watch'] + const userQuery = params?.querystring const querystring: Record<string, any> = userQuery != null ? { ...userQuery } : {} @@ -143,7 +285,10 @@ export default class Watcher { async deactivateWatch (this: That, params: T.WatcherDeactivateWatchRequest, options?: TransportRequestOptionsWithMeta): Promise<TransportResult<T.WatcherDeactivateWatchResponse, unknown>> async deactivateWatch (this: That, params: T.WatcherDeactivateWatchRequest, options?: TransportRequestOptions): Promise<T.WatcherDeactivateWatchResponse> async deactivateWatch (this: That, params: T.WatcherDeactivateWatchRequest, options?: TransportRequestOptions): Promise<any> { - const acceptedPath: string[] = ['watch_id'] + const { + path: acceptedPath + } = this.acceptedParams['watcher.deactivate_watch'] + const userQuery = params?.querystring const querystring: Record<string, any> = userQuery != null ? { ...userQuery } : {} @@ -185,7 +330,10 @@ export default class Watcher { async deleteWatch (this: That, params: T.WatcherDeleteWatchRequest, options?: TransportRequestOptionsWithMeta): Promise<TransportResult<T.WatcherDeleteWatchResponse, unknown>> async deleteWatch (this: That, params: T.WatcherDeleteWatchRequest, options?: TransportRequestOptions): Promise<T.WatcherDeleteWatchResponse> async deleteWatch (this: That, params: T.WatcherDeleteWatchRequest, options?: TransportRequestOptions): Promise<any> { - const acceptedPath: string[] = ['id'] + const { + path: acceptedPath + } = this.acceptedParams['watcher.delete_watch'] + const userQuery = params?.querystring const querystring: Record<string, any> = userQuery != null ? { ...userQuery } : {} @@ -227,8 +375,12 @@ export default class Watcher { async executeWatch (this: That, params?: T.WatcherExecuteWatchRequest, options?: TransportRequestOptionsWithMeta): Promise<TransportResult<T.WatcherExecuteWatchResponse, unknown>> async executeWatch (this: That, params?: T.WatcherExecuteWatchRequest, options?: TransportRequestOptions): Promise<T.WatcherExecuteWatchResponse> async executeWatch (this: That, params?: T.WatcherExecuteWatchRequest, options?: TransportRequestOptions): Promise<any> { - const acceptedPath: string[] = ['id'] - const acceptedBody: string[] = ['action_modes', 'alternative_input', 'ignore_condition', 'record_execution', 'simulated_actions', 'trigger_data', 'watch'] + const { + path: acceptedPath, + body: acceptedBody, + query: acceptedQuery + } = this.acceptedParams['watcher.execute_watch'] + const userQuery = params?.querystring const querystring: Record<string, any> = userQuery != null ? { ...userQuery } : {} @@ -251,8 +403,14 @@ export default class Watcher { } else if (acceptedPath.includes(key)) { continue } else if (key !== 'body' && key !== 'querystring') { - // @ts-expect-error - querystring[key] = params[key] + if (acceptedQuery.includes(key) || commonQueryParams.includes(key)) { + // @ts-expect-error + querystring[key] = params[key] + } else { + body = body ?? {} + // @ts-expect-error + body[key] = params[key] + } } } @@ -282,7 +440,10 @@ export default class Watcher { async getSettings (this: That, params?: T.WatcherGetSettingsRequest, options?: TransportRequestOptionsWithMeta): Promise<TransportResult<T.WatcherGetSettingsResponse, unknown>> async getSettings (this: That, params?: T.WatcherGetSettingsRequest, options?: TransportRequestOptions): Promise<T.WatcherGetSettingsResponse> async getSettings (this: That, params?: T.WatcherGetSettingsRequest, options?: TransportRequestOptions): Promise<any> { - const acceptedPath: string[] = [] + const { + path: acceptedPath + } = this.acceptedParams['watcher.get_settings'] + const userQuery = params?.querystring const querystring: Record<string, any> = userQuery != null ? { ...userQuery } : {} @@ -322,7 +483,10 @@ export default class Watcher { async getWatch (this: That, params: T.WatcherGetWatchRequest, options?: TransportRequestOptionsWithMeta): Promise<TransportResult<T.WatcherGetWatchResponse, unknown>> async getWatch (this: That, params: T.WatcherGetWatchRequest, options?: TransportRequestOptions): Promise<T.WatcherGetWatchResponse> async getWatch (this: That, params: T.WatcherGetWatchRequest, options?: TransportRequestOptions): Promise<any> { - const acceptedPath: string[] = ['id'] + const { + path: acceptedPath + } = this.acceptedParams['watcher.get_watch'] + const userQuery = params?.querystring const querystring: Record<string, any> = userQuery != null ? { ...userQuery } : {} @@ -364,8 +528,12 @@ export default class Watcher { async putWatch (this: That, params: T.WatcherPutWatchRequest, options?: TransportRequestOptionsWithMeta): Promise<TransportResult<T.WatcherPutWatchResponse, unknown>> async putWatch (this: That, params: T.WatcherPutWatchRequest, options?: TransportRequestOptions): Promise<T.WatcherPutWatchResponse> async putWatch (this: That, params: T.WatcherPutWatchRequest, options?: TransportRequestOptions): Promise<any> { - const acceptedPath: string[] = ['id'] - const acceptedBody: string[] = ['actions', 'condition', 'input', 'metadata', 'throttle_period', 'throttle_period_in_millis', 'transform', 'trigger'] + const { + path: acceptedPath, + body: acceptedBody, + query: acceptedQuery + } = this.acceptedParams['watcher.put_watch'] + const userQuery = params?.querystring const querystring: Record<string, any> = userQuery != null ? { ...userQuery } : {} @@ -387,8 +555,14 @@ export default class Watcher { } else if (acceptedPath.includes(key)) { continue } else if (key !== 'body' && key !== 'querystring') { - // @ts-expect-error - querystring[key] = params[key] + if (acceptedQuery.includes(key) || commonQueryParams.includes(key)) { + // @ts-expect-error + querystring[key] = params[key] + } else { + body = body ?? {} + // @ts-expect-error + body[key] = params[key] + } } } @@ -411,8 +585,12 @@ export default class Watcher { async queryWatches (this: That, params?: T.WatcherQueryWatchesRequest, options?: TransportRequestOptionsWithMeta): Promise<TransportResult<T.WatcherQueryWatchesResponse, unknown>> async queryWatches (this: That, params?: T.WatcherQueryWatchesRequest, options?: TransportRequestOptions): Promise<T.WatcherQueryWatchesResponse> async queryWatches (this: That, params?: T.WatcherQueryWatchesRequest, options?: TransportRequestOptions): Promise<any> { - const acceptedPath: string[] = [] - const acceptedBody: string[] = ['from', 'size', 'query', 'sort', 'search_after'] + const { + path: acceptedPath, + body: acceptedBody, + query: acceptedQuery + } = this.acceptedParams['watcher.query_watches'] + const userQuery = params?.querystring const querystring: Record<string, any> = userQuery != null ? { ...userQuery } : {} @@ -435,8 +613,14 @@ export default class Watcher { } else if (acceptedPath.includes(key)) { continue } else if (key !== 'body' && key !== 'querystring') { - // @ts-expect-error - querystring[key] = params[key] + if (acceptedQuery.includes(key) || commonQueryParams.includes(key)) { + // @ts-expect-error + querystring[key] = params[key] + } else { + body = body ?? {} + // @ts-expect-error + body[key] = params[key] + } } } @@ -456,7 +640,10 @@ export default class Watcher { async start (this: That, params?: T.WatcherStartRequest, options?: TransportRequestOptionsWithMeta): Promise<TransportResult<T.WatcherStartResponse, unknown>> async start (this: That, params?: T.WatcherStartRequest, options?: TransportRequestOptions): Promise<T.WatcherStartResponse> async start (this: That, params?: T.WatcherStartRequest, options?: TransportRequestOptions): Promise<any> { - const acceptedPath: string[] = [] + const { + path: acceptedPath + } = this.acceptedParams['watcher.start'] + const userQuery = params?.querystring const querystring: Record<string, any> = userQuery != null ? { ...userQuery } : {} @@ -496,7 +683,10 @@ export default class Watcher { async stats (this: That, params?: T.WatcherStatsRequest, options?: TransportRequestOptionsWithMeta): Promise<TransportResult<T.WatcherStatsResponse, unknown>> async stats (this: That, params?: T.WatcherStatsRequest, options?: TransportRequestOptions): Promise<T.WatcherStatsResponse> async stats (this: That, params?: T.WatcherStatsRequest, options?: TransportRequestOptions): Promise<any> { - const acceptedPath: string[] = ['metric'] + const { + path: acceptedPath + } = this.acceptedParams['watcher.stats'] + const userQuery = params?.querystring const querystring: Record<string, any> = userQuery != null ? { ...userQuery } : {} @@ -546,7 +736,10 @@ export default class Watcher { async stop (this: That, params?: T.WatcherStopRequest, options?: TransportRequestOptionsWithMeta): Promise<TransportResult<T.WatcherStopResponse, unknown>> async stop (this: That, params?: T.WatcherStopRequest, options?: TransportRequestOptions): Promise<T.WatcherStopResponse> async stop (this: That, params?: T.WatcherStopRequest, options?: TransportRequestOptions): Promise<any> { - const acceptedPath: string[] = [] + const { + path: acceptedPath + } = this.acceptedParams['watcher.stop'] + const userQuery = params?.querystring const querystring: Record<string, any> = userQuery != null ? { ...userQuery } : {} @@ -586,8 +779,12 @@ export default class Watcher { async updateSettings (this: That, params?: T.WatcherUpdateSettingsRequest, options?: TransportRequestOptionsWithMeta): Promise<TransportResult<T.WatcherUpdateSettingsResponse, unknown>> async updateSettings (this: That, params?: T.WatcherUpdateSettingsRequest, options?: TransportRequestOptions): Promise<T.WatcherUpdateSettingsResponse> async updateSettings (this: That, params?: T.WatcherUpdateSettingsRequest, options?: TransportRequestOptions): Promise<any> { - const acceptedPath: string[] = [] - const acceptedBody: string[] = ['index.auto_expand_replicas', 'index.number_of_replicas'] + const { + path: acceptedPath, + body: acceptedBody, + query: acceptedQuery + } = this.acceptedParams['watcher.update_settings'] + const userQuery = params?.querystring const querystring: Record<string, any> = userQuery != null ? { ...userQuery } : {} @@ -610,8 +807,14 @@ export default class Watcher { } else if (acceptedPath.includes(key)) { continue } else if (key !== 'body' && key !== 'querystring') { - // @ts-expect-error - querystring[key] = params[key] + if (acceptedQuery.includes(key) || commonQueryParams.includes(key)) { + // @ts-expect-error + querystring[key] = params[key] + } else { + body = body ?? {} + // @ts-expect-error + body[key] = params[key] + } } } diff --git a/src/api/api/xpack.ts b/src/api/api/xpack.ts index 9e6a66f7b..084fa20ec 100644 --- a/src/api/api/xpack.ts +++ b/src/api/api/xpack.ts @@ -35,12 +35,35 @@ import { TransportResult } from '@elastic/transport' import * as T from '../types' -interface That { transport: Transport } + +interface That { + transport: Transport + acceptedParams: Record<string, { path: string[], body: string[], query: string[] }> +} export default class Xpack { transport: Transport + acceptedParams: Record<string, { path: string[], body: string[], query: string[] }> constructor (transport: Transport) { this.transport = transport + this.acceptedParams = { + 'xpack.info': { + path: [], + body: [], + query: [ + 'categories', + 'accept_enterprise', + 'human' + ] + }, + 'xpack.usage': { + path: [], + body: [], + query: [ + 'master_timeout' + ] + } + } } /** @@ -51,7 +74,10 @@ export default class Xpack { async info (this: That, params?: T.XpackInfoRequest, options?: TransportRequestOptionsWithMeta): Promise<TransportResult<T.XpackInfoResponse, unknown>> async info (this: That, params?: T.XpackInfoRequest, options?: TransportRequestOptions): Promise<T.XpackInfoResponse> async info (this: That, params?: T.XpackInfoRequest, options?: TransportRequestOptions): Promise<any> { - const acceptedPath: string[] = [] + const { + path: acceptedPath + } = this.acceptedParams['xpack.info'] + const userQuery = params?.querystring const querystring: Record<string, any> = userQuery != null ? { ...userQuery } : {} @@ -91,7 +117,10 @@ export default class Xpack { async usage (this: That, params?: T.XpackUsageRequest, options?: TransportRequestOptionsWithMeta): Promise<TransportResult<T.XpackUsageResponse, unknown>> async usage (this: That, params?: T.XpackUsageRequest, options?: TransportRequestOptions): Promise<T.XpackUsageResponse> async usage (this: That, params?: T.XpackUsageRequest, options?: TransportRequestOptions): Promise<any> { - const acceptedPath: string[] = [] + const { + path: acceptedPath + } = this.acceptedParams['xpack.usage'] + const userQuery = params?.querystring const querystring: Record<string, any> = userQuery != null ? { ...userQuery } : {} diff --git a/src/api/types.ts b/src/api/types.ts index e242e803c..668948f05 100644 --- a/src/api/types.ts +++ b/src/api/types.ts @@ -2775,7 +2775,6 @@ export interface BulkIndexByScrollFailure { id: Id index: IndexName status: integer - type: string } export interface BulkStats { @@ -6103,7 +6102,7 @@ export interface MappingDynamicProperty extends MappingDocValuesPropertyBase { export interface MappingDynamicTemplate { mapping?: MappingProperty - runtime?: MappingProperty + runtime?: MappingRuntimeField match?: string | string[] path_match?: string | string[] unmatch?: string | string[] @@ -12800,7 +12799,7 @@ export interface IndicesIndexSettingsKeys { routing_partition_size?: SpecUtilsStringified<integer> load_fixed_bitset_filters_eagerly?: boolean hidden?: boolean | string - auto_expand_replicas?: string + auto_expand_replicas?: SpecUtilsWithNullValue<string> merge?: IndicesMerge search?: IndicesSettingsSearch refresh_interval?: Duration @@ -13097,7 +13096,7 @@ export interface IndicesSoftDeletes { retention_lease?: IndicesRetentionLease } -export type IndicesSourceMode = 'DISABLED' | 'STORED' | 'SYNTHETIC' +export type IndicesSourceMode = 'disabled' | 'stored' | 'synthetic' export interface IndicesStorage { type: IndicesStorageType @@ -14275,7 +14274,7 @@ export interface IndicesPutMappingRequest extends RequestBase { /** If date detection is enabled then new string fields are checked against 'dynamic_date_formats' and if the value matches then a new date field is added instead of string. */ dynamic_date_formats?: string[] /** Specify dynamic templates for the mapping. */ - dynamic_templates?: Record<string, MappingDynamicTemplate> | Record<string, MappingDynamicTemplate>[] + dynamic_templates?: Record<string, MappingDynamicTemplate>[] /** Control whether field names are enabled for the index. */ _field_names?: MappingFieldNamesField /** A mapping type can have custom meta data associated with it. These are not used at all by Elasticsearch, but can be used to store application-specific metadata. */ @@ -21364,6 +21363,10 @@ export interface SecurityRemoteIndicesPrivileges { allow_restricted_indices?: boolean } +export interface SecurityRemoteUserIndicesPrivileges extends SecurityUserIndicesPrivileges { + clusters: string[] +} + export interface SecurityReplicationAccess { names: IndexName | IndexName[] allow_restricted_indices?: boolean @@ -22051,7 +22054,8 @@ export interface SecurityGetRoleRole { remote_indices?: SecurityRemoteIndicesPrivileges[] remote_cluster?: SecurityRemoteClusterPrivileges[] metadata: Metadata - run_as: string[] + description?: string + run_as?: string[] transient_metadata?: Record<string, any> applications: SecurityApplicationPrivileges[] role_templates?: SecurityRoleTemplate[] @@ -22204,8 +22208,10 @@ export interface SecurityGetUserPrivilegesRequest extends RequestBase { export interface SecurityGetUserPrivilegesResponse { applications: SecurityApplicationPrivileges[] cluster: string[] + remote_cluster?: SecurityRemoteClusterPrivileges[] global: SecurityGlobalPrivilege[] indices: SecurityUserIndicesPrivileges[] + remote_indices?: SecurityRemoteUserIndicesPrivileges[] run_as: string[] }