可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试):
问题:
I need to verify that text extraction is working on my Solr installation on Windows Server 2003. All the examples I found for uploading files to Solr use curl like below.
curl "http://localhost:8983/solr/update/extract?&extractOnly=true" --data-binary @tutorial.html -H 'Content-type:text/html'
How can I do this in Windows? I want to test upload a pdf and Word document then confirm I can search for words contained in the document using Solr admin page.
回答1:
With the examples comes a post.jar
(see folder example\exampledocs
of the apache-solr-X.X.X.zip
):
java -jar post.jar -h
This is a simple command line tool for POSTing raw data to a Solr
port. Data can be read from files specified as commandline args,
as raw commandline arg strings, or via STDIN.
Examples:
java -jar post.jar *.xml
java -Ddata=args -jar post.jar '<delete><id>42</id></delete>'
java -Ddata=stdin -jar post.jar < hd.xml
java -Durl=http://localhost:8983/solr/update/csv -Dtype=text/csv -jar post.jar *.csv
java -Durl=http://localhost:8983/solr/update/json -Dtype=application/json -jar post.jar *.json
java -Durl=http://localhost:8983/solr/update/extract?literal.id=a -Dtype=application/pdf -jar post.jar a.pdf
Other options controlled by System Properties include the Solr
URL to POST to, the Content-Type of the data, whether a commit
or optimize should be executed, and whether the response should
be written to STDOUT. These are the defaults for all System Properties:
-Ddata=files
-Dtype=application/xml
-Durl=http://localhost:8983/solr/update
-Dcommit=yes
-Doptimize=no
-Dout=no
OR
The Windows PowerShell 3.0 has an Invoke-WebRequest
command which for sure could be used for that. See this blog post.
回答2:
With solr 5.0 you have to mention core name while updating the docs. So the command to post all the examples in the exampledocs will be:
java -Dc="core_name" -jar post.jar *.xml
here replace core_name with the name of the core
回答3:
Using Solr 6.1 on Windows I was able to recursively index a folder using the SimplePostTool from solr-core-x.y.z.jar like so:
java -classpath C:\Solr\solr-6.1.0\dist\solr-core-6.1.0.jar -Dauto=yes -Dc=yourcorename -Ddata=files -Drecursive=yes org.apache.solr.util.SimplePostTool C:\Solr\solr-6.1.0\docs
You will need to replace "C:\Solr\solr-6.1.0\" with your solr folder, specify the correct version number for solr-core-6.1.0.jar, set the folder to the location of file you want to index and ensure the core exists already.
回答4:
Can have following options -
- Fire URL from browser using the stream.file (stream.url for remote urls) parameter which points to the file on the local file system e.g. sample_url
- Install cgywin/curl for windows, which will help you to fire these urls.
- Write a short program using Solrj (or any other solr client) to post these documents.
回答5:
You can try using Firefox Poster Plugin.. I tried couple of downloads and they worked fine :)
回答6:
You could try this:
C:\Java\Libs\apache-solr-4.0.0-BETA\example>"C:\Program Files (x86)\Internet Explorer\iexplore.exe" "http://localhost:8983/solr/collection1/update?commit=true&stream.contentType=text/csv;charset=utf-8
&stream.file=C:/Java/Libs/apache-solr-4.0.0-BETA/example/exampledocs/listado_talleres_new.csv"
回答7:
If you want to use cURL command for posting files to solr, you are required to download this utility from cURL Home. Provide the path of cURL.exe in path environmental variable of the windows and then you can use the command you queried for
curl "http://localhost:8983/solr/update/extract?&extractOnly=true" --data-binary @"location of file/test.pdf" -H 'Content-type:application/pdf'
i.e. you are required to change the content type.
Another way to post the directory to Solr is by using the 'post.jar' utility in the examples directory of the Solr - remember this utility is not for production use.
Here is the sample command.
java -Ddata=files -Dtype=html -Dfiletypes=htm,html -Dauto=yes -Drecursive=yes -jar post.jar "Drive_letter:\yourpath\."
The above works perfectly with Solr 4.0
回答8:
For Windows I use this cоmmand:
java -classpath %SOLR_HOME%\dist\solr-core-6.5.1.jar -Dauto=yes -Dc=books -Ddata=files -Drecursive=yes org.apache.solr.util.SimplePostTool c:\apache-solr-6.5.1\server\solr\books\data\index\*.*
回答9:
In order to do this using Powershell, run following command:
$header = @{"Content-type"="text/plain"; "charset"="utf-8"};
Invoke-WebRequest -Uri http://localhost:8983/solr/YOUR_CORE_NAME/update/csv -Headers $header -InFile "C:\data.csv" -Method Post
回答10:
Through command line first navigate to the exampledocs folder of Solr and execute the below command
D:\solr-7.5.0\example\exampledocs>java -Dc=onlycorename -Dtype=application/json -jar post.jar books.json
Alternatively, From the example folder execute the below command
D:\Open Source Servers\solr-7.5.0\example>java -Dc=films -Dtype=application/xml -jar exampledocs/post.jar exampledocs/*.xml