Using curl to Perform CRUD Operations in Elasticsearch
This article introduces Elasticsearch as a Lucene‑based distributed search engine and demonstrates how to use curl commands to create, read, update, and delete documents and indices, providing step‑by‑step examples with command‑line output and screenshots.
Elasticsearch is a search server built on Lucene that offers a distributed, multi‑user full‑text search engine accessed via a RESTful web interface. Developed in Java and released under the Apache license, it is a popular enterprise‑grade search solution used in cloud computing for real‑time, stable, reliable, and fast search, with easy installation.
curl operation: more cumbersome, use this method for CRUD
Kibana operation ES: provides a simplified tool
Write data (specify document ID):
[root@master ~]# curl -u elastic:hahashen -X PUT http://192.168.20.41:9200/hahashen/_doc/1 -H 'Content-Type: application/json' -d '{"name": "hahashen", "age": 30}'View the inserted document formatted with Python:
[root@master ~]# curl -u elastic:hahashen -X PUT http://192.168.20.41:9200/hahashen/_doc/1|python -m json.toolWrite data with a random ID (auto‑generated):
[root@master ~]# curl -u elastic:hahashen -X POST http://192.168.20.41:9200/hahashen/_doc -H 'Content-Type: application/json' -d '{"name": "hahashen", "age": 25}'Update a document:
[root@master ~]# curl -u elastic:hahashen -X POST http://192.168.20.41:9200/hahashen/_update/1 -H 'Content-Type: application/json' -d '{"doc":{"age": 20}}'Delete a document:
[root@master ~]# curl -u elastic:hahashen -X DELETE http://192.168.20.41:9200/hahashen/_doc/1{"_index":"hahashen","_type":"_doc","_id":"1","_version":4,"result":"deleted","_shards":{"total":2,"successful":1,"failed":0},"_seq_no":4,"_primary_term":1}
Delete an entire index:
[root@master ~]# curl -u elastic:hahashen -X DELETE http://192.168.20.41:9200/hahashen{"acknowledged":true}
Signed-in readers can open the original source through BestHub's protected redirect.
This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactand we will review it promptly.
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.
