ElasticSearch _bulk和_mget
_bulk api
POST /_bulk
批量操作
POST _bulk
{ "index" : { "_index" : "movies", "_id" : "1" } }
{ "year" : 1994 }
{ "delete" : { "_index" : "movies", "_id" : "1" } }
{ "delete" : { "_index" : "movies1", "_id" : "1" } }
{ "create" : { "_index" : "movies", "_id" : "1" } }
{ "year" : "1994" }
{ "update" : {"_id" : "1", "_index" : "movies"} }
{ "doc" : {"name" : "1"} }
POST //_bulk
批量操作 指定索引
POST movies/_bulk
{ "index" : { "_id" : "2" } }
{ "year" : 1994 }
{ "delete" : { "_id" : "2" } }
{ "create" : { "_id" : "2" } }
{ "year" : "19924" }
{ "update" : {"_id" : "2"} }
{ "doc" : {"name" : "XXXX2"} }
_mget
GET /_mget 和 GET //_mget
简单的根据id 查找
GET _mget
{
"docs":[
{
"_index":"movies",
"_id":1
}, {
"_index":".kibana-event-log-7.10.2-000001",
"_id":1
}
]
}
结果:
{
"docs" : [
{
"_index" : "movies",
"_type" : "_doc",
"_id" : "1",
"_version" : 16,
"_seq_no" : 9779,
"_primary_term" : 10,
"found" : true,
"_source" : {
"year" : "1994",
"name" : "1"
}
},
{
"_index" : ".kibana-event-log-7.10.2-000001",
"_type" : "_doc",
"_id" : "1",
"found" : false
}
]
}
筛选源
GET _mget
{
"docs":[
{
"_index":"movies",
"_id":1,
"_source":["year"]
},
{
"_index":"movies",
"_id":15061,
"_source": {
"include": [ "year","user" ],
"exclude": [ "user.full_name" ]
}
}
]
}
结果
{
"docs" : [
{
"_index" : "movies",
"_type" : "_doc",
"_id" : "1",
"_version" : 16,
"_seq_no" : 9779,
"_primary_term" : 10,
"found" : true,
"_source" : {
"year" : "1994"
}
},
{
"_index" : "movies",
"_type" : "_doc",
"_id" : "15061",
"_version" : 1,
"_seq_no" : 9784,
"_primary_term" : 10,
"found" : true,
"_source" : {
"year" : 1994,
"user" : {
"last_name" : "jiayue",
"first_name" : "bi"
}
}
}
]
}