Skip to main content

获取文档

Get 单个文档

GetRequest request = new GetRequest("index", "_doc", "1");
GetResponse getResponse = client.get(request, RequestOptions.DEFAULT);
String message = getResponse.getField("message").getValue();

Get 多个文档

MultiGetRequest request = new MultiGetRequest();
request.add(new MultiGetRequest.Item("index", "type", "example_id"));
request.add(new MultiGetRequest.Item("index", "type", "another_id"));
MultiGetResponse response = client.mget(request, RequestOptions.DEFAULT);
MultiGetItemResponse item = response.getResponses()[0];
String value = item.getResponse().getField("foo").getValue();