In this blog post I will discuss changes Microsoft made to the logic behind Crawled and Managed Properties in SharePoint 2016. In SharePoint 2013, crawled and managed properties were automatically created by the Search crawler. You could then immediately start using the auto generated managed properties in your search queries, they just worked out-of-the box. I admit, they did not look pritty, but in those cases, where pritty was important, you could manually create them with pritty names …
Now, since SharePoint 2016, those auto-generated managed properties still seem to be created but they are disabled. If you look at one such managed property, you will see an info message stating the following:
Automatically created managed property. ManagedPropertyOWSTEXT is an automatically created managed property. You can't see any of its existing settings or which crawled properties are mapped to it, but you can map more crawled properties to it. If you save the managed property without making any changes, all settings will be deleted.
Now what is happening here? Is this a bug in SharePoint 2016? No, it isn’t. Microsoft states that this is intended, and is inspired by how it is configured in SharePoint Online. You cannot see what the configuration is in the property, but you can change and save, overriding the “internal” settings.
But wait, be aware that when you change the settings of auto generated managed properties, those custom settings will be lost when, for some reason, you need to reset your search index…
Changes in PowerShell
Now, I’m used to provisioning my search schema with PowerShell. I never had any problems doing this in SharePoint 2013, I assumed that my PowerShell would still work in SharePoint 2016. But the CmdLets Get-SPEnterpriseSearchMetadataCrawledProperty and Get-SPEnterpriseSearchMetadataManagedProperty did not return any results. It feels like the automatically created crawled and managed properties are not there, while I can see them in the Search Service Application Search Schema.
The reason for this is that in SharePoint 2016, crawled and managed properties that were automatically created from custom columns become part of the Search Index instead of the Search Schema. And the PowerShell CmdLets mentioned above are querying those in the Search Schema.
The solution for this is to create the crawled and managed properties from within PowerShell. Assume the following crawled and corresponding managed property that you would like to activate using PowerShell:
- MediaNameOWSTEXT (Managed property)
- ows_q_TEXT_MediaName (Crawled property)
I used the following PowerShell to activate them:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
Add-PSSnapin "Microsoft.SharePoint.PowerShell" # Get the Search Service Application $ssa = Get-SPEnterpriseSearchServiceApplication -Identity "Search Service Application" # Get Search category (origin was a site column) $category = Get-SPEnterpriseSearchMetadataCategory -SearchApplication $ssa -Identity "SharePoint" # Create crawled property # - PropSet: # - 158d7563-aeff-4dbf-bf16-4a1445f0366c - TaxonomyField # - fea84df6-a0fc-492c-9aa7-d28b8dcb08b3 - SPFieldMultiLineText, HtmlField, ImageField, LinkField # - ed280121-b677-4e2a-8fbc-0d9e2325b0a2 - SPFieldText, SPFieldChoice, SPFieldMultiChoice, SPFieldNumber, SPFieldCurrency, SPFieldDateTime, SPFieldBoolean, SPFieldUser, SPFieldUrl, SPFieldGuid # - 00130329-0000-0130-c000-000000131346 - other field types $crawledProperty = New-SPEnterpriseSearchMetadataCrawledProperty -SearchApplication $ssa -Category $category -VariantType 0 -PropSet "ed280121-b677-4e2a-8fbc-0d9e2325b0a2" -Name "ows_q_TEXT_MediaName" -IsNameEnum $false # Create managed property (Type 1 is Text, auto generated are always text) $managedProperty = New-SPEnterpriseSearchMetadataManagedProperty -SearchApplication $ssa -Name "MediaNameOWSTEXT" -Type 1 -FullTextQueriable $true -Queryable $true -Retrievable $true $managedProperty.Searchable = $true $managedProperty.Update() # Map managed property to crawled property $mapping = New-SPEnterpriseSearchMetadataMapping -SearchApplication $ssa -ManagedProperty $managedproperty -CrawledProperty $crawledproperty |
You can ignore the warnings, this is because the parameters SearchApplication and VariantType are mandatory but ignored when called like above.
No comments:
Post a Comment