创建文档:
# curl -H”Content-Type: application/json” -XPUT ‘node1:9200/students/class1/1?pretty’ -d ‘
{
“first_name”:”Zhong”,
“last_name”:”MingJia”,
“gender”:”Female”,
“age”:23,
“courses”:”Xiang Long Shi Ba Zhang”
}’
{
“_index” : “students”,
“_type” : “class1”,
“_id” : “1”,
“_version” : 1,
“result” : “created”,
“_shards” : {
“total” : 2,
“successful” : 2,
“failed” : 0
},
“_seq_no” : 0,
“_primary_term” : 1
}
获取文档:
# curl -H”Content-type: application/json” -XGET ‘node1:9200/students/class1/1?pretty’
{
“_index” : “students”,
“_type” : “class1”,
“_id” : “1”,
“_version” : 1,
“found” : true,
“_source” : {
“first_name” : “Zhong”,
“last_name” : “MingJia”,
“gender” : “Female”,
“age” : 23,
“courses” : “Xiang Long Shi Ba Zhang”
}
}
更新文档:
PUT方法会覆盖原有文档;
如果只更新部分内容,得使用_update API
# curl -H”Content-type: application/json” -XPOST ‘node1:9200/students/class1/1/_update?pretty’ -d ‘
{
“doc”: { “age” : 22 }
}’
{
“_index” : “students”,
“_type” : “class1”,
“_id” : “3”,
“_version” : 2,
“result” : “updated”,
“_shards” : {
“total” : 2,
“successful” : 2,
“failed” : 0
},
“_seq_no” : 1,
“_primary_term” : 1
}
删除文档:
DETELE
# curl -XDELETE ‘node1:9200/students/class1/1?pretty’
{
“_index” : “students”,
“_type” : “class1”,
“_id” : “1”,
“_version” : 3,
“result” : “deleted”,
“_shards” : {
“total” : 2,
“successful” : 2,
“failed” : 0
},
“_seq_no” : 6,
“_primary_term” : 1
}
# curl -XGET ‘node1:9200/_cat/indices?v&pretty’
health status index uuid pri rep docs.count docs.deleted store.size pri.store.size
green open students Vjc_PE8rRsOIpRXTjau7Aw 5 1 1 0 23.3kb 11.6kb
删除索引:
# curl -H”Conten-type: application/json” -XDELETE ‘node1:9200/students?pretty’
{
“acknowledged” : true
}
# curl -XGET ‘node1:9200/_cat/indices?v&pretty’
health status index uuid pri rep docs.count docs.deleted store.size pri.store.size
green open students Vjc_PE8rRsOIpRXTjau7Aw 5 1 1 0 12.8kb 6.4kb