OpenSearch/docs/java-api/docs/multi-get.asciidoc
Julie Tibshirani f854330e06
Make sure to use the type _doc in the REST documentation. (#34662)
* Replace custom type names with _doc in REST examples.
* Avoid using two mapping types in the percolator docs.
* Rename doc -> _doc in the main repository README.
* Also replace some custom type names in the HLRC docs.
2018-10-22 11:54:04 -07:00

31 lines
1.0 KiB
Plaintext

[[java-docs-multi-get]]
=== Multi Get API
The multi get API allows to get a list of documents based on their `index` and `id`:
[source,java]
--------------------------------------------------
MultiGetResponse multiGetItemResponses = client.prepareMultiGet()
.add("twitter", "_doc", "1") <1>
.add("twitter", "_doc", "2", "3", "4") <2>
.add("another", "_doc", "foo") <3>
.get();
for (MultiGetItemResponse itemResponse : multiGetItemResponses) { <4>
GetResponse response = itemResponse.getResponse();
if (response.isExists()) { <5>
String json = response.getSourceAsString(); <6>
}
}
--------------------------------------------------
<1> get by a single id
<2> or by a list of ids for the same index
<3> you can also get from another index
<4> iterate over the result set
<5> you can check if the document exists
<6> access to the `_source` field
For more information on the multi get operation, check out the REST
{ref}/docs-multi-get.html[multi get] docs.