赞
踩
由于没有指定数据唯一性标识(ID),默认情况下, ES 服务器会随机生成一个。
- POST /shopping/_doc
- {
- "title":"小米手机",
- "category":"小米",
- "images":"http://www.gulixueyuan.com/xm.jpg",
- "price":3999.00
- }
- 返回结果:
- {
- "_index": "shopping",//索引
- "_type": "_doc",//类型-文档
- "_id": "ANQqsHgBaKNfVnMbhZYU",//唯一标识,可以类比为 MySQL 中的主键,随机生成
- "_version": 1,//版本
- "result": "created",//结果,这里的 create 表示创建成功
- "_shards": {//
- "total": 2,//分片 - 总数
- "successful": 1,//分片 - 总数
- "failed": 0//分片 - 总数
- },
- "_seq_no": 0,
- "_primary_term": 1
- }

- POST /shopping/_doc/1
- {
- "title":"小米手机",
- "category":"小米",
- "images":"http://www.gulixueyuan.com/xm.jpg",
- "price":3999.00
- }
- 返回结果:
- {
- "_index": "shopping",
- "_type": "_doc",
- "_id": "1",//<------------------自定义唯一性标识
- "_version": 1,
- "result": "created",
- "_shards": {
- "total": 2,
- "successful": 1,
- "failed": 0
- },
- "_seq_no": 1,
- "_primary_term": 1
- }

- 先建个索引
- PUT student
- {
- "mappings" : {
- "properties" : {
- "name" : {
- "type" : "keyword"
- },
- "age" : {
- "type" : "integer"
- }
- }
- }
- }
- //批量创建
- POST _bulk
- { "index" : { "_index" : "student", "_id" : "1" } }
- { "name" : "张三", "age": 12}
- { "index" : { "_index" : "student", "_id" : "2" } }
- { "name" : "李四", "age": 10 }
- { "index" : { "_index" : "student", "_id" : "3" } }
- { "name" : "王五", "age": 11 }
- { "index" : { "_index" : "student", "_id" : "4" } }
- { "name" : "陈六", "age": 11 }

- POST /shopping/_doc/1
- {
- "title":"华为手机",
- "category":"华为",
- "images":"http://www.gulixueyuan.com/hw.jpg",
- "price":1999.00
- }
使用 _update 时,ES 做了下面几件事:
- POST /shopping/_update/1
- {
- "doc": {
- "title":"小米手机",
- "category":"小米"
- }
- }
将文档id为2的age属性值改为12,如下
- POST student/_update_by_query
- {
- "query": {
- "match": {
- "_id": 2
- }
- },
- "script": {
- "source": "ctx._source.age = 12"
- }
- }
DELETE /shopping/_doc/1
根据term、match等查询方式去删除大量的文档
- POST /user3/_delete_by_query
- {
- "query": {
- "range": {
- "age": {
- "lt": 20
- }
- }
- } }
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。