liveBook · Manning

Request message

As explained in Elasticsearch in Action, Second Edition

The POST method is an HTTP request method used to submit data to a server for processing or resource creation.

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

How Elasticsearch in Action, Second Edition covers it

How deep it goes
Explains POST through endpoint forms, JSON examples, generated IDs, and its interchangeable search-request use with GET.
Examples
Uses an untitled Elasticsearch document, a movie review, and searches whose payloads may include queries, sorting, and highlighting.
What it assumes
Introduces POST alongside plain REST endpoints, JSON request bodies, indexes, and document identifiers without assuming Elasticsearch knowledge.
What you can do after
Apply it via Elasticsearch document and search APIs by posting JSON when IDs are generated or when POST is preferred for searches.
How it connects
Connects POST to HTTP PUT, document IDs, CRUD document APIs, Query DSL, and the _create API.

Also explained in

Compare how 14 books explain request message →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Elasticsearch in Action, Second Edition. The section links point to the parts of the book it draws on.