ElasticSearch之——文档增删改查

转载请注明出处:https://blog.csdn.net/l1028386804/article/details/79720625

这里,我们使用一个实例来说明,不多说,直接上代码:

#创建文档1
PUT /ecommerce/product/1
{
    "name" : "gaolujie yagao",
    "desc" :  "gaoxiao meibai",
    "price" :  30,
    "producer" :      "gaolujie producer",
    "tags": [ "meibai", "fangzhu" ]
}
#创建文档2
PUT /ecommerce/product/2
{
    "name" : "jiajieshi yagao",
    "desc" :  "youxiao fangzhu",
    "price" :  25,
    "producer" :      "jiajieshi producer",
    "tags": [ "fangzhu" ]
}
#创建文档3
PUT /ecommerce/product/3
{
    "name" : "zhonghua yagao",
    "desc" :  "caoben zhiwu",
    "price" :  40,
    "producer" :      "zhonghua producer",
    "tags": [ "qingxin" ]
}

#查看文档
GET /ecommerce/product/1

#更新文档方式1,注意:此种方式必须传递文档的所有参数
PUT /ecommerce/product/1
{
    "name" : "jiaqiangban gaolujie yagao",
    "desc" :  "gaoxiao meibai",
    "price" :  30,
    "producer" :      "gaolujie producer",
    "tags": [ "meibai", "fangzhu" ]
}

#更新文档2,此种方式只需要传递待更新的字段
POST /ecommerce/product/1/_update
{
  "doc": {
    "name": "jiaqiangban gaolujie yagao"
  }
}

#删除文档
DELETE /ecommerce/product/1

你可能感兴趣的:(ElasticSearch,搜索优化)