一、新增文档
请求
POST http://127.0.0.1:9200/user5/prople
参数
{
"name": "Lina",
"age": "25",
"sex": "N"
}
说明
- user5:添加到哪个索引
- prople:添加到哪个type下面
响应
{
"_index": "user5",
"_type": "prople",
"_id": "AW1DSm9smMVd_1XNEVJN",
"_version": 1,
"result": "created",
"_shards": {
"total": 2,
"successful": 1,
"failed": 0
},
"created": true
}
说明
- _id:自动生成的id,可以自己指定(修改文档)
- _version:版本号,修改一次加一
- result:created表示新增,updated表示更新 ,deleted 表示删除
二、修改文档
请求
PUT http://127.0.0.1:9200/user5/prople/AW1DSm9smMVd_1XNEVJN
参数
{
"name": "Lina1",
"age": "26",
"sex": "Y"
}
说明
- user5:添加到哪个索引
- prople:添加到哪个type下面
- AW1DSm9smMVd_1XNEVJN:要修改文档的id,如果id不存在,就新增
响应
{
"_index": "user5",
"_type": "prople",
"_id": "AW1DSm9smMVd_1XNEVJN",
"_version": 2,
"result": "updated",
"_shards": {
"total": 2,
"successful": 1,
"failed": 0
},
"created": false
}
三、删除文档
请求
DELETE http://127.0.0.1:9200/user5/prople/2
响应
{
"found": true,
"_index": "user5",
"_type": "prople",
"_id": "2",
"_version": 2,
"result": "deleted",
"_shards": {
"total": 2,
"successful": 1,
"failed": 0
}
}
四、查看文档
请求
GET http://127.0.0.1:9200/user5/prople/AW1DSm9smMVd_1XNEVJN
说明
- user5:添加到哪个索引
- prople:添加到哪个type下面
- AW1DSm9smMVd_1XNEVJN:要查看文档的id
响应
{
"_index": "user5",
"_type": "prople",
"_id": "AW1DSm9smMVd_1XNEVJN",
"_version": 2,
"found": true,
"_source": {
"name": "Lina1",
"age": "26",
"sex": "Y"
}
}
说明
- found:是否查找到
- _source:原始信息,找到时候才有
五、查看全部文档
请求
GET http://127.0.0.1:9200/user5/prople/_search
响应
{
"took": 9,
"timed_out": false,
"_shards": {
"total": 3,
"successful": 3,
"skipped": 0,
"failed": 0
},
"hits": {
"total": 1,
"max_score": 1.0,
"hits": [
{
"_index": "user5",
"_type": "prople",
"_id": "AW1DSm9smMVd_1XNEVJN",
"_score": 1.0,
"_source": {
"name": "Lina1",
"age": "26",
"sex": "Y"
}
}
]
}
}
说明
- took:该操作的耗时(单位为毫秒)
- timed_out:是否超时
- hits:命中的全部记录
total
:返回记录数max_score
:最高的匹配程度hits
:返回的记录组成的数组
六、只查看原始数据
请求
GET http://127.0.0.1:9200/user5/prople/AW1DSm9smMVd_1XNEVJN/_source
响应
{
"name": "Lina1",
"age": "26",
"sex": "Y"
}