I have following requirements in my spring web app:
- find objects from Elasticsearch and display them on google map (json format preferred)
- find objects (the same query as above) from Elasticsearch and display them on list (java objects format preferred to display it on JSP page)
I've written search with Java API using SearchRequestBuilder and it works fine:
SearchRequestBuilder request = client.prepareSearch("index").setTypes("type")
.setSearchType(SearchType.QUERY_THEN_FETCH).setFrom(0).setSize(10).addFields(RESPONSE_FIELDS);
//request is much more complicated
//...
SearchResponse response = request.execute().actionGet();
SearchHits hits = response.getHits();
But for displaying it on google map i would prefer to just get JSON object from elasticsearch instead of SearchResponse object like this:
{
"_index": "indexName",
"_type": "type",
"_id": "9094",
"_version": 31,
"found": true,
"_source": {
//list of properties
}
}
Is it possible to get JSON response using Java API + SearchRequestBuilder or i have to use REST API for that?