如何在 Windows 中将文件上传到 Solr?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/7932897/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How can I upload a file to Solr in Windows?
提问by John81
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.
我需要验证文本提取在 Windows Server 2003 上的 Solr 安装中是否有效。我找到的所有将文件上传到 Solr 的示例都使用如下所示的 curl。
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.
如何在 Windows 中执行此操作?我想测试上传 pdf 和 Word 文档,然后确认我可以使用 Solr 管理页面搜索文档中包含的单词。
回答by jeha
With the examples comes a post.jar
(see folder example\exampledocs
of the apache-solr-X.X.X.zip
):
随着例子而来的post.jar
(见文件夹example\exampledocs
的apache-solr-X.X.X.zip
):
java -jar post.jar -h
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.
Windows PowerShell 3.0 有一个Invoke-WebRequest
肯定可以用于此的命令。请参阅此博客文章。
回答by Shalu
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:
使用 solr 5.0,您必须在更新文档时提及核心名称。因此,在 exampledocs 中发布所有示例的命令将是:
java -Dc="core_name" -jar post.jar *.xml
java -Dc="core_name" -jar post.jar *.xml
here replace core_name with the name of the core
这里用核心名称替换 core_name
回答by Dylan Hogg
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:
在 Windows 上使用 Solr 6.1 我能够使用 solr-core-xyzjar 中的 SimplePostTool 递归索引文件夹,如下所示:
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.
您需要将“C:\Solr\solr-6.1.0\”替换为您的 solr 文件夹,为 solr-core-6.1.0.jar 指定正确的版本号,将文件夹设置为您想要的文件位置索引并确保核心已经存在。
回答by Jayendra
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.
- 使用 stream.file(用于远程 url 的 stream.url)参数从浏览器中触发 URL,该参数指向本地文件系统上的文件,例如sample_url
- 为 windows 安装 cgywin/curl,这将帮助您触发这些 url。
- 使用 Solrj(或任何其他 solr 客户端)编写一个简短的程序来发布这些文档。
回答by Hrishikesh Karambelkar
You can try using Firefox Poster Plugin.. I tried couple of downloads and they worked fine :)
您可以尝试使用 Firefox Poster Plugin .. 我尝试了几次下载,它们运行良好:)
回答by axlkike
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"
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”
回答by Div Tiwari
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 windowsand then you can use the command you queried for
如果要使用 cURL 命令将文件发布到 solr,则需要从cURL Home下载此实用程序。在windows的path环境变量中提供cURL.exe的路径即可使用查询的命令
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.
将目录发布到 Solr 的另一种方法是使用 Solr 的示例目录中的“post.jar”实用程序 - 请记住,此实用程序不适用于生产用途。
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
以上适用于 Solr 4.0
回答by vvator
For Windows I use this cоmmand:
对于 Windows,我使用这个命令:
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\*.*
回答by Sparrow_ua
In order to do this using Powershell, run following command:
要使用 Powershell 执行此操作,请运行以下命令:
$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
回答by raikumardipak
Through command line first navigate to the exampledocs folder of Solr and execute the below command
首先通过命令行导航到 Solr 的 exampledocs 文件夹并执行以下命令
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