使用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管理界面的
qmapCore文件管理页,检查solrconfig.xml中是否存在ExtractHandler的配置:
若缺失,添加该配置后重启Solr服务。<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> - 移除重复Commit操作:代码中
req.setAction(...)已指定Commit,后续的solrClient.commit(true, true)属于重复操作,建议移除其中一个,避免不必要的资源消耗。
内容的提问来源于stack exchange,提问作者Scaddenp
相关产品推荐
相关产品推荐

