7,Multi Get API(Multi Get API)
The multi-GET API allows you to retrieve multiple documents at one time. You need to specify a docs array that contains all the documents you need to query. Each query structure contains at least an index, type and document id. If an error occurs during the operation, the error message will be returned. The result returned is similar to the result structure of the GET API.
As shown in the following example:
GET /_mget { "docs" : [ { "_index" : "test", "_type" : "_doc", "_id" : "1" }, { "_index" : "test", "_type" : "_doc", "_id" : "2" } ] }
mget can also be used for only one index:
GET /test/_mget { "docs" : [ { "_type" : "_doc", "_id" : "1" }, { "_type" : "_doc", "_id" : "2" } ] }
Or for a type:
GET /test/_doc/_mget { "docs" : [ { "_id" : "1" }, { "_id" : "2" } ] }
If only id parameters are specified, an id array can also be used to specify:
GET /test/_doc/_mget { "ids" : ["1", "2"] }
7.1 Source filtering
By default, all fields in _source will be returned for each document (if stored). Similar to get API, you can specify the fields to be returned in _source by setting the _source parameter. You can also use _source, _source_include and _source_exclude in the url parameter, such as:
GET /_mget { "docs" : [ { "_index" : "test", "_type" : "_doc", "_id" : "1", "_source" : false }, { "_index" : "test", "_type" : "_doc", "_id" : "2", "_source" : ["field3", "field4"] }, { "_index" : "test", "_type" : "_doc", "_id" : "3", "_source" : { "include": ["user"], "exclude": ["user.location"] } } ] }
7.2 fields (Fileds)
In order to save memory and storage space, you may not enable _source and use store to save some fields. Fields designated as stored can be obtained through the storage_fields field:
GET /_mget { "docs" : [ { "_index" : "test", "_type" : "_doc", "_id" : "1", "stored_fields" : ["field1", "field2"] }, { "_index" : "test", "_type" : "_doc", "_id" : "2", "stored_fields" : ["field3", "field4"] } ] }
Or, specify stored_fields in the url as fields for default queries for all documents:
GET /test/_doc/_mget?stored_fields=field1,field2 { "docs" : [ { "_id" : "1" [1] }, { "_id" : "2", "stored_fields" : ["field3", "field4"] [2] } ] }
[1]: Return field 1 and field 2 fields
[2]: Return field 3 and field 4 fields
Routing 7.3
You can also specify routing parameters
GET /_mget?routing=key1 { "docs" : [ { "_index" : "test", "_type" : "_doc", "_id" : "1", "routing" : "key2" }, { "_index" : "test", "_type" : "_doc", "_id" : "2" } ] }
The test/_doc/2 document uses key1 as the routing value, and the test/_doc/1 document uses key2 as the routing value.
7.4 Security
consult URL-based access control