文档
,即索引库中某个类型下的数据,会根据规则创建索引,将来用来搜索。可以类比做数据库中的每一行数据。
1. 新增并随机生成id
通过POST请求,可以向一个已经存在的索引库中添加文档数据。
语法:
POST /索引库名/类型名
{
“key” : “value”
}
示例:
post /test/goods
{
"title" : "小米手机",
"image":"http://image.leyou.com/12479122.jpg",
"price" : 2699.00
}
响应:
{
"_index" : "test",
"_type" : "goods",
"_id" : "p8X69nMBlhrBXMVW17-V",
"_version" : 1,
"result" : "created",
"_shards" : {
"total" : 2,
"successful" : 1,
"failed" : 0
},
"_seq_no" : 0,
"_primary_term" : 1
}
可以看到结果显示为:created
,应该是创建成功了。
另外,需要注意的是,在响应结果中有个_id
字段,这个就是这条文档数据的唯一标示
,以后的增