ELK学习总结(2-4)bulk 批量操作-实现多个文档的创建、索引、更新和删除

时间:2023-03-09 09:47:27
ELK学习总结(2-4)bulk 批量操作-实现多个文档的创建、索引、更新和删除

bulk 批量操作-实现多个文档的创建、索引、更新和删除

------------------------------------------------------------------------------

1、命令格式

{action:{metadata}}\n

{request body}

{action:{metadata}}\n

{request body}

其中,action的值有 create\index\update\delete

create:当文档不存在时创建之

index:创建或替换已有文档

update:局部更新文档

delete:删除一个文档

例如:{“delete”:{“_index”:"library","_type":"books","_id":"1"}}

------------------------------------------------------------------------------

2、举例如下

请求命令:

POST /library/books/_bulk

{"index":{"_id":1}}

{"title":"The Elasticsearch cook book","price":5}

{"index":{"_id":2}}

{"title":"Thinking in python","price":25}

{"index":{"_id":3}}

{"title":"Thinking in java","price":15}

执行结果:

{

“took”:528,

“errors”:false,

"items":

{

"index":{

"_index":"library",

"_type":"book",

"_id":"1",

"_version":1,

"status":201

}

},

"index":{

"_index":"library",

"_type":"book",

"_id":"2",

"_version":1,

"status":201

}

},

"index":{

"_index":"library",

"_type":"book",

"_id":"3",

"_version":1,

"status":201

}

},

"index":{

"_index":"library",

"_type":"book",

"_id":"4",

"_version":1,

"status":201

}

}

}

检查命令:

GET /library

GET /library/books/_mget

{

"ids":["1","2","3","4","5"]

}

------------------------------------------------------------------------------

3、还可以delete、update,但delete没有request body

------------------------------------------------------------------------------

4、批量处理文档的大小最佳值

需要验证得知

可以借助插件监控的仪表数据判断