• Home
  • LLMs
  • Docker
  • Kubernetes
  • Java
  • Maven
  • About
Apache Solr | SolrJ: Delete documents using CloudSolrClient
  1. Notes
  2. Example

  1. Notes
    In order for the code bellow to work:

    ► Make sure to update the variables ("solrUrl", "collectionName", ...) with your information.

    To force the commit, make sure to set the property "openSearcher" to true (SolrConfigXml file -> updateHandler -> autoCommit)

    Note: You can also force the commit by running the URL: http://localhost:8983/solr/COLLECTION-NAME/update?commit=true
  2. Example
    Delete documents using CloudSolrClient:
    final String[] solrUrl = { "http://localhost:8983/solr" };
    
    final String collectionName = "collection1";
    
    final CloudSolrClient cloudSolrClient = new CloudSolrClient.Builder(Arrays.asList(solrUrl)).build();
    
    cloudSolrClient.setDefaultCollection(collectionName);
    
    // deleting documents [CloudSolrClient::deleteById]
    {
        final UpdateResponse updateResponse = cloudSolrClient.deleteById(collectionName, "1");
    
        System.out.println(updateResponse);
    }
    
    cloudSolrClient.close();
© 2025  mtitek