How to find all managed properties of a document

When working with SharePoint search it is often helpful to figure out all of the managed properties that are populated for a given set of documents. With SharePoint 2013 on premise, you can use the Content Enrichment Web Service (CEWS) and its debug mode to get at (almost) all of the managed properties for a document as it is being indexed.  This requires a bit of setup to get the web service in place and then you need to feed your documents in to be indexed.  But what if you are interested in items already indexed? Or what if you are working with SharePoint Online where you don't have the CEWS?

SharePoint 2013 has a managed property called "ManagedProperties" that can be used instead. The ManagedProperties managed property is populated with the names of all the managed properties that have values for that document. The only trick is that this managed property is not retrievable, it can only be used as a refiner. 

You could add this refiner to your search center, but I have found it much more useful to explore using the SharePoint 2013 Search Query Tool and PowerShell.

To get started, download and fire up the Search Query Tool. Authenticate with you site and set up a query that returns the document(s) you are interested in.  Open a PowerShell window.

In the Query block of the Search Query Tool application configure the Refiners to be

managedproperties(filter=600/0/*)

and re-run your query. On the Refinement Results tab you should now see the managedproperties refiner that will have a big list of refinements. For example:

clip_image001

Scrolling through this list can often be helpful in itself, but sometimes it is nice to be able to see the values of all these managed properties and hand cutting-and-pasting can be quite cumbersome. The following technique can be used to make things much easier.

Go to the Raw tab and at the bottom you will see a big bunch of JSON like:

clip_image002

Select and copy all of the JSON. Now open PowerShell:

 $obj = $obj = ConvertFrom-Json (Get-Clipboard)
$r = $obj.d.query.PrimaryQueryResult.RefinementResults.Refiners.results | `
         ? { $_.name -eq 'managedproperties' }
$names = $r.Entries.results | % { $_.RefinementName } | sort
$names -join "," | Out-Clipboard

And now you can paste the list of mps separated by commas. Go back to the Search Query Tool and paste the list into the Select Properties box and run your search again. On the Primary Results tab you'll now see all of the (retrievable) managed properties. (Note: some managed properties still won't have values because they have been configured to be non-retrievable.)

clip_image003