public EsRequest getDocument ( String name , String type , String id ) throws IOException { CloseableHttpClient client = HttpClients . createDefault ( ) ; HttpGet method = new HttpGet ( String . format ( "http://%s:%d/%s/%s/%s" , host , port , name , type , id ) ) ; try { CloseableHttpResponse resp = client . execute ( method ) ; int status = resp . getStatusLine ( ) . getStatusCode ( ) ; switch ( status ) { case HttpStatus . SC_OK : EsResponse doc = EsResponse . read ( resp . getEntity ( ) . getContent ( ) ) ; return new EsRequest ( ( Document ) doc . get ( "_source" ) ) ; case HttpStatus . SC_NOT_ACCEPTABLE : case HttpStatus . SC_NOT_FOUND : return null ; default : throw new IOException ( resp . getStatusLine ( ) . getReasonPhrase ( ) ) ; } } finally { method . releaseConnection ( ) ; } }
Searches indexed document .