Elasticsearch Index Operations: Creation, Retrieval, Deletion, and Settings
This article explains Elasticsearch index concepts, index types, and provides step‑by‑step REST commands for creating, listing, deleting indices, indexing documents, querying, managing shards and replicas, and checking cluster health.
In Elasticsearch, an index is a logical storage unit comparable to a database in relational systems; it can reside on a single node or be sharded across multiple nodes, with each index containing one or more shards and each shard optionally having replicas.
An index type (index_type) functions like a table, allowing a single index to store different kinds of objects; each type can have its own mapping, but the same field cannot be assigned different data types across types.
The following REST commands illustrate common index operations:
PUT /hahashen_es – create an index named hahashen_es .
GET _cat/indices – list all indices in the cluster.
DELETE /hahashen_es – delete the index hahashen_es .
POST /aa/_doc/2
{
"name": "hahashen",
"age": 25,
"add": "beijing"
}
adds a document to the index.
GET /hahashen_es/_search – retrieve the first 10 documents from the index.
GET /hahashen_es/_doc/1 – fetch a specific document by its ID.
DELETE /hahashen_es/_doc/1 – delete a document by its ID.
To configure shards and replicas, use:
PUT /hahashen_index
{
"settings": {
"index": {
"number_of_shards": 3,
"number_of_replicas": 1
}
}
}
Finally, cluster health can be checked with:
curl http://172.16.1.162:9200/_cluster/health?pretty
Practical DevOps Architecture
Hands‑on DevOps operations using Docker, K8s, Jenkins, and Ansible—empowering ops professionals to grow together through sharing, discussion, knowledge consolidation, and continuous improvement.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.