HTTP POST sends a request body to Elasticsearch when the client does not supply a document ID. Indexing through POST lets Elasticsearch create the document and assign a random unique identifier, which suits incoming events such as alerts, heartbeats, or reviews that do not need client-managed IDs. section 5.1.1 section 5.8
Index a document without choosing its ID
Send JSON to an index’s _doc endpoint without an identifier in the URL. Elasticsearch indexes the document and gives it an ID during indexing. POST myindex/_doc { "title":"Elasticsearch in Action" } Use PUT instead when the client already owns the identifier, such as movies/_doc/1. Choosing POST here avoids inventing and coordinating IDs for every submitted document. section 5.1.1
Listing 5.2 Indexing a document with no ID using POST
POST myindex/_doc #1
{
"title":"Elasticsearch in Action" #2
}
This request shows the minimal POST form: an index and _doc endpoint, followed by the JSON document body; no ID appears in the path. section 5.1.1
POST can also send search requests. Elasticsearch accepts a request body with GET for search and allows POST as a replacement, so either method can address the same search resource. A search payload can hold a query plus pagination, source-field selection, sorting, or highlighting details. section 8.5.1
Choose the request form by the operation and identifier ownership:
- Use POST <index>/_doc with a JSON body when Elasticsearch should generate the document ID. section 5.1.1
- Use PUT <index>/_doc/<ID> when a client-provided ID identifies the document. section 5.1.1
- Use POST for a search request when you prefer it over GET with a request body; Elasticsearch treats both methods the same for that resource. section 8.5.1
An auto-generated ID does not remove the need to think about accidental replacement in workflows that use known IDs. The _create API rejects an indexing attempt when that document already exists, providing a safeguard where overwriting must be avoided. section 5.8













