multi-get.asciidoc 1.0 KB

123456789101112131415161718192021222324252627282930
  1. [[java-docs-multi-get]]
  2. === Multi Get API
  3. The multi get API allows to get a list of documents based on their `index`, `type` and `id`:
  4. [source,java]
  5. --------------------------------------------------
  6. MultiGetResponse multiGetItemResponses = client.prepareMultiGet()
  7. .add("twitter", "tweet", "1") <1>
  8. .add("twitter", "tweet", "2", "3", "4") <2>
  9. .add("another", "type", "foo") <3>
  10. .get();
  11. for (MultiGetItemResponse itemResponse : multiGetItemResponses) { <4>
  12. GetResponse response = itemResponse.getResponse();
  13. if (response.isExists()) { <5>
  14. String json = response.getSourceAsString(); <6>
  15. }
  16. }
  17. --------------------------------------------------
  18. <1> get by a single id
  19. <2> or by a list of ids for the same index / type
  20. <3> you can also get from another index
  21. <4> iterate over the result set
  22. <5> you can check if the document exists
  23. <6> access to the `_source` field
  24. For more information on the multi get operation, check out the REST
  25. {ref}/docs-multi-get.html[multi get] docs.