Reputation: 18876
I am running Solr on Windows7 and cannot use Curl on cmd so I am using post.jar. (Yes I use Cygwin and Mingw but would like to stick to cmd.exe for this scenario).
Is there a way that I can add a document via post.jar by its tags directly at the command instead of creating an xml document and then adding that xml doc to the command?
Specifically, if I add the following tags in an xml file, the document gets uploaded beautifully:
<add><doc><field name="id">50</field><field name="title">Test Title</field><field name="author">Dan</field><field name="content">Test using post.jar </field></doc></add>
However, if I try to add the same tags at the command it sends me a bad request error:
Input at Cmd:
java -Ddata=args -jar post.jar "<add><doc><field name="id">50</field><field name="title">Test Title</field><field name="author">Dan</field><field name="content">
Test using post.jar </field></doc></add>"
Returns:
SimplePostTool: FATAL: Solr returned an error: Bad Request
I cannot find any documentation or examples on adding data to solr via post.jar without it being an external xml file. Deleting works great though:
java -Ddata=args -jar post.jar '<delete><id>42</id></delete>'
Thank you in advance.
Upvotes: 1
Views: 2621
Reputation: 18876
Okay, I've figured it out. For anyone who may run into this in the future:
java -Ddata=args -jar post.jar "<add><doc><field name=\"id\">17</field></doc></add>"
Make sure you double quote the xml tags and escape the internal tag double quotes with a "\". For example, I double quoted the xml tags from <add>
to </add>
. Also, I had to escape the quotes around the field id. Make sure to do this with all of your fields and it will submit.
Additionally, if you are developing with java, make sure you escape both for the slash and quote. For example, the last argument in my ProcessBuilder string are my tags which look like:
"<add><doc><field name=\\\"id\\\">17</field></doc></add>"
Notice the extra slashes for escaping in java.
I hope this helps someone out there... Good luck!
Upvotes: 3