• 基础查询

    QQ截图20210313182039.png**

    • 保存数据

    PUT 方式 : **提交必须带唯一标识**(以下简称id)
    url格式 : http://localhost:9200/索引名称/类型名/id
    若id 不存在就新建,存在就修改并且累加**版本**号

    POST 方式 :
    url格式 : http://localhost:9200/索引名称/类型名/id
    若id 不存在就新建并且自动设置id,存在就修改并且累加版本号

    发送的json格式 : {
    “字段”:内容
    }
    返回的json :{
    “_index”: “yym”, #索引名
    “_type”: “type”, #类型名
    “_id”: “3”, #唯一标识
    “_version”: 1, #版本号
    “result”: “created”, #操作
    “_shards”: { #集群相关
    “total”: 2,
    “successful”: 1,
    “failed”: 0
    },
    }


    • 读取数据

    GET 方式 :
    url格式 : http://localhost:9200/索引名称/类型名/想要获取的id

    返回的json :{
    “_index”: “yym”, #索引名
    “_type”: “type”, #类型名
    “_id”: “1”, #唯一标识
    “_version”: 4, #版本号
    “_seq_no”: 4, #并发控制字段 数据更细会+1
    “_primary_term”: 1, #并发控制字段 主分片重新分配会+1
    “found”: true,
    “_source”: { #数据本体
    “name”: “1”
    }
    }

    通过并发控制字段实现乐观锁
    url格式 :http://localhost:9200/索引名称/类型名/想要获取的id?if_seq_no=0&if_primary_term=1


    • 修改

    POST 方式 :
    url格式 : http://localhost:9200/索引名称/类型名/id/_update
    发送的json格式 : {
    “doc”:{
    “字段”:内容
    }
    }

    这种方式更新数据会对原数据 当数据没有变化操作会显示 noop 就不会进行任何操作
    而使用上述保存数据的方法也进行更新 不会对比原数据 数据相同也会进行修改**


    • 删除

    DELETE 方式 :
    url格式 : http://localhost:9200/索引名称/类型名/id
    也可直接删除索引
    url格式 : http://localhost:9200/索引名称