Get - TuPengXiong/TuPengXiong.github.io GitHub Wiki
package tpx.elasticsearch;
import org.elasticsearch.action.get.GetResponse;
import org.elasticsearch.client.transport.TransportClient;
public class Get {
public static void main(String[] args) {
Get get = new Get();
Index index = new Index();
index.createTransportClient();
GetResponse response = get.getResponse(index.client,"tpx", "testBuilder", "1");
printResponse(response);
response = get.prepareGetResponse(index.client,"tpx", "testBuilder", "1");
printResponse(response);
index.closeTransportClient();
}
public GetResponse getResponse(TransportClient client,String index,String shard,String id){
GetResponse response = client.prepareGet(index, shard, id)
.setOperationThreaded(false)
.get();
return response;
}
public GetResponse prepareGetResponse(TransportClient client,String index,String shard,String id){
GetResponse response = client.prepareGet(index, shard, id).get();
return response;
}
public static void printResponse(GetResponse response){
System.out.println(response.getSourceAsString());
}
}