1.put创建文档
指定的ID,就是文档的_id值。可以根据文档的ID,更新文档的元数据。
--但是POST 创建的文档_id是个UUID值,根据文档的:_id的UUID
--无法操作成功。
{
"took" : 2,
"timed_out" : false,
"_shards" : {
"total" : 1,
"successful" : 1,
"skipped" : 0,
"failed" : 0
},
"hits" : {
"total" : {
"value" : 3,
"relation" : "eq"
},
"max_score" : 1.0,
"hits" : [
{
"_index" : "myindex15",
"_type" : "_doc",
"_id" : "1",
"_score" : 1.0,
"_source" : {
"id" : 1,
"name" : "zhangsan",
"city" : "chengdu",
"course" : "语文",
"teacher" : "李四",
"pxdate" : "riqi"
}
},
{
"_index" : "myindex15",
"_type" : "_doc",
"_id" : "2",
"_score" : 1.0,
"_source" : {
"id" : 2,
"name" : "zhangsan",
"city" : "chengdu",
"course" : "语文",
"teacher" : "李五",
"pxdate" : "riqi"
}
},
{
"_index" : "myindex15",
"_type" : "_doc",
"_id" : "3",
"_score" : 1.0,
"_source" : {
"id" : 3,
"name" : "zhangsan",
"city" : "chengdu",
"course" : "语文",
"teacher" : "李六",
"pxdate" : "riqi"
}
}
]
}
}
2.POST创建文档
post myindex15/_doc
{
"id":4,
"name":"力气",
"city":"shanghai",
"teacher":"zhagnyu"
}
get myindex15/_search
{
"took" : 596,
"timed_out" : false,
"_shards" : {
"total" : 1,
"successful" : 1,
"skipped" : 0,
"failed" : 0
},
"hits" : {
"total" : {
"value" : 4,
"relation" : "eq"
},
"max_score" : 1.0,
"hits" : [
{
"_index" : "myindex15",
"_type" : "_doc",
"_id" : "1",
"_score" : 1.0,
"_source" : {
"id" : 1,
"name" : "zhangsan",
"city" : "chengdu",
"course" : "语文",
"teacher" : "李四",
"pxdate" : "riqi"
}
},
{
"_index" : "myindex15",
"_type" : "_doc",
"_id" : "2",
"_score" : 1.0,
"_source" : {
"id" : 2,
"name" : "zhangsan",
"city" : "chengdu",
"course" : "语文",
"teacher" : "李五",
"pxdate" : "riqi"
}
},
{
"_index" : "myindex15",
"_type" : "_doc",
"_id" : "3",
"_score" : 1.0,
"_source" : {
"id" : 3,
"name" : "zhangsan",
"city" : "chengdu",
"course" : "语文",
"teacher" : "李六",
"pxdate" : "riqi"
}
},
{
"_index" : "myindex15",
"_type" : "_doc",
"_id" : "iz6wXZABmMobXH8At5mW",
"_score" : 1.0,
"_source" : {
"id" : 4,
"name" : "力气",
"city" : "shanghai",
"teacher" : "zhagnyu"
}
}
]
}
}
POST插入的文档的_id='iz6wXZABmMobXH8At5mW';
3.总结
在执行添加字段,删除字段等操作时,PUT方式指定的_ID值的方式更方便。
POST方式创建的文档,无法具体指定文档的_iD值,进行更新。