Skip to content

Commit

Permalink
[DOCS] Add examples for create, delete, index, reindex APIs (#3540)
Browse files Browse the repository at this point in the history
(cherry picked from commit f48fc40)
  • Loading branch information
lcawl committed Jan 16, 2025
1 parent 9a0c020 commit 4ee300c
Show file tree
Hide file tree
Showing 57 changed files with 1,972 additions and 580 deletions.
260 changes: 150 additions & 110 deletions output/openapi/elasticsearch-openapi.json

Large diffs are not rendered by default.

252 changes: 146 additions & 106 deletions output/openapi/elasticsearch-serverless-openapi.json

Large diffs are not rendered by default.

530 changes: 324 additions & 206 deletions output/schema/schema.json

Large diffs are not rendered by default.

7 changes: 3 additions & 4 deletions specification/_doc_ids/table.csv
Original file line number Diff line number Diff line change
Expand Up @@ -140,17 +140,14 @@ dissect-processor,https://www.elastic.co/guide/en/elasticsearch/reference/{branc
distance-units,https://www.elastic.co/guide/en/elasticsearch/reference/{branch}/api-conventions.html#distance-units
docs-bulk,https://www.elastic.co/guide/en/elasticsearch/reference/{branch}/docs-bulk.html
docs-delete-by-query,https://www.elastic.co/guide/en/elasticsearch/reference/{branch}/docs-delete-by-query.html
docs-delete-by-query,https://www.elastic.co/guide/en/elasticsearch/reference/{branch}/docs-delete-by-query.html
docs-delete,https://www.elastic.co/guide/en/elasticsearch/reference/{branch}/docs-delete.html
docs-get,https://www.elastic.co/guide/en/elasticsearch/reference/{branch}/docs-get.html
docs-get,https://www.elastic.co/guide/en/elasticsearch/reference/{branch}/docs-get.html
docs-index_,https://www.elastic.co/guide/en/elasticsearch/reference/{branch}/docs-index_.html
docs-index,https://www.elastic.co/guide/en/elasticsearch/reference/{branch}/docs-index_.html
docs-multi-get,https://www.elastic.co/guide/en/elasticsearch/reference/{branch}/docs-multi-get.html
docs-multi-termvectors,https://www.elastic.co/guide/en/elasticsearch/reference/{branch}/docs-multi-termvectors.html
docs-reindex,https://www.elastic.co/guide/en/elasticsearch/reference/{branch}/docs-reindex.html
docs-termvectors,https://www.elastic.co/guide/en/elasticsearch/reference/{branch}/docs-termvectors.html
docs-update-by-query,https://www.elastic.co/guide/en/elasticsearch/reference/{branch}/docs-update-by-query.html
docs-update-by-query,https://www.elastic.co/guide/en/elasticsearch/reference/{branch}/docs-update-by-query.html
docs-update,https://www.elastic.co/guide/en/elasticsearch/reference/{branch}/docs-update.html
document-input-parameters,https://www.elastic.co/guide/en/elasticsearch/reference/{branch}/query-dsl-mlt-query.html#_document_input_parameters
dot-expand-processor,https://www.elastic.co/guide/en/elasticsearch/reference/{branch}/dot-expand-processor.html
Expand Down Expand Up @@ -381,6 +378,7 @@ node-roles,https://www.elastic.co/guide/en/elasticsearch/reference/{branch}/modu
nodes-api-shutdown-delete,https://www.elastic.co/guide/en/elasticsearch/reference/{branch}/delete-shutdown.html
nodes-api-shutdown-status,https://www.elastic.co/guide/en/elasticsearch/reference/{branch}/get-shutdown.html
nodes-api-shutdown,https://www.elastic.co/guide/en/elasticsearch/reference/{branch}/put-shutdown.html
optimistic-concurrency,https://www.elastic.co/guide/en/elasticsearch/reference/{branch}/optimistic-concurrency-control.html
paginate-search-results,https://www.elastic.co/guide/en/elasticsearch/reference/{branch}/paginate-search-results.html
painless-contexts,https://www.elastic.co/guide/en/elasticsearch/painless/{branch}/painless-contexts.html
painless-execute-api,https://www.elastic.co/guide/en/elasticsearch/painless/{branch}/painless-execute-api.html
Expand Down Expand Up @@ -674,6 +672,7 @@ set-processor,https://www.elastic.co/guide/en/elasticsearch/reference/{branch}/s
shape,https://www.elastic.co/guide/en/elasticsearch/reference/{branch}/shape.html
simulate-ingest-api,https://www.elastic.co/guide/en/elasticsearch/reference/{branch}/simulate-ingest-api.html
simulate-pipeline-api,https://www.elastic.co/guide/en/elasticsearch/reference/{branch}/simulate-pipeline-api.html
slice-scroll,https://www.elastic.co/guide/en/elasticsearch/reference/{branch}/paginate-search-results.html#slice-scroll
slm-api-delete-policy,https://www.elastic.co/guide/en/elasticsearch/reference/{branch}/slm-api-delete-policy.html
slm-api-execute-lifecycle,https://www.elastic.co/guide/en/elasticsearch/reference/{branch}/slm-api-execute-lifecycle.html
slm-api-execute-retention,https://www.elastic.co/guide/en/elasticsearch/reference/{branch}/slm-api-execute-retention.html
Expand Down
120 changes: 101 additions & 19 deletions specification/_global/create/CreateRequest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,67 +30,149 @@ import {
import { Duration } from '@_types/Time'

/**
* Index a document.
* Adds a JSON document to the specified data stream or index and makes it searchable.
* If the target is an index and the document already exists, the request updates the document and increments its version.
* 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.
* @rest_spec_name create
* @availability stack since=5.0.0 stability=stable
* @availability serverless stability=stable visibility=public
* @index_privileges create
* @doc_tag document
* @doc_id docs-index
* @ext_doc_id data-streams
*/
export interface Request<TDocument> extends RequestBase {
path_parts: {
/**
* Unique identifier for the document.
* A unique identifier for the document.
* To automatically generate a document ID, use the `POST /<target>/_doc/` request format.
*/
id: Id
/**
* Name of the data stream or index to target.
* If the target doesnt exist and matches the name or wildcard (`*`) pattern of an index template with a `data_stream` definition, this request creates the data stream.
* If the target doesnt exist and doesn’t match a data stream template, this request creates the index.
* The name of the data stream or index to target.
* If the target doesn't exist and matches the name or wildcard (`*`) pattern of an index template with a `data_stream` definition, this request creates the data stream.
* If the target doesn't exist and doesn’t match a data stream template, this request creates the index.
*/
index: IndexName
}
query_parameters: {
/**
* 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.
* The ID of the pipeline to use to preprocess incoming documents.
* If the index has a default ingest pipeline specified, setting the value to `_none` turns off 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
/**
* If `true`, Elasticsearch refreshes the affected shards to make this operation visible to search, if `wait_for` then wait for a refresh to make this operation visible to search, if `false` do nothing with refreshes.
* Valid values: `true`, `false`, `wait_for`.
* If `true`, Elasticsearch refreshes the affected shards to make this operation visible to search.
* If `wait_for`, it waits for a refresh to make this operation visible to search.
* If `false`, it does nothing with refreshes.
* @server_default false
*/
refresh?: Refresh
/**
* Custom value used to route operations to a specific shard.
* A custom value that is used to route operations to a specific shard.
*/
routing?: Routing
/**
* Period the request waits for the following operations: automatic index creation, dynamic mapping updates, waiting for active shards.
* The period the request waits for the following operations: automatic index creation, dynamic mapping updates, waiting for active shards.
* Elasticsearch waits for at least the specified timeout period before failing.
* The actual wait time could be longer, particularly when multiple waits occur.
*
* This parameter is useful for situations where the primary shard assigned to perform the operation might not be available when the operation runs.
* Some reasons for this might be that the primary shard is currently recovering from a gateway or undergoing relocation.
* By default, the operation will wait on the primary shard to become available for at least 1 minute before failing and responding with an error.
* The actual wait time could be longer, particularly when multiple waits occur.
* @server_default 1m
*/
timeout?: Duration
/**
* Explicit version number for concurrency control.
* The specified version must match the current version of the document for the request to succeed.
* The explicit version number for concurrency control.
* It must be a non-negative long number.
*/
version?: VersionNumber
/**
* Specific version type: `external`, `external_gte`.
* The version type.
*/
version_type?: VersionType
/**
* 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`).
* You can set it to `all` or any positive integer up to the total number of shards in the index (`number_of_replicas+1`).
* The default value of `1` means it waits for each primary shard to be active.
* @server_default 1
*/
wait_for_active_shards?: WaitForActiveShards
}
/**
* Request body contains the JSON source for the document data.
* The request body contains the JSON source for the document data.
* @codegen_name document */
body: TDocument
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# summary:
# method_request: PUT my-index-000001/_create/1
description: >
Run `PUT my-index-000001/_create/1` to index a document into the `my-index-000001` index if no document with that ID exists.
# type: request
value: |-
{
"@timestamp": "2099-11-15T13:12:00",
"message": "GET /search HTTP/1.1 200 1070000",
"user": {
"id": "kimchy"
}
}
Loading

0 comments on commit 4ee300c

Please sign in to comment.