Skip to content

Instantly share code, notes, and snippets.

Created March 10, 2011 13:44
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save anonymous/864108 to your computer and use it in GitHub Desktop.
Save anonymous/864108 to your computer and use it in GitHub Desktop.
@RequestMapping(value = "handle", method = RequestMethod.GET)
public void handle(HttpServletRequest request, HttpServletResponse response) throws IOException{
XContentBuilder builder = XContentFactory.contentBuilder(XContentType.JSON);
SearchResponse searchResponse = buildRequest(request).execute().actionGet();
builder.startObject();
searchResponse.toXContent(builder, ToXContent.EMPTY_PARAMS);
builder.endObject();
String result = builder.string();
response.setContentType("application/json; charset=UTF-8");
ServletOutputStream sos = response.getOutputStream();
sos.write(result.getBytes(Charset.forName("UTF-8")));
sos.flush();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment