liveBook · Manning

CRUD

As explained in Elasticsearch in Action, Second Edition

CRUD is the set of operations for creating, reading, updating, and deleting stored resources.

CRUD groups the basic operations for stored Elasticsearch documents: create, read, update, and delete. Single-document APIs target one document, while multi-document APIs handle sets of documents in one request. section 5.1.1 section 5.8

A document ID identifies a document for its lifetime, much like a relational primary key. Index a document with a client-provided ID using PUT; omit the ID and use POST, which assigns a generated UUID. section 5.1.1 section 5.8

Create a movie with a known ID

Use PUT when the application chooses the identity. The index name, _doc endpoint, and final path segment identify where the movie is stored and which document it is. section 5.1.1

Listing 5.1 Indexing a new document into the movies index
PUT movies/_doc/1           #1
{                           #2
  "title":"The Godfather", 
  "synopsis":"The aging patriarch of an organized crime dynasty transfers 
   control of his clandestine empire to his reluctant son"
}

This request creates or indexes The Godfather document at ID 1 in the movies index. section 5.1.1

For safer creation, use _create: it returns an error when the ID already exists instead of overriding the document. Retrieve several known documents with _mget, perform grouped indexing, deletion, or updates with _bulk, and use _update or _update_by_query to modify documents. Delete one document with DELETE or many with _delete_by_query. section 5.1.1 section 5.8

CRUD has storage and operational consequences: indexed documents first reside in a shard’s in-memory buffer, then refresh into segments that Lucene later merges. Reindexing transfers data from a source index to a destination index. section 5.8

How Elasticsearch in Action, Second Edition covers it

How deep it goes
Explains request methods, IDs, conflict prevention, batch operations, updates, deletion, and refresh-to-segment storage behavior.
Examples
Uses movie documents including The Godfather and Mission: Impossible, plus an ID-less movie review.
What it assumes
Introduces document identifiers and PUT-versus-POST indexing from basic RESTful API use.
What you can do after
Apply it via Elasticsearch document APIs to index, retrieve, update, delete, and batch-process documents while avoiding accidental overwrites.
How it connects
Connects CRUD to REST, HTTP PUT and POST, document IDs, UUIDs, _bulk, _update_by_query, and reindexing.

Also explained in

Compare how 11 books explain CRUD →

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.