Friday, October 17, 2014

Retrieve count of documents in Search Index - SharePoint 2013

To retrieve count of  documents in search index, save below script as .ps1 file and run it using powershell


<# 
.SYNOPSIS 
    Script to get the total number of indexed documents  
.DESCRIPTION 
    For the given Search Application, return the total number of indexed documents. 
    This will be the sum of indexed documents for all index partitions. 
.PARAMETER SearchApplication 
    Search application to use.   Multiple SSA's can be specified by 
    piping them in to the script.  In that case the result will be an array 
    of document counts, one for each SSA 
.EXAMPLE 
    Get-SPEnterpriseSearchServiceApplication | Get-SPEnterpriseSearchIndexedDocumentCount.ps1 
    88123 
.LINK 
http://gallery.technet.microsoft.com/ScriptCenter 
.NOTES 
  File Name : Get-SPEnterpriseSearchIndexedDocumentCount.ps1 
  Author    : Matthew King 
 
#> 
 
[CmdletBinding()] 
param([Parameter(ValueFromPipeline=$True)] 
      [Microsoft.Office.Server.Search.Cmdlet.SearchServiceApplicationPipeBind]$SearchApplication) 
 
Process { 
    $ssa = Get-SPEnterpriseSearchServiceApplication $SearchApplication 
    $topo = Get-SPEnterpriseSearchTopology -SearchApplication $ssa | ? { $_.State -eq 'Active'} 
    $count = 0 
    Get-SPEnterpriseSearchComponent -SearchTopology $topo | ` 
        ? { $_ -is [Microsoft.Office.Server.Search.Administration.Topology.IndexComponent] } | ` 
        Sort-Object IndexPartitionOrdinal -Unique | % { $component = $_ 
            [int]$c = $ssa | Get-SPEnterpriseSearchStatus –HealthReport –Component $component.Name | ` 
                ? { $_.name -match 'number of documents\[' } | % { $_.message } 
            Write-Verbose ("{0} {1} {2} " -$ssa.Name, $component.Name, $c) 
            $count +$c 
    } 
    $count 
}

Reference
https://gallery.technet.microsoft.com/office/Script-to-report-total-88056b1b

Delete Search Index - SharePoint 2013

To delete search index in SharePoint 2013, it can be done by Central Admin or by powershell. To delete it using powershell run below command

(Get-SPEnterpriseSearchServiceApplication).Reset($true,$true)

If it takes a long time to delete index and ultimatley if it gives time out error, follow below steps


  1. Stop the Windows SharePoint Services Timer service (Found in Windows Services)
  2. Navigate to the cache folder
  3. In Windows Server 2008, the configuration cache is in the following location:
  4. Drive:\ProgramData\Microsoft\SharePoint\Config
  5. In Windows Server 2003, the configuration cache is in the following location:
  6. Drive:\Documents and Settings\All Users\Application Data\Microsoft\SharePoint\Config
  7. Locate the folder that has the file "Cache.ini"
  8. (Note: The Application Data folder may be hidden. To view the hidden folder, change the folder options as required)
  9. Back up the Cache.ini file.
  10. Delete all the XML configuration files in the GUID folder. Do this so that you can verify that the GUID folder is replaced by new XML configuration files when the cache is rebuilt.
  11. Note When you empty the configuration cache in the GUID folder, make sure that you do not delete the GUID folder and the Cache.ini file that is located in the GUID folder.
  12. Double-click the Cache.ini file.
  13. On the Edit menu, click Select All. On the Edit menu, click Delete. Type 1, and then click Save on the File menu. On the File menu, click Exit.
  14. Start the Windows SharePoint Services Timer service
  15. Note The file system cache is re-created after you perform this procedure. Make sure that you perform this procedure on all servers in the server farm.
  16. Make sure that the Cache.ini file in the GUID folder now contains its previous value. For example, make sure that the value of the Cache.ini file is not 1.



Reference
http://blogs.technet.com/b/maruntz/archive/2013/04/10/reset-the-content-index-of-sharepoint-server-2010-via-powershell.aspx
https://social.technet.microsoft.com/Forums/sharepoint/en-US/ede11fc6-59a7-47be-893d-dc1ea4c88879/cant-reset-index-sharepoint-2013