背景:
批量操作可以在一次API调用中,对不同的索引进行操作,可以减少网络连接产生的开销,提高性能
一、bulk API
bulk API支持的类型:
1.1 index
1.2 create
1.3 update
1.4 delete
{"index": {"_index": "users","_id": "1"}}
{"name": "li si","age": 20,"addr": "Hk"}
{"delete": {"_index": "users","_id": "2"}}
{"create": {"_index": "users","_id":"3"}}
{"name": "wang wu","age": "35","addr": "HO"}
{"update": {"_index": "users","_id": "1"}}
{"doc": {"age": "99"}}
二、_mget 读取
GET _mget
{
"docs": [
{
"_index": "users",
"_id": 1
},
{"_index": "test2",
"_id": 3
},
{
"_index": "test",
"_id": "1"
}
]
}
三、_msearch 搜索
POST _msearch
{"index": "kibana_sample_data_flights"}
{"query": {"match_all": {}},"from":0,"size": 20}
{"index": "kibana_sample_data_ecommerce"}
{"query": {"match_all": {}},"from":0,"size": 5}
说明:
批量操作,不要发送过多的数据,通常建议是1000~5000个文档,大小建议在5~15MB,默认不能超过100M。超过太多的数据会对集群产生较大的压力,使集群的性能下降