diff --git a/specification/_global/update_by_query/UpdateByQueryRequest.ts b/specification/_global/update_by_query/UpdateByQueryRequest.ts index b96a3d320b..c9ca514b00 100644 --- a/specification/_global/update_by_query/UpdateByQueryRequest.ts +++ b/specification/_global/update_by_query/UpdateByQueryRequest.ts @@ -20,20 +20,21 @@ import { RequestBase } from '@_types/Base' import { Conflicts, - ExpandWildcards, + Fields, Indices, MediaType, + Refresh, Routing, SearchType, Slices, WaitForActiveShards } from '@_types/common' -import { float, long } from '@_types/Numeric' +import { RuntimeFields } from '@_types/mapping/RuntimeFields' +import { float, integer, long } from '@_types/Numeric' import { QueryContainer } from '@_types/query_dsl/abstractions' -import { Operator } from '@_types/query_dsl/Operator' import { Script } from '@_types/Scripting' -import { SlicedScroll } from '@_types/SlicedScroll' import { Duration } from '@_types/Time' +import { SourceConfigParam } from '@global/search/_types/SourceFilter' /** * Update documents. @@ -46,97 +47,12 @@ import { Duration } from '@_types/Time' * * `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. - * - * **Refreshing shards** - * - * Specifying the `refresh` parameter refreshes all shards once the request completes. - * This is different to the update API's `refresh` parameter, which causes only the shard - * that received the request to be refreshed. Unlike the update API, it does not support - * `wait_for`. - * - * **Running update by query asynchronously** - * - * If the request contains `wait_for_completion=false`, Elasticsearch - * performs some preflight checks, launches the request, and returns a - * [task](https://www.elastic.co/docs/api/doc/elasticsearch/group/endpoint-tasks) 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/${taskId}`. - * - * **Waiting for active shards** - * - * `wait_for_active_shards` controls how many copies of a shard must be active - * before proceeding with the request. See [`wait_for_active_shards`](https://www.elastic.co/docs/api/doc/elasticsearch/operation/operation-create#operation-create-wait_for_active_shards) - * for details. `timeout` controls how long each write request waits for unavailable - * shards to become available. Both work exactly the way they work in the - * [Bulk API](https://www.elastic.co/docs/api/doc/elasticsearch/operation/operation-bulk). Update by query uses scrolled searches, so you can also - * specify the `scroll` parameter to control how long it keeps the search context - * alive, for example `?scroll=10m`. The default is 5 minutes. - * - * **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. - * Refer to the linked documentation for examples of how to update documents using the `_update_by_query` API: * @rest_spec_name update_by_query * @availability stack since=2.4.0 stability=stable * @availability serverless stability=stable visibility=public - * @index_privileges read,write + * @index_privileges read, index * @doc_tag document * @doc_id docs-update-by-query - * @ext_doc_id update-by-query */ export interface Request extends RequestBase { urls: [ @@ -148,9 +64,8 @@ export interface Request extends RequestBase { path_parts: { /** * A comma-separated list of data streams, indices, and aliases to search. - * It supports wildcards (`*`). + * Supports wildcards (`*`). * To search all data streams or indices, omit this parameter or use `*` or `_all`. - * @ext_doc_id search-multiple-indices */ index: Indices } @@ -158,104 +73,81 @@ export interface Request extends RequestBase { response_media_type: MediaType.Json query_parameters: { /** - * A setting that does two separate checks on the index expression. - * If `false`, the request returns an error (1) if any wildcard expression - * (including `_all` and `*`) resolves to zero matching indices or (2) if the - * complete set of resolved indices, aliases or data streams is empty after all - * expressions are evaluated. If `true`, index expressions that resolve to no - * indices are allowed and the request returns an empty result. + * If `false`, the request returns an error if any wildcard expression, index alias, or `_all` value targets only missing or closed indices. + * This behavior applies even if the request targets other open indices. + * For example, a request targeting `foo*,bar*` returns an error if an index starts with `foo` but no index starts with `bar`. * @server_default true */ allow_no_indices?: boolean /** - * The analyzer to use for the query string. - * This parameter can be used only when the `q` query string parameter is specified. - */ - analyzer?: string - /** - * If `true`, wildcard and prefix queries are analyzed. - * This parameter can be used only when the `q` query string parameter is specified. - * @server_default false + * Analyze the request and collect statistics about each shard that would execute it, without actually running it. */ analyze_wildcard?: boolean /** - * The preferred behavior when update by query hits version conflicts: `abort` or `proceed`. - * @server_default abort + * The analyzer to use for the query string. */ - conflicts?: Conflicts + analyzer?: string /** - * The default operator for query string query: `and` or `or`. - * This parameter can be used only when the `q` query string parameter is specified. - * @server_default or + * The default operator for query string query: `AND` or `OR`. + * @server_default OR */ - default_operator?: Operator + default_operator?: string /** - * The field to use as default where no field prefix is given in the query string. - * This parameter can be used only when the `q` query string parameter is specified. + * The field to use as a default where no field prefix is given in the query string. */ df?: string /** * The type of index that wildcard patterns can match. * If the request can target data streams, this argument determines whether wildcard expressions match hidden data streams. - * It supports comma-separated values, such as `open,hidden`. + * Supports comma-separated values, such as `open,hidden`. + * Valid values are: `all`, `open`, `closed`, `hidden`, `none`. * @server_default open */ - expand_wildcards?: ExpandWildcards + expand_wildcards?: string /** - * Skips the specified number of documents. - * @server_default 0 + * If `true`, returns the `_source` of each hit. */ - from?: long + from?: integer /** - * If `false`, the request returns an error if it targets a concrete (non-wildcarded) - * index, alias, or data stream that is missing, closed, or otherwise unavailable. - * If `true`, unavailable concrete targets are silently ignored. + * If `false`, the request returns an error if it targets a missing or closed index. * @server_default false */ ignore_unavailable?: boolean /** * If `true`, format-based query failures (such as providing text to a numeric field) in the query string will be ignored. - * This parameter can be used only when the `q` query string parameter is specified. * @server_default false */ lenient?: boolean /** - * The maximum number of documents to process. - * It defaults to all documents. - * When set to a value less than or equal to `scroll_size` and `conflicts` is set to `abort`, a scroll will not be used to retrieve the results for the operation. + * The maximum number of documents to update. + * By default, all matching documents are updated. */ max_docs?: long /** - * The ID of the pipeline to use to preprocess incoming documents. + * ID of the pipeline to use to preprocess incoming documents. * If the index has a default ingest pipeline specified, then setting the value to `_none` disables the default ingest pipeline for this request. * If a final pipeline is configured it will always run, regardless of the value of this parameter. */ pipeline?: string /** - * The node or shard the operation should be performed on. - * It is random by default. + * Specifies the node or shard the operation should be performed on. + * Random by default. */ preference?: string - /** - * A query in the Lucene query string syntax. - */ - q?: string /** * If `true`, Elasticsearch refreshes affected shards to make the operation visible to search after the request completes. - * This is different than the update API's `refresh` parameter, which causes just the shard that received the request to be refreshed. * @server_default false */ refresh?: boolean /** * If `true`, the request cache is used for this request. - * It defaults to the index-level setting. - * @ext_doc_id shard-request-cache + * Defaults to the index-level setting. */ request_cache?: boolean /** - * The maximum number of documents to update per second, across the entire update_by_query operation (including slices). - * It can be either `-1` to turn off throttling or any decimal number like `1.7` or `12` to throttle to that level. - * @server_default -1 + * The number of shard copies that must be active before proceeding with the operation. + * Set to `all` or any positive integer up to the total number of shards in the index (`number_of_replicas+1`). + * @server_default 1 */ requests_per_second?: float /** @@ -264,53 +156,45 @@ export interface Request extends RequestBase { routing?: Routing /** * The period to retain the search context for scrolling. - * @server_default 5m - * @ext_doc_id search-scroll-results */ scroll?: Duration /** * The size of the scroll request that powers the operation. * @server_default 1000 */ - scroll_size?: long + scroll_size?: integer /** - * An explicit timeout for each search request. - * By default, there is no timeout. + * The type of the search operation. + * Available options: `dfs_query_then_fetch`, `query_then_fetch`. + * @server_default query_then_fetch */ - search_timeout?: Duration + search_type?: SearchType /** - * The type of the search operation. Available options include `query_then_fetch` and `dfs_query_then_fetch`. + * The period of time to wait for a response from each shard. + * If no response is received before the timeout expires, the request fails and returns an error. + * @server_default 30s */ - search_type?: SearchType + search_timeout?: Duration /** * The number of slices this task should be divided into. * @server_default 1 */ slices?: Slices /** - * A comma-separated list of : pairs. + * A comma-separated list of `:` pairs. */ sort?: string[] /** - * The specific `tag` of the request for logging and statistical purposes. + * Specific `tag` of the request for logging and statistical purposes. */ stats?: string[] /** - * The maximum number of documents to collect for each shard. - * If a query reaches this limit, Elasticsearch terminates the query early. - * Elasticsearch collects documents before sorting. - * - * IMPORTANT: Use with caution. - * Elasticsearch applies this parameter to each shard handling the request. - * When possible, let Elasticsearch perform early termination automatically. - * Avoid specifying this parameter for requests that target data streams with backing indices across multiple data tiers. - */ - terminate_after?: long - /** - * The period each update request waits for the following operations: dynamic mapping updates, waiting for active shards. - * By default, it is one minute. - * This guarantees Elasticsearch waits for at least the timeout before failing. - * The actual wait time could be longer, particularly when multiple waits occur. + * The maximum number of documents to collect for each shard, upon which the coordinating node and batching is stopped. + * If Elasticsearch estimates that the number of results to be returned is greater than `max_docs`, it terminates the query. + */ + terminate_after?: integer + /** + * The period each update request waits for the following operations: dynamic mapping updates and waiting for active shards. * @server_default 1m */ timeout?: Duration @@ -319,47 +203,79 @@ export interface Request extends RequestBase { */ version?: boolean /** - * Should the document increment the version number (internal) on hit or not (reindex) + * If `true`, the request uses optimistic concurrency control. */ version_type?: boolean /** * The number of shard copies that must be active before proceeding with the operation. * Set to `all` or any positive integer up to the total number of shards in the index (`number_of_replicas+1`). - * The `timeout` parameter controls how long each write request waits for unavailable shards to become available. - * Both work exactly the way they work in the bulk API. * @server_default 1 */ wait_for_active_shards?: WaitForActiveShards /** * If `true`, the request blocks until the operation is complete. - * If `false`, Elasticsearch performs some preflight checks, launches the request, and returns a task ID that 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/${taskId}`. * @server_default true */ wait_for_completion?: boolean + /** + * Indicates whether to return the `_source` field (`true` or `false`) or contains a list of fields to return. + */ + _source?: SourceConfigParam + /** + * A comma-separated list of source fields to exclude from the response. + */ + _source_excludes?: Fields + /** + * A comma-separated list of source fields to include in the response. + */ + _source_includes?: Fields + /** + * What to do if update by query hits version conflicts: `abort` or `proceed`. + * @server_default abort + */ + conflicts?: Conflicts } - body?: { + body: { + /** + * What to do if update by query hits version conflicts: `abort` or `proceed`. + * @server_default abort + */ + conflicts?: Conflicts /** * The maximum number of documents to update. */ max_docs?: long /** - * The documents to update using the Query DSL. + * The query definition using the Query DSL. */ query?: QueryContainer /** * The script to run to update the document source or metadata when updating. - * */ script?: Script /** - * Slice the request manually using the provided slice ID and total number of slices. + * Defines one or more runtime fields in the search request. + * These fields take precedence over mapped fields with the same name. */ - slice?: SlicedScroll + runtime_mappings?: RuntimeFields /** - * The preferred behavior when update by query hits version conflicts: `abort` or `proceed`. - * @server_default abort + * Slice the request manually using the provided slice ID and total number of slices. */ - conflicts?: Conflicts + slice?: SlicedScroll } } + +export class SlicedScroll { + /** + * The slice ID. + */ + id: integer + /** + * The maximum number of slices. + */ + max: integer + /** + * The field to use for slicing. + */ + field?: string +} \ No newline at end of file