I've developed a REST API entry with Spring which conducts a search in Elasticsearch and now I want to return whatever results ES has found as the response. I don't care about the search results and I don't know the JSON structure in it. I just want to return it back to the client.
I was hoping something like this would work:
@RequestMapping(value = "/search/{index:.*}", method = RequestMethod.GET) public void search(@PathVariable String index, @RequestParam Map allRequestParams, HttpServletResponse response) throws IOException { BoolQueryBuilder query = QueryBuilders.boolQuery(); for (Map.Entry entry : allRequestParams.entrySet()) { query.should(QueryBuilders.fuzzyQuery(entry.getKey(), entry.getValue())); } SearchResponse results = esClient.prepareSearch("nyc_visionzero") .setTypes("logs") .setQuery(query) .execute() .actionGet(); SearchHits hits = results.getHits(); hits.writeTo(response.getOutputStream()); }
But the last line has a compile error since the two OutputStreams are not compatible. So my question is, what is the easiest way of wiring the results of Elasticsearch into Spring's response?