• Home
  • LLMs
  • Docker
  • Kubernetes
  • Java
  • Maven
  • About
Apache Solr | SolrJ: Delete documents using the request handler /update
  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 the request handler /update:
    final String UPDATE_REQUEST_PATH = "/update";
    
    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 [/update] [UpdateRequest::deleteById]
    {
        final UpdateRequest updateRequest = new UpdateRequest();
    
        updateRequest.deleteById("1");
        updateRequest.setPath(UPDATE_REQUEST_PATH);
        updateRequest.setMethod(METHOD.POST);
    
        final NamedList<Object> response = cloudSolrClient.request(updateRequest);
    
        System.out.println(response);
    }
    
    cloudSolrClient.close();
© 2025  mtitek