Master Elasticsearch Index & Document Operations with Simple REST Calls
This guide walks through using Elasticsearch 7.8.0 and Postman to create, view, update, and delete indices and documents via RESTful API calls, including mapping setup and query‑based deletions, providing clear code examples and request details.
Environment: Elasticsearch 7.8.0 + Postman
Index Operations
1. Create Index
Method: PUT
URL: http://localhost:9200/users
<code>{
"settings": {
"number_of_shards": 3,
"number_of_replicas": 0
}
}</code>number_of_shards: number of shards
number_of_replicas: number of replicas
2. View All Indices
Method: GET
URL: http://localhost:9200/_cat/indices?v
3. View Single Index
Method: GET
URL: http://localhost:9200/users
4. Delete Index
Method: DELETE
URL: http://localhost:9200/users
Document Operations
1. Create Document
Method: POST
URL: http://localhost:9200/users/_doc
<code>{"name":"张三", "sex":"男", "age":30}</code>2. Create Document with Specified ID
Method: POST
URL: http://localhost:9200/student/_doc/唯一I
<code>{"name":"莉莉", "sex":"女","age":30}</code>3. View Document
Method: GET
URL: http://localhost:9200/users/_doc/唯一ID
4. Update Document
Method: POST
URL: http://localhost:9200/users/_doc/唯一I
<code>{"name":"莉莉007", "sex":"女","age":60}</code>5. Partial Update (Field)
Method: POST
URL: http://localhost:9200/users/_update/唯一ID
<code>{
"doc": {
"age":50
}
}</code>6. Delete Document
Method: DELETE
URL: http://localhost:9200/users/_doc/唯一ID
7. Delete Documents by Query
Method: POST
URL: http://localhost:9200/users/_delete_by_query
<code>{
"query": {
"match": {
"age": 50
}
}
}</code>Mapping Creation
1. Create Mapping
Method: PUT
URL: http://localhost:9200/users/_mapping
<code>{
"properties": {
"name": {"type": "text", "index": true},
"sex": {"type": "text", "index": true},
"age": {"type": "long", "index": true}
}
}</code>2. View Mapping
Method: GET
URL: http://localhost:9200/users/_mapping
Spring Full-Stack Practical Cases
Full-stack Java development with Vue 2/3 front-end suite; hands-on examples and source code analysis for Spring, Spring Boot 2/3, and Spring Cloud.
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.