The key to doing this is to pipe the output of a directory list to another Linux command.  For windows users, this may feel unfamiliar but it’s one thing about the *nix operating system that is really powerful for developers.

We will build this up in pieces.  First, posting an xml file to solr is done like this:

curl http://localhost:8938/solr/CORE_NAME/update?commit=true -H “Content-Type: text/xml” –data-binary @file_name

We can list the directory of files normally with “ls” and pipe the results to our curl command using “xargs”

ls POST_DIRECTORY | xargs -I % curl http://localhost:8938/solr/CORE_NAME/update?commit=true -H “Content-Type: text/xml” –data-binary @POST_DIRECTORY/%

The trick here is the -I flag of xargs, which basically makes the input a variable that you can place into the executed command wherever and however you want.  The end result is every file in the “POST_DIRECTORY” subdirectory from where you execute the command will be posted to the “CORE_NAME” core.

 

Leave a Reply

Post Navigation