|
REST API (curl -X ...) |
Dev Tools (OpenSearch Dashboards) |
health |
GET "https://localhost:9200/_cluster/health |
GET _cluster/health |
index
a document
(add an entry to an index)
(index students is automatically created) |
PUT
https://<host>:<port>/<index-name>/_doc/<document-id> |
PUT /students/_doc/1
{
"name": "John Doe",
"gpa": 3.89,
"grad_year": 2022
} |
dynamic
mapping
|
|
GET /students/_mapping
|
Search
your data
|
|
GET /students/_search
GET
/students/_search
{
"query": {
"match_all": {}
}
}
|
Updating
documents (total upload)
|
|
PUT /students/_doc/1
{
"name": "John Doe",
"gpa": 3.91,
"grad_year": 2022,
"address": "123 Main St."
}
|
Updating documents (partial upload) |
|
POST /students/_update/1/
{
"doc": {
"gpa": 3.74,
"address": "123 Main St."
}
} |
Delete a document |
|
DELETE /students/_doc/1 |
Delete index
|
|
DELETE /students
|
Index mapping and settings |
|
PUT /students
{
"settings": {
"index.number_of_shards": 1
},
"mappings": {
"properties": {
"name": {
"type":
"text"
},
"grad_year": {
"type":
"date"
}
}
}
}
GET /students/_mapping |
Bulk
ingestion |
POST "https://localhost:9200/_bulk"
-H 'Content-Type: application/json' -d'
{ "create": { "_index": "students", "_id": "2" } }
{ "name": "Jonathan Powers", "gpa": 3.85, "grad_year":
2025 }
{ "create": { "_index": "students", "_id": "3" } }
{ "name": "Jane Doe", "gpa": 3.52, "grad_year": 2024 }
' |
POST _bulk
{ "create": { "_index": "students", "_id": "2" } }
{ "name": "Jonathan Powers", "gpa": 3.85, "grad_year":
2025 }
{ "create": { "_index": "students", "_id": "3" } }
{ "name": "Jane Doe", "gpa": 3.52, "grad_year": 2024 } |
Ingest from local json files (sample mapping) |
curl -H "Content-Type: application/json" -X PUT
"https://localhost:9200/ecommerce" -ku
admin:<custom-admin-password> --data-binary
"@ecommerce-field_mappings.json" |
|
Ingest from local json files (sample data) |
curl -H "Content-Type: application/x-ndjson" -X
PUT "https://localhost:9200/ecommerce/_bulk" -ku
admin:<custom-admin-password> --data-binary
"@ecommerce.ndjson" |
|
Query |
|
GET /ecommerce/_search
{
"query": {
"match": {
"customer_first_name":
"Sonya"
}
}
} |
Query string queries |
|
GET /students/_search?q=name:john |
|
|
|