Solr异常:org.apache.solr.common.SolrException:缺少内容流

时间:2013-07-15 14:02:34

标签: java curl solr

我遇到了这个例外:

SEVERE: org.apache.solr.common.SolrException: missing content stream
    at org.apache.solr.handler.ContentStreamHandlerBase.handleRequestBody(ContentStreamHandlerBase.java:69)
    at org.apache.solr.handler.RequestHandlerBase.handleRequest(RequestHandlerBase.java:135)
    at org.apache.solr.core.SolrCore.execute(SolrCore.java:1817)
    at org.apache.solr.servlet.SolrDispatchFilter.execute(SolrDispatchFilter.java:639)
    at org.apache.solr.servlet.SolrDispatchFilter.doFilter(SolrDispatchFilter.java:345)
    at org.apache.solr.servlet.SolrDispatchFilter.doFilter(SolrDispatchFilter.java:141)
    at org.eclipse.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1307)
    at org.eclipse.jetty.servlet.ServletHandler.doHandle(ServletHandler.java:453)
    at org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:137)
    at org.eclipse.jetty.security.SecurityHandler.handle(SecurityHandler.java:560)
    at org.eclipse.jetty.server.session.SessionHandler.doHandle(SessionHandler.java:231)
    at org.eclipse.jetty.server.handler.ContextHandler.doHandle(ContextHandler.java:1072)
    at org.eclipse.jetty.servlet.ServletHandler.doScope(ServletHandler.java:382)
    at org.eclipse.jetty.server.session.SessionHandler.doScope(SessionHandler.java:193)
    at org.eclipse.jetty.server.handler.ContextHandler.doScope(ContextHandler.java:1006)
    at org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:135)
    at org.eclipse.jetty.server.handler.ContextHandlerCollection.handle(ContextHandlerCollection.java:255)
    at org.eclipse.jetty.server.handler.HandlerCollection.handle(HandlerCollection.java:154)
    at org.eclipse.jetty.server.handler.HandlerWrapper.handle(HandlerWrapper.java:116)
    at org.eclipse.jetty.server.Server.handle(Server.java:365)
    at org.eclipse.jetty.server.AbstractHttpConnection.handleRequest(AbstractHttpConnection.java:485)
    at org.eclipse.jetty.server.BlockingHttpConnection.handleRequest(BlockingHttpConnection.java:53)
    at org.eclipse.jetty.server.AbstractHttpConnection.headerComplete(AbstractHttpConnection.java:926)
    at org.eclipse.jetty.server.AbstractHttpConnection$RequestHandler.headerComplete(AbstractHttpConnection.java:988)
    at org.eclipse.jetty.http.HttpParser.parseNext(HttpParser.java:642)
    at org.eclipse.jetty.http.HttpParser.parseAvailable(HttpParser.java:235)
    at org.eclipse.jetty.server.BlockingHttpConnection.handle(BlockingHttpConnection.java:72)
    at org.eclipse.jetty.server.bio.SocketConnector$ConnectorEndPoint.run(SocketConnector.java:264)
    at org.eclipse.jetty.util.thread.QueuedThreadPool.runJob(QueuedThreadPool.java:608)
    at org.eclipse.jetty.util.thread.QueuedThreadPool$3.run(QueuedThreadPool.java:543)
    at java.lang.Thread.run(Thread.java:722)

我尝试使用CURL索引一些CSV文件。 首先我在shell中试过这个:

 curl http://localhost:8080/solr/update/csv -F "stream.file=/home/usersolr/Data/production/MyFile_1373882442023" -F  "commit=true" -F "header=false" -F "fieldnames=`cat /home/usersolr/Data/header/My_header`"

它的确有效,因为我收到了回复:

<?xml version="1.0" encoding="UTF-8"?>
<response>
<lst name="responseHeader"><int name="status">0</int><int name="QTime">1782</int></lst>
</response>

然后,我想在我的Java应用程序中集成这个命令行,我写了这段代码:

    Runtime runtime = Runtime.getRuntime();
    String cmd = "curl http://localhost:8080/solr/update/csv -F \"stream.file=/home/usersolr/Data/production/MyFile_1373882442023\" -F  \"commit=true\" -F \"header=false\" -F \"fieldnames=`cat /home/usersolr/Data/header/My_header`\"";          
    System.out.println(cmd);
    runtime.exec(cmd);

我得到了SolrException

org.apache.solr.common.SolrException: missing content stream.

我的文档没有编入索引。我在控制台中显示的cmd字符串与上面的shell命令完全相同。

我不管理getInputStream()getOutputStream()方法。它与我的问题有关吗?

由于

2 个答案:

答案 0 :(得分:1)

对于runtime.exec,你需要有一个命令数组,如下所示:

String cmd[] = new String[]{"curl", "http://localhost:8080/solr/update/csv", "-F", "\"stream.file=/home/usersolr/Data/production/MyFile_1373882442023\"", "-F"  "\"commit=true\"", "-F", "\""header=false\"", "-F", "\"fieldnames=`cat /home/usersolr/Data/header/My_header`\""};

答案 1 :(得分:0)

看起来您的URL输入未被提交,因此收到“缺少内容流”错误。

尝试以下命令,它应该可以工作。

curl http://localhost:8983/solr/update/csv?stream.file=exampledocs/books.csv&stream.contentType=text/plain;charset=utf-8

注意:必须使用完整路径或相对于正在运行的solr服务器的CWD的路径。