Skip to content

Instantly share code, notes, and snippets.

@jacobben85
Created July 21, 2016 12:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jacobben85/5e4aae1e3c44e40130f4ce9a722f4ed5 to your computer and use it in GitHub Desktop.
Save jacobben85/5e4aae1e3c44e40130f4ce9a722f4ed5 to your computer and use it in GitHub Desktop.
search wrapper
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