ClusterHealthResponse clusterHealth = client.admin().cluster().health(clusterHealthRequest().waitForGreenStatus()).actionGet();
assertThat(clusterHealth.timedOut(), equalTo(false));
assertThat(clusterHealth.status(), equalTo(ClusterHealthStatus.GREEN));
MultiGetResponse response = client.prepareMultiGet().add("test", "type1", "1").execute().actionGet();
assertThat(response.responses().length, equalTo(1));
assertThat(response.responses()[0].response().exists(), equalTo(false));
for (int i = 0; i < 10; i++) {
client.prepareIndex("test", "type1", Integer.toString(i)).setSource("field", "value" + i).execute().actionGet();
}
response = client.prepareMultiGet()
.add("test", "type1", "1")
.add("test", "type1", "15")
.add("test", "type1", "3")
.add("test", "type1", "9")
.add("test", "type1", "11")
.execute().actionGet();
assertThat(response.responses().length, equalTo(5));
assertThat(response.responses()[0].id(), equalTo("1"));
assertThat(response.responses()[0].response().exists(), equalTo(true));
assertThat(response.responses()[0].response().sourceAsMap().get("field").toString(), equalTo("value1"));
assertThat(response.responses()[1].id(), equalTo("15"));
assertThat(response.responses()[1].response().exists(), equalTo(false));
assertThat(response.responses()[2].id(), equalTo("3"));
assertThat(response.responses()[2].response().exists(), equalTo(true));
assertThat(response.responses()[3].id(), equalTo("9"));
assertThat(response.responses()[3].response().exists(), equalTo(true));
assertThat(response.responses()[4].id(), equalTo("11"));
assertThat(response.responses()[4].response().exists(), equalTo(false));
// multi get with specific field
response = client.prepareMultiGet()
.add(new MultiGetRequest.Item("test", "type1", "1").fields("field"))
.add(new MultiGetRequest.Item("test", "type1", "3").fields("field"))
.execute().actionGet();
assertThat(response.responses().length, equalTo(2));
assertThat(response.responses()[0].response().source(), nullValue());
assertThat(response.responses()[0].response().field("field").values().get(0).toString(), equalTo("value1"));
}