Databases 8 min read

How Elasticsearch Implements CRUD Operations Like a Relational Database

This article explains how Elasticsearch stores JSON documents, indexes them, and uses RESTful PUT, GET, DELETE, and search APIs to perform create, read, update, and delete operations, illustrating each step with concrete employee examples and query syntax.

Coder Circle
Coder Circle
Coder Circle
How Elasticsearch Implements CRUD Operations Like a Relational Database

Elasticsearch is a document‑oriented store where each record is a JSON document, avoiding the table‑splitting approach of relational databases and enabling fast retrieval without costly object assembly.

Kibana is introduced as a visual companion that can be launched from the bin/kibana script and accessed at http://localhost:5601 for interactive Dev Tools.

To index an employee, the article creates an index company with type employee and sends a PUT /company/employee/1 request containing fields such as name, age, sex, birth, about, and interests. Additional employees are added with similar PUT calls for IDs 2 and 3.

Reading a document is done with GET /company/employee/1, which returns the document inside the _source field and includes metadata like _index, _type, found, and _version.

Searching all employees uses GET /company/employee/_search, which by default returns the first ten hits in the hits array.

A simple name query can be expressed as a URL query string ( GET /company/employee/_search?q=name:zhangsan) or as a request body with a match clause ( {"query":{"match":{"name":"lisi"}}}).

More complex filters use the bool + filter construct; for example, {"query":{"bool":{"filter":{"range":{"age":{"lt":30}}}}}} returns employees younger than 30.

Full‑text search on the about field demonstrates relevance scoring: a match query for "rock climbing" returns the document where the exact phrase appears with the highest score, while a document containing only "rock" appears with a lower score.

When an exact phrase is required, the article shows a match_phrase query that returns only documents containing the whole phrase "rock climbing".

Deletion is performed with DELETE /company/employee/3. The response includes a _version field, indicating that Elasticsearch marks the document as deleted and later removes it during background segment merging.

Updating a document reuses the PUT API with the same ID, adding or modifying fields such as department. The version number increments, confirming the update.

Through this step‑by‑step example, the article demonstrates that basic CRUD functionality in Elasticsearch mirrors relational operations while leveraging its native document model and powerful search capabilities.

IndexingElasticsearchJSONREST APICRUDFull-text searchDocument
Coder Circle
Written by

Coder Circle

Limited experience, continuously learning and summarizing knowledge, aiming to join a top tech company.

0 followers
Reader feedback

How this landed with the community

Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.