Sitcore 9 SolrCloud Custom Index/Alias Error
If you are adding custom Solr collections/indexes to SolrCloud in Sitecore 9, it is important to note that the parameter order matters in your patch config (always use a patch config). Without the proper order, you are likely to receive the following error:
The remote server returned an error: (400) Bad Request
[SolrConnectionException: <?xml version="1.0" encoding="UTF-8"?>
<response>
<lst name="responseHeader"><int name="status">400</int><int name="QTime">41</int></lst><str name="Operation createalias caused exception:">org.apache.solr.common.SolrException:org.apache.solr.common.SolrException: Can't create collection alias for collections='mycustom_web_index_MainAlias', 'mycustom_web_index_MainAlias' is not an existing collection or alias</str><lst name="exception"><str name="msg">Can't create collection alias for collections='mycustom_web_index_MainAlias', 'mycustom_web_index_MainAlias' is not an existing collection or alias</str><int name="rspCode">400</int></lst><lst name="error"><lst name="metadata"><str name="error-class">org.apache.solr.common.SolrException</str><str name="root-error-class">org.apache.solr.common.SolrException</str></lst><str name="msg">Can't create collection alias for collections='mycustom_web_index_MainAlias'
An example patch config that would generate such an error has the collection parameters first, when it needs the alias parameters first:
Important: This patch example is wrong per Sitecore as it needs the parameters in another order (more on the solution below!)
<index id="mycustom_web_index" type="Sitecore.ContentSearch.SolrProvider.SwitchOnRebuildSolrCloudSearchIndex, Sitecore.ContentSearch.SolrProvider">
<param desc="name">$(id)</param>
<param desc="collection">$(id)</param>
<param desc="rebuildcollection">$(id)_rebuild</param>
<param desc="mainalias">$(id)_MainAlias</param>
<param desc="rebuildalias">$(id)_RebuildAlias</param>
How to Fix the “Can’t Create Collection Alias for Collections” Error
The Sitecore documentation located at the following clearly defines a few key items: https://doc.sitecore.com/developers/90/platform-administration-and-architecture/en/switch-solr-indexes.html#UUID-7ae69678-7ac3-d0db-09d2-3937aacdf677_N1530083724083
- You need to have the ContentSearch.Solr.EnforceAliasCreation setting to true. This should be within a patch file and can look something like the following:
<?xml version="1.0" encoding="utf-8" ?>
<configuration xmlns:patch="http://www.sitecore.net/xmlconfig/" xmlns:set="http://www.sitecore.net/xmlconfig/set/"
xmlns:role="http://www.sitecore.net/xmlconfig/role/" xmlns:search="http://www.sitecore.net/xmlconfig/search/">
<sitecore search:require="Solr">
<settings>
<setting name="ContentSearch.Solr.EnforceAliasCreation" set:value="true" role:require="ContentManagement or Standalone" />
</settings>
</sitecore>
</configuration>
- You need to ensure that the patch file used on the CMS is different than the CDS (including the name spaces). The example patch for the CMS should look as follows (note: Sitecore does not provide a full example in their documentation… including that you need the name parameter in your include file).
Important: Only change the index id= line as Sitecore appears to be looking for the _MainAlias and _RebuildAlias names (much like how it looks for the xdb_internal alias and if you attempt a different alias name it fails).
<index id="mycustom_web_index" type="Sitecore.ContentSearch.SolrProvider.SwitchOnRebuildSolrCloudSearchIndex, Sitecore.ContentSearch.SolrProvider">
<param desc="name">$(id)</param>
<param desc="mainalias">$(id)_MainAlias</param>
<param desc="rebuildalias">$(id)_RebuildAlias</param>
<param desc="collection">$(id)</param>
<param desc="rebuildcollection">$(id)_rebuild</param>
<param desc="propertyStore" ref="contentSearch/indexConfigurations/databasePropertyStore" param1="$(id)" />
- For the CD Server, the patch file section would look something like the following. Note that the name space is different:
<index id="sitecore_web_index" type="Sitecore.ContentSearch.SolrProvider.SolrSearchIndex, Sitecore.ContentSearch.SolrProvider">
<param desc="name">$(id)</param>
<param desc="core">$(id)_MainAlias</param>
<param ref="contentSearch/indexConfigurations/databasePropertyStore"
desc="propertyStore" param1="$(id)" />
- Make sure that you define an active index update strategy in your patch config when using the SwitchOnRebuildSolrCloudSearchIndex