Skip to content

Commit f48fc40

Browse files
authored
[DOCS] Add examples for create, delete, index, reindex APIs (#3540)
1 parent 027ad70 commit f48fc40

File tree

57 files changed

+1972
-580
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

57 files changed

+1972
-580
lines changed

output/openapi/elasticsearch-openapi.json

+150-110
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

output/openapi/elasticsearch-serverless-openapi.json

+146-106
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

output/schema/schema.json

+324-206
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

specification/_doc_ids/table.csv

+3-4
Original file line numberDiff line numberDiff line change
@@ -140,17 +140,14 @@ dissect-processor,https://www.elastic.co/guide/en/elasticsearch/reference/{branc
140140
distance-units,https://www.elastic.co/guide/en/elasticsearch/reference/{branch}/api-conventions.html#distance-units
141141
docs-bulk,https://www.elastic.co/guide/en/elasticsearch/reference/{branch}/docs-bulk.html
142142
docs-delete-by-query,https://www.elastic.co/guide/en/elasticsearch/reference/{branch}/docs-delete-by-query.html
143-
docs-delete-by-query,https://www.elastic.co/guide/en/elasticsearch/reference/{branch}/docs-delete-by-query.html
144143
docs-delete,https://www.elastic.co/guide/en/elasticsearch/reference/{branch}/docs-delete.html
145144
docs-get,https://www.elastic.co/guide/en/elasticsearch/reference/{branch}/docs-get.html
146-
docs-get,https://www.elastic.co/guide/en/elasticsearch/reference/{branch}/docs-get.html
147-
docs-index_,https://www.elastic.co/guide/en/elasticsearch/reference/{branch}/docs-index_.html
145+
docs-index,https://www.elastic.co/guide/en/elasticsearch/reference/{branch}/docs-index_.html
148146
docs-multi-get,https://www.elastic.co/guide/en/elasticsearch/reference/{branch}/docs-multi-get.html
149147
docs-multi-termvectors,https://www.elastic.co/guide/en/elasticsearch/reference/{branch}/docs-multi-termvectors.html
150148
docs-reindex,https://www.elastic.co/guide/en/elasticsearch/reference/{branch}/docs-reindex.html
151149
docs-termvectors,https://www.elastic.co/guide/en/elasticsearch/reference/{branch}/docs-termvectors.html
152150
docs-update-by-query,https://www.elastic.co/guide/en/elasticsearch/reference/{branch}/docs-update-by-query.html
153-
docs-update-by-query,https://www.elastic.co/guide/en/elasticsearch/reference/{branch}/docs-update-by-query.html
154151
docs-update,https://www.elastic.co/guide/en/elasticsearch/reference/{branch}/docs-update.html
155152
document-input-parameters,https://www.elastic.co/guide/en/elasticsearch/reference/{branch}/query-dsl-mlt-query.html#_document_input_parameters
156153
dot-expand-processor,https://www.elastic.co/guide/en/elasticsearch/reference/{branch}/dot-expand-processor.html
@@ -381,6 +378,7 @@ node-roles,https://www.elastic.co/guide/en/elasticsearch/reference/{branch}/modu
381378
nodes-api-shutdown-delete,https://www.elastic.co/guide/en/elasticsearch/reference/{branch}/delete-shutdown.html
382379
nodes-api-shutdown-status,https://www.elastic.co/guide/en/elasticsearch/reference/{branch}/get-shutdown.html
383380
nodes-api-shutdown,https://www.elastic.co/guide/en/elasticsearch/reference/{branch}/put-shutdown.html
381+
optimistic-concurrency,https://www.elastic.co/guide/en/elasticsearch/reference/{branch}/optimistic-concurrency-control.html
384382
paginate-search-results,https://www.elastic.co/guide/en/elasticsearch/reference/{branch}/paginate-search-results.html
385383
painless-contexts,https://www.elastic.co/guide/en/elasticsearch/painless/{branch}/painless-contexts.html
386384
painless-execute-api,https://www.elastic.co/guide/en/elasticsearch/painless/{branch}/painless-execute-api.html
@@ -684,6 +682,7 @@ set-processor,https://www.elastic.co/guide/en/elasticsearch/reference/{branch}/s
684682
shape,https://www.elastic.co/guide/en/elasticsearch/reference/{branch}/shape.html
685683
simulate-ingest-api,https://www.elastic.co/guide/en/elasticsearch/reference/{branch}/simulate-ingest-api.html
686684
simulate-pipeline-api,https://www.elastic.co/guide/en/elasticsearch/reference/{branch}/simulate-pipeline-api.html
685+
slice-scroll,https://www.elastic.co/guide/en/elasticsearch/reference/{branch}/paginate-search-results.html#slice-scroll
687686
slm-api-delete-policy,https://www.elastic.co/guide/en/elasticsearch/reference/{branch}/slm-api-delete-policy.html
688687
slm-api-execute-lifecycle,https://www.elastic.co/guide/en/elasticsearch/reference/{branch}/slm-api-execute-lifecycle.html
689688
slm-api-execute-retention,https://www.elastic.co/guide/en/elasticsearch/reference/{branch}/slm-api-execute-retention.html

specification/_global/create/CreateRequest.ts

+101-19
Original file line numberDiff line numberDiff line change
@@ -30,13 +30,85 @@ import {
3030
import { Duration } from '@_types/Time'
3131

3232
/**
33-
* Index a document.
34-
* Adds a JSON document to the specified data stream or index and makes it searchable.
35-
* If the target is an index and the document already exists, the request updates the document and increments its version.
33+
* Create a new document in the index.
34+
*
35+
* You can index a new JSON document with the `/<target>/_doc/` or `/<target>/_create/<_id>` APIs
36+
* Using `_create` guarantees that the document is indexed only if it does not already exist.
37+
* It returns a 409 response when a document with a same ID already exists in the index.
38+
* To update an existing document, you must use the `/<target>/_doc/` API.
39+
*
40+
* If the Elasticsearch security features are enabled, you must have the following index privileges for the target data stream, index, or index alias:
41+
*
42+
* * 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.
43+
* * To automatically create a data stream or index with this API request, you must have the `auto_configure`, `create_index`, or `manage` index privilege.
44+
*
45+
* Automatic data stream creation requires a matching index template with data stream enabled.
46+
*
47+
* **Automatically create data streams and indices**
48+
*
49+
* 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.
50+
*
51+
* 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.
52+
*
53+
* NOTE: Elasticsearch includes several built-in index templates. To avoid naming collisions with these templates, refer to index pattern documentation.
54+
*
55+
* If no mapping exists, the index operation creates a dynamic mapping.
56+
* By default, new fields and objects are automatically added to the mapping if needed.
57+
*
58+
* Automatic index creation is controlled by the `action.auto_create_index` setting.
59+
* If it is `true`, any index can be created automatically.
60+
* 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.
61+
* 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.
62+
* When a list is specified, the default behaviour is to disallow.
63+
*
64+
* NOTE: The `action.auto_create_index` setting affects the automatic creation of indices only.
65+
* It does not affect the creation of data streams.
66+
*
67+
* **Routing**
68+
*
69+
* By default, shard placement — or routing — is controlled by using a hash of the document's ID value.
70+
* 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.
71+
*
72+
* 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.
73+
* This does come at the (very minimal) cost of an additional document parsing pass.
74+
* If the `_routing` mapping is defined and set to be required, the index operation will fail if no routing value is provided or extracted.
75+
*
76+
* NOTE: Data streams do not support custom routing unless they were created with the `allow_custom_routing` setting enabled in the template.
77+
*
78+
* ** Distributed**
79+
*
80+
* The index operation is directed to the primary shard based on its route and performed on the actual node containing this shard.
81+
* After the primary shard completes the operation, if needed, the update is distributed to applicable replicas.
82+
*
83+
* **Active shards**
84+
*
85+
* 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.
86+
* 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.
87+
* 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`).
88+
* This default can be overridden in the index settings dynamically by setting `index.write.wait_for_active_shards`.
89+
* To alter this behavior per operation, use the `wait_for_active_shards request` parameter.
90+
*
91+
* 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).
92+
* Specifying a negative value or a number greater than the number of shard copies will throw an error.
93+
*
94+
* 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).
95+
* If you attempt an indexing operation, by default the operation will only ensure the primary copy of each shard is available before proceeding.
96+
* 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.
97+
* 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.
98+
* This requirement should be met because there are 3 active nodes in the cluster, each one holding a copy of the shard.
99+
* 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.
100+
* The operation will timeout unless a new node is brought up in the cluster to host the fourth copy of the shard.
101+
*
102+
* 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.
103+
* 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.
104+
* The `_shards` section of the API response reveals the number of shard copies on which replication succeeded and failed.
36105
* @rest_spec_name create
37106
* @availability stack since=5.0.0 stability=stable
38107
* @availability serverless stability=stable visibility=public
108+
* @index_privileges create
39109
* @doc_tag document
110+
* @doc_id docs-index
111+
* @ext_doc_id data-streams
40112
*/
41113
export interface Request<TDocument> extends RequestBase {
42114
urls: [
@@ -47,56 +119,66 @@ export interface Request<TDocument> extends RequestBase {
47119
]
48120
path_parts: {
49121
/**
50-
* Unique identifier for the document.
122+
* A unique identifier for the document.
123+
* To automatically generate a document ID, use the `POST /<target>/_doc/` request format.
51124
*/
52125
id: Id
53126
/**
54-
* Name of the data stream or index to target.
55-
* 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.
56-
* If the target doesnt exist and doesn’t match a data stream template, this request creates the index.
127+
* The name of the data stream or index to target.
128+
* 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.
129+
* If the target doesn't exist and doesn’t match a data stream template, this request creates the index.
57130
*/
58131
index: IndexName
59132
}
60133
query_parameters: {
61134
/**
62-
* ID of the pipeline to use to preprocess incoming documents.
63-
* If the index has a default ingest pipeline specified, then setting the value to `_none` disables the default ingest pipeline for this request.
64-
* If a final pipeline is configured it will always run, regardless of the value of this parameter.
135+
* The ID of the pipeline to use to preprocess incoming documents.
136+
* If the index has a default ingest pipeline specified, setting the value to `_none` turns off the default ingest pipeline for this request.
137+
* If a final pipeline is configured, it will always run regardless of the value of this parameter.
65138
*/
66139
pipeline?: string
67140
/**
68-
* 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.
69-
* Valid values: `true`, `false`, `wait_for`.
141+
* If `true`, Elasticsearch refreshes the affected shards to make this operation visible to search.
142+
* If `wait_for`, it waits for a refresh to make this operation visible to search.
143+
* If `false`, it does nothing with refreshes.
70144
* @server_default false
71145
*/
72146
refresh?: Refresh
73147
/**
74-
* Custom value used to route operations to a specific shard.
148+
* A custom value that is used to route operations to a specific shard.
75149
*/
76150
routing?: Routing
77151
/**
78-
* Period the request waits for the following operations: automatic index creation, dynamic mapping updates, waiting for active shards.
152+
* The period the request waits for the following operations: automatic index creation, dynamic mapping updates, waiting for active shards.
153+
* Elasticsearch waits for at least the specified timeout period before failing.
154+
* The actual wait time could be longer, particularly when multiple waits occur.
155+
*
156+
* This parameter is useful for situations where the primary shard assigned to perform the operation might not be available when the operation runs.
157+
* Some reasons for this might be that the primary shard is currently recovering from a gateway or undergoing relocation.
158+
* 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.
159+
* The actual wait time could be longer, particularly when multiple waits occur.
79160
* @server_default 1m
80161
*/
81162
timeout?: Duration
82163
/**
83-
* Explicit version number for concurrency control.
84-
* The specified version must match the current version of the document for the request to succeed.
164+
* The explicit version number for concurrency control.
165+
* It must be a non-negative long number.
85166
*/
86167
version?: VersionNumber
87168
/**
88-
* Specific version type: `external`, `external_gte`.
169+
* The version type.
89170
*/
90171
version_type?: VersionType
91172
/**
92173
* The number of shard copies that must be active before proceeding with the operation.
93-
* Set to `all` or any positive integer up to the total number of shards in the index (`number_of_replicas+1`).
174+
* You can set it to `all` or any positive integer up to the total number of shards in the index (`number_of_replicas+1`).
175+
* The default value of `1` means it waits for each primary shard to be active.
94176
* @server_default 1
95177
*/
96178
wait_for_active_shards?: WaitForActiveShards
97179
}
98180
/**
99-
* Request body contains the JSON source for the document data.
181+
* The request body contains the JSON source for the document data.
100182
* @codegen_name document */
101183
body: TDocument
102184
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
# summary:
2+
# method_request: PUT my-index-000001/_create/1
3+
description: >
4+
Run `PUT my-index-000001/_create/1` to index a document into the `my-index-000001` index if no document with that ID exists.
5+
# type: request
6+
value: |-
7+
{
8+
"@timestamp": "2099-11-15T13:12:00",
9+
"message": "GET /search HTTP/1.1 200 1070000",
10+
"user": {
11+
"id": "kimchy"
12+
}
13+
}

0 commit comments

Comments
 (0)