我正在尝试使用 solrj 在集合中添加/删除文档。当我在 SolrCloudClient 实例上设置默认集合时,该过程成功完成。但是,当我尝试使用请求发送集合名称而不是设置默认集合时,会引发异常:
org.apache.solr.client.solrj.SolrServerException: No collection param specified on request and no default collection has been set.
我已确保集合名称确实是从我的代码中发送的。
这是代码:
public void createDocument(Document document, String collectionName) throws BusinessException
{
SolrInputDocument solrInputDocument = new SolrInputDocument();
//cloudSolrClient.setDefaultCollection(collectionName);
Map<String,Object> fieldsData = document.getData();
for( String fieldName : fieldsData.keySet() )
{
Object fieldValue = fieldsData.get(fieldName);
solrInputDocument.addField(fieldName, fieldValue);
}
try
{
System.out.println(collectionName);
UpdateResponse documentAdditionResponse = cloudSolrClient.add(collectionName, solrInputDocument);
if(documentAdditionResponse.getStatus() != 0)
{
throw new BusinessException(StaticResponseCode.SOLR_SERVER_ERROR);
}
cloudSolrClient.commit();
}
catch(SolrException e)
{
throw new BusinessException(StaticResponseCode.NON_EXISTENT_COLLECTION);
}
catch (SolrServerException | IOException e)
{
e.printStackTrace();
throw new BusinessException(StaticResponseCode.SOLR_SERVER_ERROR);
}
}
我在这里想念什么?