Search code examples
javaelasticsearch

ElasticSearch Java API get only JSON Documents


The Java API client normally returns a deserialized object, e.g.

SearchResponse<Product> result = client.search(searchRequest, Product.class);

For searches with many results e.g. 10000 documents, the process can have a high duration. Is it somehow possible to get only the raw source JSON as String to handle it by my own?

I tried already

SearchResponse<String> result = client.search(searchRequest, String.class);

but this leads to an MappingException.


Solution

  • You could try:

    SearchResponse<ObjectNode> result = client.search(searchRequest, ObjectNode.class);