mget,多条获取,批量查询多条数据,可减少网络开销次数。
批量查询id为1和2的数据
GET /_mget
{
"docs":[
{
"_index":"test_index",
"_type":"test_type",
"_id":1
},
{
"_index":"test_index",
"_type":"test_type",
"_id":2
}
]
}
返回的为两个结果
{
"docs": [
{
"_index": "test_index",
"_type": "test_type",
"_id": "1",
"_version": 1,
"found": true,
"_source": {
"test_content": "my test1"
}
},
{
"_index": "test_index",
"_type": "test_type",
"_id": "2",
"_version": 1,
"found": true,
"_source": {
"test_content": "my test"
}
}
]
}
同一个index下可以简写为:
GET /test_index/_mget
{
"docs":[
{
"_type":"test_type",
"_id":1
},
{
"_type":"test_type",
"_id":2
}
]
}
同一个index和type下可以简写为:
GET /test_index/test_type/_mget
{
"ids":[1,2]
}
批量bulk操作,需要注意的是,在kibana中,不能用json的格式,每个json串不能换行,只能放到一行。json串与json串之前必须要换行。
删除
POST /_bulk
{"delete":{"_index":"test_index","_type":"test_type","_id":"3"}}
创建数据
POST /_bulk
{"create":{"_index":"test_index","_type":"test_type","_id":"12"}}
{"test_content":"test12"}
查询数据
POST /_bulk
{"index":{"_index":"test_index","_type":"test_type","_id":"13"}}
{"test_content":"test13"}
更新操作
POST /_bulk
{"update":{"_index":"test_index","_type":"test_type","_id":"13","_retry_on_conflict":3}}
{"doc":{"test_content":"buld test update01"}}
bulk中任意一个操作失败是不会影响到其他的,但是会在结果中显示。
json串操作的是同一个index和type,可以把index和type写到url中
如下
POST /test_index/test_type/_bulk
{"create":{"_index":"test_index","_type":"test_type","_id":"16"}}
{"test_content":"test16"}
{"delete":{"_index":"test_index","_type":"test_type","_id":"13"}}
bulk request会加载到内存中,如果太大的话,性能会降低。需要不停的测试性能大小。
多条搜索请求合并为一次,发送一次请求到es集群中。
POST /_msearch
{"index":"test_index","type":"test_type"}
{"query":{"match": {"test_content": "test16"}}}
{"index":"test_index","type":"test_type"}
{"query":{"match": {"test_content": "test13"}}}