- 新增文档
请求 (POST)
{{url}}/nba/_doc
指定id 则 {{url}}/nba/_doc/id
可以通过 op_type=create 指定创建
{
"name":"哈登",
"team_name":"⽕火箭",
"position":"得分后卫",
"play_year":"10",
"jerse_no":"13"
}
响应
{
"_index": "nba",
"_type": "_doc",
"_id": "tvhlbHMBc4_-cyfMH_q7",
"_version": 1,
"result": "created",
"_shards": {
"total": 2,
"successful": 1,
"failed": 0
},
"_seq_no": 0,
"_primary_term": 3
}
- 查看文档
请求(GET)
{{url}}/nba/_doc/tvhlbHMBc4_-cyfMH_q7
响应
{
"_index": "nba",
"_type": "_doc",
"_id": "tvhlbHMBc4_-cyfMH_q7",
"_version": 1,
"_seq_no": 0,
"_primary_term": 3,
"found": true,
"_source": {
"name": "哈登",
"team_name": "⽕火箭",
"position": "得分后卫",
"play_year": "10",
"jerse_no": "13"
}
}
- 自动创建索引
1 查看auto_create_index开关状态,{{url}}/_cluster/settings
2 当索引不不存在并且auto_create_index为true的时候,新增⽂文档时会⾃自动创建索引
3 修改auto_create_index状态
PUT {{url}}/_cluster/settings
{
"persistent":{
"action.auto_create_index":"false"
}
}
4 自动创建索引(和新增索引步骤一致)
- 查询多个
请求 (POST)
{{url}}/_mget
json
{
"docs":[
{
"_index":"nba",
"_type":"_doc",
"_id":"tvhlbHMBc4_-cyfMH_q7"
}, {
"_index":"nba",
"_type":"_doc",
"_id": "uPhtcXMBc4_-cyfMtfqP"
}
]
}
- 修改文档
请求 (POST)
{{url}}/nba/_update/t_h4bHMBc4_-cyfMvfo4
json
{
"doc":{
"name":"刘博",
"team_name":"⽕火箭",
"position":"得分后卫",
"play_year":"10",
"jerse_no":"13"
}
}
- 新增字段
请求(POST)
{{url}}/nba/_update/t_h4bHMBc4_-cyfMvfo4
json
{
"script":"ctx._source.age = 18"
}
- 删除字段
请求(POST)
{{url}}/nba/_update/t_h4bHMBc4_-cyfMvfo4
json
{
"script":"ctx._source.remove (\"age\")"
}
- 更新指定文档字段
请求(POST)
{{url}}/nba/_update/t_h4bHMBc4_-cyfMvfo34
{
"script":{
"source":"ctx._source.allstar += params.allstar",
"params":{
"allstar":4
}
},
"upsert":{
"allstar":1
}
}
upsert : 如果文档不存在 则新创建
- 删除文档
请求(Delete)
{{url}}/nba/_doc/t_h4bHMBc4_-cyfMvfo34