一、格式
http://192.168.0.1:9200/<index>/<type>/[<id>]
- index:代表数据库
- type:对应表
二、增
//可以使用put,也可以使用post
curl -XPUT "http://192.168.0.1:9200/store/books/1" -d '{
"title":"Elastticsearch: The Definitive Guide",
"name": {
"first": "jason",
"last": "lai"
},
"publish_date":"2015-02-06",
"price":"88.88"
}'
- 返回如下信息
{"_index":"store","_type":"books","_id":"1","_version":1,"result":"created","_shards":{"total":2,"successful":1,"failed":0},"created":true}
三、删
curl -XDELETE 'http://192.168.0.1:9200/store/books/1'
四、改(将价格字段由原来的88.88改为99.99)
//可以使用put,也可以使用post
curl -XPUT "http://192.168.0.1:9200/store/books/1" -d '{
"title":"Elastticsearch: The Definitive Guide",
"name": {
"first": "jason",
"last": "lai"
},
"publish_date":"2015-02-06",
"price":"99.99"
}'
五、查
- 使用curl查询,也可以是用浏览器查询
curl -XGET "http://192.168.0.1:9200/store/books/1"
- 返回如下信息
{"_index":"store","_type":"books","_id":"1","_version":1,"found":true,"_source":{
"title":"Elastticsearch: The Definitive Guide",
"name": {
"first": "jason",
"last": "lai"
},
"publish_date":"2015-02-06",
"price":"88.88"
}
}
- 可以指定字段查询(_source代表返回字段)
curl -XGET "http://192.168.0.1:9200/store/books/1?_source=title,name"
返回如下信息
{"_index":"store","_type":"books","_id":"1","_version":2,"found":true,"_source":{"name":{"first":"Vineeth","last":"Mohan"},"title":"Elastticsearch Blueprints"}}