iNikkz
iNikkz

Reputation: 3829

Adding shard in collection using collection API in solr

I am using Apache solr to create collection, shards. I am able to build collection using

sudo curl 'http://localhost:8983/solr/admin/collections?action=CREATE&name=demo&numShards=2&replicationFactor=1'

Here, collection name = "demo" number of Shards = "2"

but when I am adding new shard using

sudo curl 'http://localhost:8983/solr/admin/collections?action=CREATESHARD&shard=shard3&collection=demo'

It is giving error :

<?xml version="1.0" encoding="UTF-8"?>
<response>
<lst name="responseHeader"><int name="status">400</int><int name="QTime">1</int></lst><lst name="error"><str name="msg">shards can be added only to 'implicit' collections</str><int name="code">400</int></lst>
</response>

Upvotes: 0

Views: 1724

Answers (2)

leiting.liu
leiting.liu

Reputation: 1

Shards can only created with this API for collections that use the 'implicit' router (i.e., when the collection was created, router.name=implicit). A new shard with a name can be created for an existing 'implicit' collection.

reference,https://solr.apache.org/guide/8_6/collection-management.html

Upvotes: 0

MatsLindh
MatsLindh

Reputation: 52912

From the documentation for CREATESHARD:

Shards can only created with this API for collections that use the 'implicit' router. Use SPLITSHARD for collections using the 'compositeId' router. A new shard with a name can be created for an existing 'implicit' collection.

So the proper way to do this is to issue a SPLITSHARD command instead, and then remove the old shard after the two new shards have been created. From the SPLITSHARD documentation:

Splitting a shard will take an existing shard and break it into two pieces. The original shard will continue to contain the same data as-is but it will start re-routing requests to the new shards. The new shards will have as many replicas as the original shard. After splitting a shard, you should issue a commit to make the documents visible, and then you can remove the original shard (with the Core API or Solr Admin UI) when ready.

Upvotes: 2

Related Questions