0Pricing
Elasticsearch & Full Text Search Systems · Lesson

CRUD Operations with Documents

Master the Create, Read, Update, and Delete operations for documents using Elasticsearch's REST API, including partial updates.

CRUD Operations with Documents is a free Elasticsearch & Full Text Search Systems lesson on CoddyKit — lesson 2 of 4. You can read the complete lesson below for free — then practise it hands-on in the browser with a built-in code editor and a 24/7 AI tutor. It is part of the Elasticsearch & Full Text Search Systems learning path, one of 4 lessons in the course, and your progress syncs across the web and the CoddyKit app.

What are CRUD Operations?

In the world of data, CRUD is a fundamental concept. It stands for Create, Read, Update, and Delete.

These are the four basic operations you perform on data in any system, including Elasticsearch. Mastering them is key to managing your search documents effectively.

Indexing New Documents

Adding a new document to Elasticsearch is called indexing. You can index documents:

  • By letting Elasticsearch generate a unique ID (using POST).
  • By providing your own custom ID (using PUT).

The document content is sent as a JSON body.

Example: Indexing a Book

Let's index a book document. We'll use PUT and specify books/_doc/101 to give it a custom ID of 101.

PUT /books/_doc/101
{
  "title": "The Hitchhiker's Guide to the Galaxy",
  "author": "Douglas Adams",
  "year": 1979
}

Retrieving Documents

To fetch a document, you use the Get API. You just need to know its unique ID (_id) and the index it's in.

Elasticsearch will return the document's source (_source) along with metadata like its _index, _id, and _version.

Example: Getting Our Book

Now, let's retrieve the book we just indexed using its ID.

GET /books/_doc/101

Full Document Replacement

One way to update a document is to completely replace it. You use the PUT method with the same document ID.

Be careful! Any fields missing from your new PUT request will be deleted from the original document.

Example: Adding a Genre

Let's add a genre field to our book. Notice how we provide the full document again, including existing fields.

PUT /books/_doc/101
{
  "title": "The Hitchhiker's Guide to the Galaxy",
  "author": "Douglas Adams",
  "year": 1979,
  "genre": "Science Fiction"
}

Efficient Partial Updates

For small changes, fully replacing a document is inefficient. Elasticsearch provides the _update API for partial updates.

This allows you to send only the fields you want to change, making the operation faster and using less bandwidth. You use the POST method.

Example: Changing a Field

Let's update just the year field of our book using the _update API and the "doc" parameter. This merges the changes.

POST /books/_update/101
{
  "doc": {
    "year": 1980
  }
}

Removing Documents

To permanently remove a document from your index, you use the Delete API. Simply specify the index and the document's ID.

Once deleted, the document is gone and cannot be retrieved.

DELETE /books/_doc/101

Quick Check

You have a document with fields name, age, and city. You want to change only the city field to a new value. Which is the most efficient and recommended way to do this in Elasticsearch?

Recap: CRUD in Elasticsearch

Great job! You've learned the essential CRUD operations for managing documents in Elasticsearch:

  • Create (Index): Add new documents with PUT (custom ID) or POST (auto ID).
  • Read (Get): Retrieve documents by ID using GET.
  • Update: Replace documents entirely with PUT or perform efficient partial updates with POST /_update.
  • Delete: Remove documents by ID using DELETE.

These operations form the backbone of interacting with your Elasticsearch data.

Frequently asked questions

Is the “CRUD Operations with Documents” lesson free?

Yes — the full text of “CRUD Operations with Documents” is free to read here on the web, and the Elasticsearch & Full Text Search Systems course includes 4 lessons in total. To practise it interactively (a built-in code editor and a 24/7 AI tutor) and unlock the rest of the Elasticsearch & Full Text Search Systems course, upgrade to CoddyKit PRO.

What will I learn in “CRUD Operations with Documents”?

Master the Create, Read, Update, and Delete operations for documents using Elasticsearch's REST API, including partial updates. You practise Elasticsearch & Full Text Search Systems with hands-on code you run directly in the browser, and a 24/7 AI tutor answers your questions as you work through the lesson.

Do I need any experience to start Elasticsearch & Full Text Search Systems?

No prior experience is required. Elasticsearch & Full Text Search Systems on CoddyKit is structured for beginners through advanced learners; this is — lesson 2 of 4, so you can start here or from the beginning and move at your own pace.

How long does the “CRUD Operations with Documents” lesson take?

Most CoddyKit lessons take about 5–10 minutes. Each one is bite-sized and interactive, so you make steady progress and pick up exactly where you left off across the web and the app.

Can I write and run code in this Elasticsearch & Full Text Search Systems lesson?

Yes. Every Elasticsearch & Full Text Search Systems lesson includes a built-in code editor, so you write and run real code right in your browser and get instant AI feedback — no local setup required.

All lessons in this course

  1. Indexing Documents into Elasticsearch
  2. CRUD Operations with Documents
  3. Basic Mapping and Data Types
  4. Bulk Indexing and the Bulk API
← Back to Elasticsearch & Full Text Search Systems