This article provides a guide on Elasticsearch CRUD commands for creating, updating, retrieving, and deleting indices and documents using Kibana’s DevTools interface.
Welcome to this comprehensive lesson on Elasticsearch CRUD commands. In this guide, we demonstrate how to create, update, retrieve, and delete indices and documents through Kibana’s DevTools interface. Follow the sections below to learn how to interact with Elasticsearch using various commands.The Kibana UI provides an intuitive editor where you can send requests to Elasticsearch. The left pane is for entering commands, while the right pane displays the corresponding output. Let’s dive in.
Before executing any modifications, it is advisable to verify the health of your Elasticsearch cluster. Run this GET request to check the cluster’s status:
Copy
Ask AI
GET /_cluster/health
A successful response (HTTP status 200) returns details similar to the example below:
Attempting to update a document using the PUT command may result in issues, as it replaces the entire document rather than updating specific fields. For example:
Copy
Ask AI
PUT /products/_doc/1{ "price": 129.99}
This approach can trigger a parsing exception (HTTP status 400) if not formatted correctly.
To modify only specific fields without replacing the entire document, use the POST command with the _update endpoint. First, ensure your document exists:
Copy
Ask AI
POST /products/_doc/1{ "product_id": 67890, "name": "Cozy Winter Sweater", "description": "Soft and stylish sweater for cold days", "price": 59.99, "category": "Apparel", "brand": "Trendy Threads"}
Now, update specific fields using:
Copy
Ask AI
POST /products/_doc/1/_update{ "doc": { "description": "Soft and stylish sweater for cold days. Available in multiple colors.", "category": "Apparel - Seasonal" }}
After executing this update command, verify the changes by retrieving the document again:
Copy
Ask AI
GET /products/_doc/1
Using PUT replaces the whole document, whereas using POST with _update only modifies the designated fields.
Mastering these Elasticsearch CRUD commands is essential for effective data management and troubleshooting in your Elasticsearch environment. Experiment with these commands in Kibana’s DevTools to enhance your understanding and ensure smooth operations.Happy querying!