添加文档
POST /user/docs
{
"name": "张三",
"sex": 1,
"age": 25,
"address": "北京市"
}
POST /user/docs
{
"name": "张三",
"sex": 1,
"age": 25,
"address": "北京市"
}
添加成功返回
{
"_index" : "user",
"_type" : "docs",
"_id" : "ci_ApnsBetYTPGlJc287",
"_version" : 1,
"result" : "created",
"_shards" : {
"total" : 2,
"successful" : 1,
"failed" : 0
},
"_seq_no" : 0,
"_primary_term" : 1
}
{
"_index" : "user",
"_type" : "docs",
"_id" : "ci_ApnsBetYTPGlJc287",
"_version" : 1,
"result" : "created",
"_shards" : {
"total" : 2,
"successful" : 1,
"failed" : 0
},
"_seq_no" : 0,
"_primary_term" : 1
}
不指定ID默认会自动生成一个不重复的随机ID,且可以重复添加。指定ID后重复执行就是更新(全量更新)。
指定一个ID为3的数据
POST /user/docs/3
{
"name": "王五",
"sex": 1,
"age": 25,
"address": "河北省"
}
POST /user/docs/3
{
"name": "王五",
"sex": 1,
"age": 25,
"address": "河北省"
}
添加成功返回,可以看到 _id 已经是3了
{
"_index" : "user",
"_type" : "docs",
"_id" : "3",
"_version" : 1,
"result" : "created",
"_shards" : {
"total" : 2,
"successful" : 1,
"failed" : 0
},
"_seq_no" : 6,
"_primary_term" : 1
}
{
"_index" : "user",
"_type" : "docs",
"_id" : "3",
"_version" : 1,
"result" : "created",
"_shards" : {
"total" : 2,
"successful" : 1,
"failed" : 0
},
"_seq_no" : 6,
"_primary_term" : 1
}
重复执行返回,result已经变成了updated
{
"_index" : "user",
"_type" : "docs",
"_id" : "3",
"_version" : 3,
"result" : "updated",
"_shards" : {
"total" : 2,
"successful" : 1,
"failed" : 0
},
"_seq_no" : 8,
"_primary_term" : 1
}
{
"_index" : "user",
"_type" : "docs",
"_id" : "3",
"_version" : 3,
"result" : "updated",
"_shards" : {
"total" : 2,
"successful" : 1,
"failed" : 0
},
"_seq_no" : 8,
"_primary_term" : 1
}