Overview
Solr has built-in support for importing data from CSV files via the /update/csv request handler. This is one of the easiest ways to bulk-load data into your Opensolr index without writing any code.
Video Tutorial
Watch this demonstration of uploading CSV data to your Opensolr index:
Importing CSV via curl
You can upload a CSV file directly from the command line using curl:
curl "https://YOUR_SOLR_HOST/solr/YOUR_INDEX/update/csv?commit=true" \
--data-binary @your_data.csv \
-H "Content-Type: application/csv"
Common Parameters
commit=true— Commits the data immediately after import so it becomes searchable.separator=%09— Use a tab separator instead of comma (for TSV files).skip=unwanted_column— Skip a column that exists in your CSV but is not in your schema.fieldnames=id,title,description— Override column names if your CSV header does not match your schema field names.overwrite=true— Update existing documents if the unique key (id) already exists.
Auto-Generating Unique IDs
If your CSV file does not have a unique ID column, you can configure Solr to auto-generate unique IDs. Add this updateRequestProcessorChain to your solrconfig.xml:
<updateRequestProcessorChain>
<processor class="solr.UUIDUpdateProcessorFactory">
<str name="fieldName">id</str>
</processor>
<processor class="solr.LogUpdateProcessorFactory" />
<processor class="solr.RunUpdateProcessorFactory" />
</updateRequestProcessorChain>
Add this snippet right below one of the </searchComponent> closing tags in your solrconfig.xml file. With this in place, Solr will automatically assign a UUID to each imported row.
Preparing Your CSV File
- The first row must contain column headers that match your schema.xml field names.
- Use UTF-8 encoding for proper character support.
- Ensure your data does not contain unescaped commas within fields — use double quotes around fields that contain commas.
- Remove any BOM (Byte Order Mark) that some editors add to the beginning of CSV files.
Troubleshooting Common Issues
- "Unknown field" error — Your CSV header contains a field name that is not defined in schema.xml. Either add the field to your schema or use the
skipparameter. - "Document is missing mandatory uniqueKey field: id" — Your CSV does not have an
idcolumn. Either add one or configure the UUID processor above. - Data not appearing in search — Make sure you include
commit=truein your request, or send a separate commit command after uploading.