Get health
curl -XGET 'localhost:9200/_cat/health?v'
Create index
curl -XPUT 'localhost:9200/products?&pretty'
Status yellow --> Don't have replica
GET All indices:
curl -XGET 'localhost:9200/_cat/indices?v&pretty'
Create a document
curl -XPUT 'localhost:9200/products/mobiles/1?pretty' -H 'Content-Type: application/json' -d'
{
"name" : "iPhone 7",
"camera" : "12MP",
"storage" : "256GB",
"display" : "4.7 inch",
"battery" : "1960 mAh",
"reviews": [
"Incredibly happy after having used it for one week",
"Best iPhone so far",
"Very expensive, still prefer Android"
]
}
'
Retrieve Doc:
curl -XGET 'localhost:9200/products/mobiles/1?pretty'
Get specified fields only
curl -XGET 'localhost:9200/products/mobiles/1?pretty&_source=name,reviews'
Update whole doc:
Same with doc creation, but must include id in the url
Partial update the doc:
curl -XPOST 'localhost:9200/products/mobiles/1/_update?pretty' -H 'Content-Type: application/json' -d'
{
"doc" : {
"name" : "iPhone 7 Plus"
}
}
'
New field can be included to partial update body
Update With script
curl -XPOST 'localhost:9200/products/shoes/1/_update?pretty' -H 'Content-Type: application/json' -d'
{
"script": "ctx._source.size -= 1"
}
'
Delete doc:
curl -XDELETE 'localhost:9200/products/shoes/1?pretty'