At last, we'll now see how we can index CSV data in Solr using Content-Type: text/csv. A sample CSV file has been provided at %SOLR_EXAMPLES/Chapter-4/sampleMusicCatalog.csv
, and we can use it to add documents to our musicCatalgoue
example.
The following is an example of indexing data using the curl
command:
curl 'http://localhost:8983/solr/musicCatalog/update' --data-binary @sampleMusicCatalog.csv -H 'Content-type:application/csv'
In the preceding command, we're telling CSVUpdateHandler
to use the first line of the CSV as the header row, which will contain the field name. If the CSV does not have a header row, we can use the header=false parameter, which will tell UpdateHandler
that there is no header row present. We can specify the field names in the CSV using another parameter named fieldnames, which accepts a comma-separated list of field names for the CSV file. There are a lot of optional configurations that can be set on the update handler. More information...