In an spring boot application, I am using solrj to query on solr 7.4. I want the output as xlsx
file(not csv
).
As mentioned here, I have added the required jars into the solr server classpath. Now when i hit http://localhost:8983/solr/collection_name/select?q=*:*&wt=xlsx
in browser, I get a proper response from solr to download the result as a xlsx file.
BUT
How can i achieve this using SOLRJ in a spring boot app?
Any help is appreciated.
Finally i figured out a way.
As per the solr documentation, first copy the required jars into solr server classpath, then use the below code to get the response as xlsx file...
SolrQuery solrQuery = new SolrQuery();
solrQuery.setQuery("add solr query");
solrQuery.addFilterQuery("add filter query");
solrQuery.setParam("wt", "xlsx");
QueryRequest request = new QueryRequest(solrQuery);
request.setMethod(METHOD.POST);
request.setResponseParser(new InputStreamResponseParser("xlsx"));
SolrClient client = // create solrClient
NamedList<Object> resp = client.request(request, collectionName);
InputStream xlsxStream = (InputStream) resp.get("stream");
OutputStream outStream = new FileOutputStream("/path/to/xlsx/file");
IOUtils.copy(xlsxStream, output);