• 商品的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
    }

  • 相关阅读:
    Codeforces Beta Round #6 (Div. 2 Only)
    Codeforces Beta Round #5
    Codeforces Beta Round #4 (Div. 2 Only)
    Codeforces Beta Round #3
    Codeforces Beta Round #2
    Codeforces Beta Round #1
    HDU 4020 Ads Proposal
    SRM 615 DIV1 500
    求1+2+……+n(位运算)
    好好加油!
  • 原文地址:https://www.cnblogs.com/kesimin/p/9559825.html
Copyright © 2020-2023  润新知