Created
July 21, 2016 12:43
-
-
Save jacobben85/5e4aae1e3c44e40130f4ce9a722f4ed5 to your computer and use it in GitHub Desktop.
search wrapper
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private String elasticsearch = "http://localhost:9200/boeing4/_search"; | |
public final String getResponse(final String searchString) | |
throws IOException, URISyntaxException { | |
String url = elasticsearch + "?q=" + searchString; | |
URI uri = URI.create(url); | |
HttpClient client = HttpClientBuilder.create().build(); | |
HttpGet httpGet = new HttpGet(); | |
httpGet.setURI(uri); | |
// auth if required | |
HttpResponse response = client.execute(httpGet); | |
BufferedReader rd = new BufferedReader( | |
new InputStreamReader(response.getEntity().getContent())); | |
StringBuilder result = new StringBuilder(); | |
String line; | |
while ((line = rd.readLine()) != null) { | |
result.append(line); | |
} | |
return result.toString(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment