I am trying to invoke the CSVResponseWriter to create a CSV file of all
stored fields. There are millions of documents so I need to write to the
file iteratively. I saw a snippet of code online that claimed it could
effectively remove the SorDocumentList wrapper and allow the docs to be
retrieved in the actual format requested in the query. However, I get a null
pointer from the CSVResponseWriter.write() method.

SolrQuery qry = new SolrQuery("*:*");
qry.setParam("wt", "csv");
// set other params
SolrServer server = getSolrServer();
try {
        QueryResponse res = server.query(qry);

        CSVResponseWriter writer = new CSVResponseWriter();
        Writer w = new StringWriter();
         SolrQueryResponse solrResponse = new SolrQueryResponse();
        solrResponse.setAllValues(res.getResponse());
        try {
              SolrParams list = new MapSolrParams(new HashMap<String, 
String>());
              writer.write(w, new LocalSolrQueryRequest(null, list), 
solrResponse);
    } catch (IOException e) {
        throw new RuntimeException(e);
    }
    System.out.print(w.toString());

} catch (SolrServerException e) {
        e.printStackTrace();
}

NPE snippet:
org.apache.solr.response.CSVWriter.writeResponse(CSVResponseWriter.java:281)
org.apache.solr.response.CSVResponseWriter.write(CSVResponseWriter.java:56)

Am I on the right track with the approach? I really don't want to roll my
own document to CSV line convertor. Thanks!
Solr 4.9



--
View this message in context: 
http://lucene.472066.n3.nabble.com/exporting-to-CSV-with-solrj-tp4166845.html
Sent from the Solr - User mailing list archive at Nabble.com.

Reply via email to