Hello,

I've been investigating how to update our product search to be backed by a
category-routed alias. The initial steps used Postman to connect directly
to the Solr server (version 9.3.0). However, the final solution will need
to work with the SolrJ client (version 9.3.0). Yet I am unable to get SolrJ
to create the category routed alias.

While our client will create and manage the indexes, it may communicate
with servers that need different configurations. So we assume that the
server will have updated its defaults as necessary. In Postman I am using
the following requests to simulate the category creation and solr setup.
/api/cluster
{
"set-obj-property": {
"defaults" : {
"collection": {
"numShards": 3,
"nrtReplicas": 3,
"tlogReplicas": 0,
"pullReplicas": 0
}
}
}
}

/api/aliases
{
"name": "categorisedProducts",
"routers": [
{
"type": "category",
"field": "product_category_s",
"maxCardinality": 1000
}
],
"create-collection": {
"config": "ProductSearch"
}
}

When using SolrJ I am only doing the category creation, but when I omit any
details about how to shard the collection I get an error. If I only create
a collection I do not get an error.

Here is the error
org.apache.solr.client.solrj.impl.BaseHttpSolrClient$RemoteSolrException:
Error from server at
http://localhost:8983/solr/admin/collections?action=CREATEALIAS&name=TestCategory&router.name=CATEGORY&router.field=product_category_s&router.maxCardinality=0&create-collection.collection.configName=TestCategory&wt=javabin&version=2:
numShards is a required param (when using CompositeId router).

The Java code that creates the category.

Create createCollection = CollectionAdminRequest.createCollection(
categoryName, configSetName, null, null, null, null);

CreateCategoryRoutedAlias createCategory = CollectionAdminRequest.
createCategoryRoutedAlias(categoryName, categoryFieldName, 0,
createCollection);

createCategory.process(client);

Regards
David Driver

Reply via email to