新增商品
PUT /index/type/id
PUT /ecommerce/product/1
{
"name": "gaolujie yagao",
"desc": "gaoxiao meibai",
"price": 30,
"producer": "gaolujie producer",
"tags": ["meibai", "fangzhu"]
}
PUT /ecommerce/product/2
{
"name": "jiajieshi yagao",
"desc": "youxiao fangzhu",
"price": 25,
"producer": "jiajieshi producer",
"tags": ["fangzhu"]
}
PUT /ecommerce/product/3
{
"name": "zhonghua yagao",
"desc": "qingxinkouqi",
"price": 40,
"producer": "zhonghua producer",
"tags": ["qingxin"]
}
es会自动建立index和type,不需要提前创建,而且es默认会对document每个field都建立倒排索引,让其可以被搜索。
执行一条返回结果为
{
"_index": "ecommerce",
"_type": "product",
"_id": "1",
"_version": 1,
"result": "created",
"_shards": {
"total": 2,
"successful": 1,
"failed": 0
},
"created": true
}
查询商品
GET /ecommerce/product/1
// 返回结果
{
"_index": "ecommerce",
"_type": "product",
"_id": "1",
"_version": 1,
"found": true,
"_source": {
"name": "gaolujie yagao",
"desc": "gaoxiao meibai",
"price": 30,
"producer": "gaolujie producer",
"tags": [
"meibai",
"fangzhu"
]
}
}
修改商品:替换文档
PUT /ecommerce/product/1
{
"name": "new gaolujie yagao",
"desc": "gaoxiao meibai",
"price": 30,
"producer": "gaolujie producer",
"tags": ["meibai", "fangzhu"]
}
// 返回结果
{
"_index": "ecommerce",
"_type": "product",
"_id": "1",
"_version": 2,
"result": "updated",
"_shards": {
"total": 2,
"successful": 1,
"failed": 0
},
"created": false
}
修改商品:更新文档
POST /ecommerce/product/1/_update
{
"doc": {
"name": "new gaolujie yagao 2"
}
}
// 返回结果
{
"_index": "ecommerce",
"_type": "product",
"_id": "1",
"_version": 3,
"result": "updated",
"_shards": {
"total": 2,
"successful": 1,
"failed": 0
}
}
删除商品
DELETE /ecommerce/product/1
//返回结果
{
"found": true,
"_index": "ecommerce",
"_type": "product",
"_id": "1",
"_version": 4,
"result": "deleted",
"_shards": {
"total": 2,
"successful": 1,
"failed": 0
}
}