Post Tool
Solr includes a simple command line tool for POSTing various types of content to a Solr server.
The tool is bin/solr post
.
The bin/solr post tool is a Unix shell script; for Windows (non-Cygwin) usage,use bin/solr.cmd post
.
This tool is meant for use by new users exploring Solr’s capabilities, and is not intended as a robust solution to be used for indexing documents into production systems. |
You may be familiar with SimplePostTool and the bin/post Unix shell script. While this is still available, it is deprecated and will be removed in Solr 10. |
To run it, open a window and enter:
$ bin/solr post -url http://localhost:8983/gettingstarted/update example/films/films.json
This will contact the server at localhost:8983
.
The -help
(or simply -h
) option will output information on its usage (i.e., bin/solr post -help)
.
Using the bin/solr post Tool
Specifying the full update url
is mandatory when using bin/solr post
.
The basic usage of bin/solr post
is:
$ bin/solr post -h
Usage: post -url http://localhost:8983/gettingstarted/update [OPTIONS] <files|directories|urls|-d ["...",...]>
or post -help
OPTIONS
=======
Solr options:
-url <base Solr update URL>
-commit issue a commit
-u or -user <user:pass> (sets BasicAuth credentials)
Web crawl options:
-recursive <depth> (default: 1)
-delay <seconds> (default: 10)
Directory crawl options:
-delay <seconds> (default: 0)
stdin/args options:
-type <content/type> (default: application/json)
Other options:
-filetypes <type>[,<type>,...] (default: xml,json,csv,pdf,doc,docx,ppt,pptx,xls,xlsx,odt,odp,ods,ott,otp,ots,rtf,htm,html,txt,log)
-params "<key>=<value>[&<key>=<value>...]" (values must be URL-encoded; these pass through to Solr update request)
-out output the Solr responses to console
-format solr (sends application/json content as Solr commands to /update instead of /update/json/docs
Examples:
* JSON file: bin/solr post -url http://localhost:8983/wizbang/update events.json
* XML files: bin/solr post -url http://localhost:8983/records/update article*.xml
* CSV file: bin/solr post -url http://localhost:8983/signals/update LATEST-signals.csv
* Directory of files: bin/solr post -filetypes xml,json,csv -url http://localhost:8983/myfiles/update ~/Documents
* Web crawl: bin/solr post -mode web -url http://localhost:8983/gettingstarted/update -recursive 1 -delay 1 https://solr.apache.org/
* Standard input (stdin): echo '{commit: {}}' | bin/solr post -mode stdin -url http://localhost:8983/my_collection/update -out
* Data as string: bin/solr post -url http://localhost:8983/signals/update -mode args -type text/csv -out $'id,value\n1,0.47'
Examples Using bin/solr post
There are several ways to use bin/solr post
.
This section presents several examples.
Indexing XML
Add all documents with file extension .xml
to the collection named gettingstarted
.
bin/solr post -url http://localhost:8983/solr/gettingstarted/update *.xml
Add all documents with file extension .xml
to the gettingstarted
collection on Solr running on port 8984
.
bin/solr post -url http://localhost:8984/solr/gettingstarted/update *.xml
Send XML arguments to delete a document from gettingstarted
.
bin/solr post -url http://localhost:8983/solr/gettingstarted/update -mode args -type application/xml '<delete><id>42</id></delete>'
Indexing CSV and JSON
Index all CSV and JSON files into gettingstarted
from current directory:
bin/solr post -url http://localhost:8983/solr/gettingstarted/update -filetypes json,csv .
Index a tab-separated file into gettingstarted
:
bin/solr post -url http://localhost:8984/solr/signals/update -params "separator=%09" -type text/csv data.tsv
The content type (-type
) parameter is required to treat the file as the proper type, otherwise it will be ignored and a WARNING logged as it does not know what type of content a .tsv file is.
The CSV handler supports the separator
parameter, and is passed through using the -params
setting.
Indexing JSON
Index all JSON files into gettingstarted
.
bin/solr post -url http://localhost:8983/solr/gettingstarted/update *.json
Indexing Rich Documents (PDF, Word, HTML, etc.)
Index a PDF file into gettingstarted
.
bin/solr post -url http://localhost:8983/solr/gettingstarted/update a.pdf
Automatically detect content types in a folder, and recursively scan it for documents for indexing into gettingstarted
.
bin/solr post -url http://localhost:8983/solr/gettingstarted/update afolder/
Automatically detect content types in a folder, but limit it to PPT and HTML files and index into gettingstarted
.
bin/solr post -url http://localhost:8983/solr/gettingstarted/update -filetypes ppt,html afolder/