Hi,
I use this code (based on my search) to convert JSon String response returned by a query issued against ES 1.3.2 to a SearchResponse object in order to navigate with the java objects (total, hits, ...)
InputStream is = new ByteArrayInputStream(result.getBytes(StandardCharsets.UTF_8));
InputStreamStreamInput stream = new InputStreamStreamInput(is);
SearchResponse searchResponse = SearchResponse.readSearchResponse(stream);
But I get this error
java.io.IOException: Can't read unknown type [101]
at org.elasticsearch.common.io.stream.StreamInput.readGenericValue(StreamInput.java:435)
at org.elasticsearch.common.io.stream.StreamInput.readGenericValue(StreamInput.java:411)
at org.elasticsearch.common.io.stream.StreamInput.readMap(StreamInput.java:359)
at org.elasticsearch.transport.TransportMessage.readFrom(TransportMessage.java:86)
at org.elasticsearch.action.ActionResponse.readFrom(ActionResponse.java:35)
at org.elasticsearch.action.search.SearchResponse.readFrom(SearchResponse.java:226)
at org.elasticsearch.action.search.SearchResponse.readSearchResponse(SearchResponse.java:220)
The json string (returned by ES) looks correct
{
"took" : 2,
"timed_out" : false,
"_shards" : {
"total" : 5,
"successful" : 5,
"failed" : 0
},
"hits" : {
"total" : 1,
"max_score" : 1.0,
"hits" : [ {
"_index" : "blog",
"_type" : "post",
"_id" : "_a0wZNZwTaSlC_D2-3FPNg",
"_score" : 1.0,
"_source":{"user":"cmoulliard","postDate":"2014-12-12","body":"Integration is hard. Integration should be easy.","title":"On distributed search"}
} ]
}
}
Is there a way to map JSon String to a SearchReponse object or I should use JSONObject, JSONArray to map the result ?
Regards,
Charles