You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

使用SolrJ向Solr 9.1新Core添加PDF时出现路径错误异常求助

问题

将老旧Solr应用与SolrJ索引器升级至9.1版本后,添加文档时抛出如下异常:

Exception in thread "main" org.apache.solr.client.solrj.impl.BaseHttpSolrClient$RemoteSolrException: Error from server at http://my.host:8983/solr/qmap:
Searching for Solr
You must type the correct path
Solr will respond

已确认Solr处于运行状态,且Solr管理界面中可见qmap Core,相关代码如下:

public class DocumentIndexer {
private final  String fileToIndex;
private final ConcurrentUpdateHttp2SolrClient solrClient;
private final Http2SolrClient http2Client;

public DocumentIndexer(String solrUrl, String fileToIndex) {
    this.fileToIndex =fileToIndex;
    http2Client = new Http2SolrClient.Builder().build();
    solrClient = new ConcurrentUpdateHttp2SolrClient.Builder(solrUrl, http2Client).build();
}

public void indexDocuments() throws IOException, SolrServerException{
  ContentStreamUpdateRequest req = new ContentStreamUpdateRequest("/update/extract");
  req.setAction(AbstractUpdateRequest.ACTION.COMMIT, true, true);
  req.addFile(new File(fileToIndex),"application/xml");
  req.setParam("id", fileToIndex);
  req.process(solrClient);
  solrClient.commit(true, true);
}
}

解决方案

  • 修正SolrClient初始化URL:确保传入DocumentIndexer的solrUrl为Core完整地址http://my.host:8983/solr/qmap。若之前传入的是Solr根地址http://my.host:8983/solr,请求会发送到根路径而非指定Core,引发路径错误。
  • 调整请求路径(可选):若必须使用Solr根地址初始化SolrClient,需将ContentStreamUpdateRequest的路径改为/qmap/update/extract,确保请求定位到目标Core。优先推荐直接绑定Core URL的方式,避免路径拼接失误。
  • 验证ExtractHandler配置:进入Solr管理界面的qmap Core文件管理页,检查solrconfig.xml中是否存在ExtractHandler的配置:
    <requestHandler name="/update/extract" class="org.apache.solr.handler.extraction.ExtractingRequestHandler">
      <lst name="defaults">
        <str name="lowernames">true</str>
        <str name="fmap.content">_text_</str>
      </lst>
    </requestHandler>
    
    若缺失,添加该配置后重启Solr服务。
  • 移除重复Commit操作:代码中req.setAction(...)已指定Commit,后续的solrClient.commit(true, true)属于重复操作,建议移除其中一个,避免不必要的资源消耗。

内容的提问来源于stack exchange,提问作者Scaddenp

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.04 07:35:18