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.
Path parameters
-
Name of the data stream or index to target.
-
Unique identifier for the document.
Query parameters
-
if_primary_term number
Only perform the operation if the document has this primary term.
-
if_seq_no number
Only perform the operation if the document has this sequence number.
-
op_type string
Set to create to only index the document if it does not already exist (put if absent). If a document with the specified
_id
already exists, the indexing operation will fail. Same as using the<index>/_create
endpoint. Valid values:index
,create
. If document id is specified, it defaults toindex
. Otherwise, it defaults tocreate
.Values are
index
orcreate
. -
pipeline string
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. -
refresh string
If
true
, Elasticsearch refreshes the affected shards to make this operation visible to search, ifwait_for
then wait for a refresh to make this operation visible to search, iffalse
do nothing with refreshes. Valid values:true
,false
,wait_for
.Values are
true
,false
, orwait_for
. -
routing string
Custom value used to route operations to a specific shard.
-
timeout string
Period the request waits for the following operations: automatic index creation, dynamic mapping updates, waiting for active shards.
-
version number
Explicit version number for concurrency control. The specified version must match the current version of the document for the request to succeed.
-
version_type string
Specific version type:
external
,external_gte
.Values are
internal
,external
,external_gte
, orforce
. -
wait_for_active_shards number | string
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
). -
require_alias boolean
If
true
, the destination must be an index alias.
curl \
-X POST http://api.example.com/{index}/_doc/{id} \
-H "Content-Type: application/json"
{}
{
"_id": "string",
"_index": "string",
"_primary_term": 42.0,
"result": "created",
"_seq_no": 42.0,
"_shards": {
"failed": 42.0,
"successful": 42.0,
"total": 42.0,
"failures": [
{
"index": "string",
"node": "string",
"reason": {
"type": "string",
"reason": "string",
"stack_trace": "string",
"caused_by": {},
"root_cause": [
{}
],
"suppressed": [
{}
]
},
"shard": 42.0,
"status": "string"
}
],
"skipped": 42.0
},
"_version": 42.0,
"forced_refresh": true
}