发送大字符串时 ContentStreamUpdateRequest 套接字写入错误
使用 SolrJ 的 ContentStreamUpdateRequest 向 solr 发送数据时出现以下异常
Exception in thread "main" org.apache.solr.client.solrj.SolrServerException: java.net.SocketException: Software caused connection abort: socket write error
at org.apache.solr.client.solrj.impl.CommonsHttpSolrServer.request(CommonsHttpSolrServer.java:478)
at org.apache.solr.client.solrj.impl.CommonsHttpSolrServer.request(CommonsHttpSolrServer.java:244)
at com.atosworldline.documentarchiver.core.solr.SolrIndexer.addDocument(SolrIndexer.java:48)
at com.atosworldline.documentarchiver.core.solr.SolrIndexerTest.main(SolrIndexerTest.java:14)
Caused by: java.net.SocketException: Software caused connection abort: socket write error
at java.net.SocketOutputStream.socketWrite0(Native Method)
at java.net.SocketOutputStream.socketWrite(SocketOutputStream.java:92)
at java.net.SocketOutputStream.write(SocketOutputStream.java:136)
at java.io.BufferedOutputStream.write(BufferedOutputStream.java:105)
at org.apache.commons.httpclient.HttpConnection.write(HttpConnection.java:975)
at org.apache.commons.httpclient.HttpConnection.write(HttpConnection.java:943)
at org.apache.commons.httpclient.HttpConnection.print(HttpConnection.java:1033)
at org.apache.commons.httpclient.MultiThreadedHttpConnectionManager$HttpConnectionAdapter.print(MultiThreadedHttpConnectionManager.java:1644)
at org.apache.commons.httpclient.HttpMethodBase.writeRequestLine(HttpMethodBase.java:2218)
at org.apache.commons.httpclient.HttpMethodBase.writeRequest(HttpMethodBase.java:2059)
at org.apache.commons.httpclient.HttpMethodBase.execute(HttpMethodBase.java:1096)
at org.apache.commons.httpclient.HttpMethodDirector.executeWithRetry(HttpMethodDirector.java:398)
at org.apache.commons.httpclient.HttpMethodDirector.executeMethod(HttpMethodDirector.java:171)
at org.apache.commons.httpclient.HttpClient.executeMethod(HttpClient.java:397)
at org.apache.commons.httpclient.HttpClient.executeMethod(HttpClient.java:323)
at org.apache.solr.client.solrj.impl.CommonsHttpSolrServer.request(CommonsHttpSolrServer.java:422)
... 3 more
该异常的原因是,我将文档的二进制数据发送到 solr。如果我删除它,应用程序将成功运行。 我使用以下代码发送请求,
SolrServer solrServer = new CommonsHttpSolrServer(url);
ContentStreamUpdateRequest request = new ContentStreamUpdateRequest(EXTRACT);
request.addFile(document);
//request.setParam("literal.id", documentName);
request.setAction(ACTION.COMMIT, true, true);
byte[] byteContent = FileUtils.readFileToByteArray(document);
String base64encodedFile = Base64.byteArrayToBase64(byteContent, 0, byteContent.length);
request.setParam(SolrDBSchema.DOCUMENT.toString(), base64encodedFile);
request.setParam("literal." + SolrDBSchema.OWNER.toString(), owner);
request.setParam("literal." + SolrDBSchema.VALID.toString(), Boolean.toString(valid));
request.setParam("literal." + SolrDBSchema.DATE.toString(), validFor.toString());
request.setParam("literal." + SolrDBSchema.DOCUMENT_TYPE.toString(), documentType);
solrServer.request(request);
我认为 String base64encodedFile 对于 HTTP 请求来说太长了,但我不知道该问题的解决方案。据我所知,Solr 无法通过配置存储文档。
I get the following exception when sending data to solr using the ContentStreamUpdateRequest of SolrJ
Exception in thread "main" org.apache.solr.client.solrj.SolrServerException: java.net.SocketException: Software caused connection abort: socket write error
at org.apache.solr.client.solrj.impl.CommonsHttpSolrServer.request(CommonsHttpSolrServer.java:478)
at org.apache.solr.client.solrj.impl.CommonsHttpSolrServer.request(CommonsHttpSolrServer.java:244)
at com.atosworldline.documentarchiver.core.solr.SolrIndexer.addDocument(SolrIndexer.java:48)
at com.atosworldline.documentarchiver.core.solr.SolrIndexerTest.main(SolrIndexerTest.java:14)
Caused by: java.net.SocketException: Software caused connection abort: socket write error
at java.net.SocketOutputStream.socketWrite0(Native Method)
at java.net.SocketOutputStream.socketWrite(SocketOutputStream.java:92)
at java.net.SocketOutputStream.write(SocketOutputStream.java:136)
at java.io.BufferedOutputStream.write(BufferedOutputStream.java:105)
at org.apache.commons.httpclient.HttpConnection.write(HttpConnection.java:975)
at org.apache.commons.httpclient.HttpConnection.write(HttpConnection.java:943)
at org.apache.commons.httpclient.HttpConnection.print(HttpConnection.java:1033)
at org.apache.commons.httpclient.MultiThreadedHttpConnectionManager$HttpConnectionAdapter.print(MultiThreadedHttpConnectionManager.java:1644)
at org.apache.commons.httpclient.HttpMethodBase.writeRequestLine(HttpMethodBase.java:2218)
at org.apache.commons.httpclient.HttpMethodBase.writeRequest(HttpMethodBase.java:2059)
at org.apache.commons.httpclient.HttpMethodBase.execute(HttpMethodBase.java:1096)
at org.apache.commons.httpclient.HttpMethodDirector.executeWithRetry(HttpMethodDirector.java:398)
at org.apache.commons.httpclient.HttpMethodDirector.executeMethod(HttpMethodDirector.java:171)
at org.apache.commons.httpclient.HttpClient.executeMethod(HttpClient.java:397)
at org.apache.commons.httpclient.HttpClient.executeMethod(HttpClient.java:323)
at org.apache.solr.client.solrj.impl.CommonsHttpSolrServer.request(CommonsHttpSolrServer.java:422)
... 3 more
The reason for that exception is, that I'm sending the binary data of the document to solr. If I remove this, the application runs successfull.
I'm using the following code to send the request
SolrServer solrServer = new CommonsHttpSolrServer(url);
ContentStreamUpdateRequest request = new ContentStreamUpdateRequest(EXTRACT);
request.addFile(document);
//request.setParam("literal.id", documentName);
request.setAction(ACTION.COMMIT, true, true);
byte[] byteContent = FileUtils.readFileToByteArray(document);
String base64encodedFile = Base64.byteArrayToBase64(byteContent, 0, byteContent.length);
request.setParam(SolrDBSchema.DOCUMENT.toString(), base64encodedFile);
request.setParam("literal." + SolrDBSchema.OWNER.toString(), owner);
request.setParam("literal." + SolrDBSchema.VALID.toString(), Boolean.toString(valid));
request.setParam("literal." + SolrDBSchema.DATE.toString(), validFor.toString());
request.setParam("literal." + SolrDBSchema.DOCUMENT_TYPE.toString(), documentType);
solrServer.request(request);
I think the String base64encodedFile is to long for a HTTP request, but I don't know a solution for that problem. As far as I know Solr is not able to store the document by configuration.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
由于您使用的是 SolrJ,请考虑将 RequestWriter 设置为使用 BinaryRequestWriter,如下所示
:将允许您以二进制格式将数据写入 Solr,并且可以绕过您在以 XML 形式发送大数据流时遇到的问题。
请注意,您需要确保在 solrconfig.xml 设置中启用 BinaryUpdateRequestHandler。
Since you are using SolrJ, consider setting the RequestWriter to use the BinaryRequestWriter, like this:
This will allow you to write your data to Solr in the binary format and may bypass the issue you are experiencing sending the large data stream as XML.
Note that you will need to ensure you have the BinaryUpdateRequestHandler enabled in your solrconfig.xml settings.