ElasticSearch笔记-增删改
添加文档:
添加单个文档
POST index1/user/1000
{
"id":1001,
"name":"张三",
"age":20,
"sex":"男"
}
如果不指定id,将随机生成一个,id的字段名是_id
删除文档:
删除指定id的文档
DELETE /blog/article2/1
按条件删除
POST index5/people/_delete_by_query?q=name:zhangsan
修改文档
覆盖文档:
ES中文档数据不能修改,可以通过覆盖的方式进行更新。所以和上面的操作相同
POST index1/user/1001
{
"id":1001,
"name":"张三",
"age":20,
"sex":"男"
}
修改字段:
上面操作时更新整个文档,可以操作局部更新,但是实际上es内部帮我们查询这个文档,然后修改、覆盖整个文档
POST index1/user/1001/_update
{
"doc":
{
"age":2000
}
}
批量操作文档
语法
{ action: { metadata }}
{ requestbody}
{ action: { metadata }}
{ requestbody}
最后一行一定要回车
批量添加
POST index6/_doc/_bulk
{ "index": {} }
{"id":2001,"name":"name1","age": 20,"sex": "男"}
{ "index": {} }
{"id":2002,"name":"name2","age": 20,"sex": "男"}
{ "index": {} }
{"id":2003,"name":"name3","age": 20,"sex": "男"}
批量删除
POST index6/_doc/_bulk
{"delete":{"_index":"index6","_type":"_doc","_id":2001}}
{"delete":{"_index":"index6","_type":"_doc","_id":2002}}
{"delete":{"_index":"index6","_type":"_doc","_id":2003}}