zoukankan      html  css  js  c++  java
  • 商品的CRUD操作

    (1)新增商品:新增文档,建立索引

    PUT /index/type/id
    {
    "json数据"
    }

    PUT /ecommerce/product/1
    {
    "name" : "gaolujie yagao",
    "desc" : "gaoxiao meibai",
    "price" : 30,
    "producer" : "gaolujie producer",
    "tags": [ "meibai", "fangzhu" ]
    }

    {
    "_index": "ecommerce",
    "_type": "product",
    "_id": "1",
    "_version": 1,
    "result": "created",
    "_shards": {
    "total": 2,
    "successful": 1,
    "failed": 0
    },
    "created": true
    }

    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" : "caoben zhiwu",
    "price" : 40,
    "producer" : "zhonghua producer",
    "tags": [ "qingxin" ]
    }

    es会自动建立index和type,不需要提前创建,而且es默认会对document每个field都建立倒排索引,让其可以被搜索

    (2)查询商品:检索文档

    GET /index/type/id
    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"
    ]
    }
    }

    (3)修改商品:替换文档

    PUT /ecommerce/product/1
    {
    "name" : "jiaqiangban gaolujie yagao",
    "desc" : "gaoxiao meibai",
    "price" : 30,
    "producer" : "gaolujie producer",
    "tags": [ "meibai", "fangzhu" ]
    }

    {
    "_index": "ecommerce",
    "_type": "product",
    "_id": "1",
    "_version": 1,
    "result": "created",
    "_shards": {
    "total": 2,
    "successful": 1,
    "failed": 0
    },
    "created": true
    }

    {
    "_index": "ecommerce",
    "_type": "product",
    "_id": "1",
    "_version": 2,
    "result": "updated",
    "_shards": {
    "total": 2,
    "successful": 1,
    "failed": 0
    },
    "created": false
    }


    PUT /ecommerce/product/1
    {
    "name" : "jiaqiangban gaolujie yagao"
    }

    替换方式有一个不好,即使必须带上所有的field,才能去进行信息的修改

    (4)修改商品:更新文档

    POST /ecommerce/product/1/_update
    {
    "doc": {
    "name": "jiaqiangban gaolujie yagao"
    }
    }

    {
    "_index": "ecommerce",
    "_type": "product",
    "_id": "1",
    "_version": 8,
    "result": "updated", //变了
    "_shards": {
    "total": 2,
    "successful": 1,
    "failed": 0
    }
    }

    (5)删除商品:删除文档

    DELETE /ecommerce/product/1

    {
    "found": true,
    "_index": "ecommerce",
    "_type": "product",
    "_id": "1",
    "_version": 9,
    "result": "deleted",
    "_shards": {
    "total": 2,
    "successful": 1,
    "failed": 0
    }
    }

    {
    "_index": "ecommerce",
    "_type": "product",
    "_id": "1",
    "found": false
    }

  • 相关阅读:
    css选择器的优先级
    ECHO.js 纯javascript轻量级延迟加载
    Chrome测试网站加载时间与流量消耗
    演示:纯CSS实现自适应布局表格
    通过jquery-ui中的sortable来实现拖拽排序
    XAMPP下的composer的安装
    jQuery动态五星评分
    HTML,CSS编码规范
    mysql排序,可以对统计的数据进行排序
    thinkphp中配置信息的二维数组设置与使用
  • 原文地址:https://www.cnblogs.com/kesimin/p/9559825.html
Copyright © 2011-2022 走看看