Solr CSV Output

Solr has been able to slurp in CSV for quite some time, and now I’ve finally got around to adding the ability to output query results in CSV also. The output format matches what the CSV loader can slurp.

Adding a simple wt=csv to a query request will cause the docs to be written in a CSV format that can be loaded into something like Excel.

http://localhost:8983/solr/select?q=ipod&fl=id,cat,name,popularity,price,score&wt=csv

id,cat,name,popularity,price,score
IW-02,"electronics,connector",iPod & iPod Mini USB 2.0 Cable,1,11.5,0.98867977
F8V7067-APL-KIT,"electronics,connector",Belkin Mobile Power Cord for iPod w/ Dock,1,19.95,0.6523595
MA147LL/A,"electronics,music",Apple 60 GB iPod with Video Playback Black,10,399.0,0.2446348

CSV formats tend to vary, so there are a number of parameters that allow you to customize the output. For example setting csv.escape= and csv.separator=%09 (a URL-encoded tab character) will use a tab separator and backslash escaping to match the default CSV format that MySQL uses.

http://localhost:8983/solr/select?q=ipod&fl=score,id&wt=csv&csv.escape=&csv.separator=%09

score id
0.98867977 IW-02
0.6523595 F8V7067-APL-KIT
0.2446348 MA147LL/A

The CSVResponseWriter is documented on the Solr Wiki, but you will need a recent
nightly build (Solr 3.1-dev or Solr 4.0-dev) to try it out.

You Might Also Like

How Lenovo made search a strategic growth driver in the AI era

Discover how Lenovo turned search into a strategic growth driver with Lucidworks,...

Read More

The State of Generative AI 2025: 3 questions to understand your agentic AI readiness

How prepared are businesses for agentic AI? Lucidworks data gives us the...

Read More

Announcing our 2025 Superstars of Search Award winners: Mouser, TE, and Coppel

Celebrating 3 incredible Lucidworks clients who transformed their search experiences and drove...

Read More

Quick Links