• Home
  • LLMs
  • Docker
  • Kubernetes
  • Java
  • Maven
  • About
Apache Solr | Solr HTTP Admin API: Collections API
  1. Notes
  2. List Collections
  3. Create a Collection
  4. Delete a Collection
  5. Reload a Collection

  1. Notes
    See this page for more details about the Collections API:
    https://lucene.apache.org/solr/guide/8_5/collections-api.html
  2. List Collections
    • HTTP Request (URL):
      http://localhost:8983/solr/admin/collections?action=List&omitHeader=true&wt=xml&indent=true

      These parameters can be added to the request:
      • omitHeader=true|false

      • wt=json|xml

      • indent=true|false

    • Java sample:
      private void listCollections(final int jettyPort) throws IOException {
          final String url = "http://localhost:"
                  + jettyPort
                  + "/solr/admin/collections?action=List";
      
          final HttpGet request = new HttpGet(url);
      
          try (final CloseableHttpClient client = HttpClientBuilder.create().build();
                  final CloseableHttpResponse response = client.execute(request)) {
              final HttpEntity entity = response.getEntity();
      
              System.out.println(IOUtils.toString(entity.getContent(), "UTF-8"));
      
              // close the content stream.
              EntityUtils.consumeQuietly(entity);
          }
      }
  3. Create a Collection
    Create a collection (2 shards, 2 replicas), using an existing configuration directory in ZooKeeper ("_default").
    Assuming you have at least 2 Solr instances up and running.

    • HTTP Request (URL):
      http://localhost:8983/solr/admin/collections?action=CREATE&name=collection1&numShards=2&replicationFactor=2&maxShardsPerNode=2&collection.configName=_default

      Output:
      <response>
          <lst name="success">
              <lst name="192.168.2.33:8984_solr">
                  <lst name="responseHeader">
                      <int name="status">0</int>
                      <int name="QTime">2176</int>
                  </lst>
                  <str name="core">collection1_shard1_replica_n1</str>
              </lst>
              <lst name="192.168.2.33:8984_solr">
                  <lst name="responseHeader">
                      <int name="status">0</int>
                      <int name="QTime">2174</int>
                  </lst>
                  <str name="core">collection1_shard2_replica_n4</str>
              </lst>
              <lst name="192.168.2.33:8983_solr">
                  <lst name="responseHeader">
                      <int name="status">0</int>
                      <int name="QTime">2557</int>
                  </lst>
                  <str name="core">collection1_shard1_replica_n2</str>
              </lst>
              <lst name="192.168.2.33:8983_solr">
                  <lst name="responseHeader">
                      <int name="status">0</int>
                      <int name="QTime">2594</int>
                  </lst>
                  <str name="core">collection1_shard2_replica_n6</str>
              </lst>
          </lst>
      </response>

    • Java sample:
      private void createCollection(final int jettyPort, final String collectionName, final int numShards, final int numReplicas, final int maxShardsPerNode, final String configSetName) throws IOException {
          final String url = "http://localhost:"
                  + jettyPort
                  + "/solr/admin/collections?action=CREATE"
                  + "&name=" + collectionName
                  + "&numShards=" + numShards
                  + "&replicationFactor=" + numReplicas
                  + "&maxShardsPerNode=" + maxShardsPerNode
                  + "&collection.configName=" + configSetName;
      
          final HttpGet request = new HttpGet(url);
      
          try (final CloseableHttpClient client = HttpClientBuilder.create().build();
                  final CloseableHttpResponse response = client.execute(request)) {
              final HttpEntity entity = response.getEntity();
      
              System.out.println(IOUtils.toString(entity.getContent(), "UTF-8"));
      
              // close the content stream.
              EntityUtils.consumeQuietly(entity);
          }
      }
  4. Delete a Collection
    You will get an error if you try to delete a collection that is part of aliases.
    You have, first, to delete those aliases (or remove the collection from them) to be able to delete the collection.

    • HTTP Request (URL):
      http://localhost:8983/solr/admin/collections?action=DELETE&name=collection1

    • Java sample:
      private void deleteCollection(final int jettyPort, final String collectionName) throws IOException {
          final String url = "http://localhost:"
                  + jettyPort
                  + "/solr/admin/collections?action=DELETE"
                  + "&name=" + collectionName;
      
          final HttpGet request = new HttpGet(url);
      
          try (final CloseableHttpClient client = HttpClientBuilder.create().build();
                  final CloseableHttpResponse response = client.execute(request)) {
              final HttpEntity entity = response.getEntity();
      
              System.out.println(IOUtils.toString(entity.getContent(), "UTF-8"));
      
              // close the content stream.
              EntityUtils.consumeQuietly(entity);
          }
      }
  5. Reload a Collection
    The "RELOAD" action can be used if you the change the collection configuration in ZooKeeper.

    • HTTP Request (URL):
      http://localhost:8983/solr/admin/collections?action=RELOAD&name=collection1

    • Java sample:
      private void reloadCollection(final int jettyPort, final String collectionName) throws IOException {
          final String url = "http://localhost:"
                  + jettyPort
                  + "/solr/admin/collections?action=RELOAD"
                  + "&name=" + collectionName;
      
          final HttpGet request = new HttpGet(url);
      
          try (final CloseableHttpClient client = HttpClientBuilder.create().build();
                  final CloseableHttpResponse response = client.execute(request)) {
              final HttpEntity entity = response.getEntity();
      
              System.out.println(IOUtils.toString(entity.getContent(), "UTF-8"));
      
              // close the content stream.
              EntityUtils.consumeQuietly(entity);
          }
      }
© 2025  mtitek