SharePoint 2013–Move the Search Index Location

2013-09-03T21:32:18+00:00 September 3rd, 2013|Uncategorized|

Chances are if you’re new to SharePoint you may have never thought about the Search Index location. The fact is, it should be a conscious design decision, not simply left to default without thought. It’s really quite an important part of the Search architecture (aren’t they all?) and if you’ve not given it much consideration before, I strongly urge you to start reading up on it. The Index component essentially partitions up the Search Indexes (into rows and columns) which allow for enormous scaling of both a) load from the Search Query and b) straight up volume of data. If we’re talking BIG indexes then it’s also possible to achieve low-latency so that as your content changes, the indexes are ready within seconds! Phew! What’s the net result of a well architected Search solution? Performance, resilience and stability.

So, if you find yourself having forgot to set the Index location value properly when you deployed Search, or you are re-visiting an existing environment and wish to ship them elsewhere, this post is for you. I’ve created a very simple PowerShell function that needs three user-defined variables. I’d recommend using the SharePoint Setup/Admin account for this.

Of course, if you want some assurance and expertise on hand, why not get in touch? We can arrange to send over a SharePoint Consultant to help out. If you ask really nicely, you might get me turning up!

Pre-Requisites

  • Ensure the Search topology is error-free. If you continue with problems in your topology, good luck explaining yourself when it breaks!
  • Know the name of the target Search Service Application (it’s not uncommon to have more than one)
  • Ensure the new Index directory is known and that it exists on ALL Index servers
  • Stop all Full and Incremental crawls, but let any running ones complete (not essential but good practice for completeness)

The Process

  1. Logon to the Index server, if you have more than one simply repeat this process on each Index server in turn (not together unless you relish over a bit of down time)
  2. Edit the PowerShell script (below) and change the three user-defined variables to suit your environment ($SearchServiceName, $Server and $IndexLocation)
  3. Save the PowerShell script somewhere on the Index server and execute it from an elevated Management Shell session
  4. Repeat on all Index servers, remembering to adjust the $Server variable
  5. Test! Once you’re happy it’s working, remove the old Index folder from the file system

Notes

  • During the first Set-SPEnterpriseSearchTopology; components in the Search topology will systematically show a warning (off and on) a few times. It will then show this:

1

  • During the second Set-SPEnterpriseSearchTopology; components in the Search topology will again systematically show a warning (off and on) a few times. It will then show this:

2

  • Once the script has finished, it’s a good time to check the topology is nice and tidy. You should see something like this:

3

The Script

# User-defined variables
 $SearchServiceName  = "Search Service"  # The name of your Search Service Application being altered
 $Server             = "SPSSERVER02"   # The name of the Index server currently being used
 $IndexLocation      = "E:Search Index" # The full path to the new Index location
 # No need to edit below this line
 # -------------------------------
function SearchIndexMove($SearchServiceName,$Server,$IndexLocation) {
 Add-PSSnapin Microsoft.SharePoint.PowerShell -ea 0;
 # Get the Search Service Application
 $SSA = Get-SPServiceApplication -Name $SearchServiceName;
 # Get the Search Service Instance
 $Instance = Get-SPEnterpriseSearchServiceInstance -Identity $Server;
 # Get the current Search topology
 $Current = Get-SPEnterpriseSearchTopology -SearchApplication $SSA -Active;
 # Create a clone of the current Search topology
 $Clone = New-SPEnterpriseSearchTopology -Clone -SearchApplication $SSA -SearchTopology $Current;
 # Add a new Index Component and the new Index location
 New-SPEnterpriseSearchIndexComponent -SearchTopology $Clone -IndexPartition 0 -SearchServiceInstance $Instance -RootDirectory $IndexLocation | Out-Null;
 if (!$?) { throw "ERROR: Check that `"$IndexLocation`" exists on `"$Server`""; }
 # Set the new Search topology as "Active"
 Set-SPEnterpriseSearchTopology -Identity $Clone;
 # Remove the old Search topology
 Remove-SPEnterpriseSearchTopology -Identity $Current -Confirm:$false;
 # There is an additional Index Component that needs removing
 # Get the Search topology again
 $Current = Get-SPEnterpriseSearchTopology -SearchApplication $SSA -Active;
 # Create a clone of the current Search topology
 $Clone = New-SPEnterpriseSearchTopology -Clone -SearchApplication $SSA -SearchTopology $Current;
 # Get the Index Component and remove the old one
 Get-SPEnterpriseSearchComponent -SearchTopology $Clone | ? {($_.GetType().Name -eq "IndexComponent") -and ($_.ServerName -eq $($Instance.Server.Address)) -and ($_.RootDirectory -ne $IndexLocation)} | Remove-SPEnterpriseSearchComponent -SearchTopology $Clone -Confirm:$false;
 # Set the new Search topology as "Active"
 Set-SPEnterpriseSearchTopology -Identity $Clone;
 # Remove the old Search topology
 Remove-SPEnterpriseSearchTopology -Identity $Current -Confirm:$False;
 Write-Host -ForegroundColor Green "Finished, remember to clean up the old Index location";
 }
SearchIndexMove -SearchServiceName $SearchServiceName -Server $Server -IndexLocation $IndexLocation
 # END

Disclaimer:

This script has been tested and working in the environment it was intended to be used in. This script is provided “as is”  without warranty, be it expressed or implied.