Finally, The E
in ELK stack, elasticsearch
In this step, we will explore some common Elasticsearch APIs and Document APIs using Kibana's Dev Tools. We'll create a new index, demonstrate various document operations, and finally delete the index.
-
Open your web browser and navigate to Kibana. By default, Kibana is hosted at
http://localhost:5601
. -
In the Kibana interface, click on the "Dev Tools" link in the left-hand sidebar. This will open the Dev Tools panel where we can execute Elasticsearch APIs.
- Checks the health of the Elasticsearch cluster, providing information about its status.
- Example API request:
GET /_cluster/health
- Retrieves the cluster's metadata and current state.
- Example API request:
GET /_cluster/state
Elasticsearch provides a set of Cat APIs that are designed to make it easier to view information about the cluster, nodes, indices, and more in a human-readable format. These APIs are often used for monitoring and troubleshooting purposes.
- Example APIs:
GET _cat/indices
When appending ?pretty=true to any request made, the JSON returned will be pretty formatted
- Retrieves information about the nodes in the Elasticsearch cluster.
- Example API request:
GET /_nodes
Let's start by creating a new index named "my-index."
PUT /my-index
- Adds or updates a document in an index.
- Example API request to add a document to the "my-index" index:
POST /my-index/_doc/1 { "field1": "value1", "field2": "value2" }
- Retrieves a specific document by its ID.
- Example API request to get a document from the "my-index" index:
GET /my-index/_doc/1
- Updates an existing document.
- Example API request to update a document in the "my-index" index:
POST /my-index/_update/1 { "doc": { "field2": "new_value" } }
- Deletes a document by its ID.
- Example API request to delete a document from the "my-index" index:
DELETE /my-index/_doc/1
- Allows you to perform multiple index, update, or delete operations in a single request.
- Example API request to perform bulk operations:
POST /my-index/_bulk { "index": { "_id": "1" } } { "field1": "value1" } { "delete": { "_id": "2" } } { "update": { "_id": "3" } } { "doc": { "field2": "new_value" } }
To clean up, let's delete the "my-index" index.
DELETE /my-index