赞
踩
PUT /dangdang/ 创建索引
DELETE /dangdang 删除索引
DELETE /* 删除所有索引
GET /_cat/indices?v 查看索引信息
创建/dangdang索引并创建(product)类型
PUT /dangdang { "mappings": { "product": { "properties": { "title": { "type": "text" }, "name": { "type": "text" }, "age": { "type": "integer" }, "created": { "type": "date", "format": "strict_date_optional_time||epoch_millis" } } } } }
注意: 这种方式创建类型要求索引不能存在
Mapping Type: : text , keyword , date ,integer, long , double , boolean or ip
GET /dangdang/_mapping/product # 语法:GET /索引名/_mapping/类型名
PUT /ems/emp/1 #/索引/类型/id
{
"name":"赵小六",
"age":23,
"bir":"2012-12-12",
"content":"这是一个好一点的员工"
}
GET /ems/emp/1
返回结果:
{
"_index": "ems",
"_type": "emp",
"_id": "1",
"_version": 1,
"found": true,
"_source": {
"name": "赵小六",
"age": 23,
"bir": "2012-12-12",
"content": "这是一个好一点的员工"
}
}
DELETE /ems/emp/1
{
"_index": "ems",
"_type": "emp",
"_id": "1",
"_version": 2,
"result": "deleted", #删除成功
"_shards": {
"total": 2,
"successful": 1,
"failed": 0
},
"_seq_no": 1,
"_primary_term": 1
}
1.第一种方式 更新原有的数据 POST /dangdang/emp/1/_update { "doc":{ "name":"xiaohei" } } 2.第二种方式 添加新的数据 POST /ems/emp/1/_update { "doc":{ "name":"xiaohei", "age":11, "dpet":"你好部门" } } 3.第三种方式 在原来数据基础上更新 POST /ems/emp/1/_update { "script": "ctx._source.age += 5" }
ES的使用语法风格为:
REST /Index/Type/ID ------------ REST操作 /索引/类型/文档id
1. 批量索引两个文档
PUT /dangdang/emp/_bulk
{"index":{"_id":"1"}}
{"name": "John Doe","age":23,"bir":"2012-12-12"}
{"index":{"_id":"2"}}
{"name": "Jane Doe","age":23,"bir":"2012-12-12"}
2. 更新文档同时删除文档
POST /dangdang/emp/_bulk
{"update":{"_id":"1"}}
{"doc":{"name":"lisi"}}
{"delete":{"_id":2}}
{"index":{}}
{"name":"xxx","age":23}
注意:批量时不会因为一个失败而全部失败,二十继续执行后续操作,批量在返回时按照执行的状态开始返回
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。