Querying SharePoint 2013 Search Index for Managed Property Values / Refiners using REST API

A client recently had a request to provide a search users by department with the department list pre-populated in a drop-down menu:

Snapshot

So the question was:

How can I query the Department managed property values for People to populate the drop-down menu?” (which would be cool if it autocompleted.. for another day maybe!)

The answer is: Using the Search REST API with a single GET query:

https://mysite/_api/search/query?QueryText=’*’&ContentClass=’urn:content-class:SPSPeople’&selectproperties=’Department’&Refiners=’Department’&RowLimit=0

To break down the above URL:

QueryText=’*’ – Get EVERYTHING

ContentClass=’urn:content-class:SPSPeople’ – Only People

selectproperties=’Department’ – Retrieve Department property (Edit: No surprise @mikaelsvenson is right this is not strictly necessary unless you need this in the results, but we don’t care about them for now!)

Refiners=’Department’ – This is the important element; retrieve all Department refiners

RowLimit=0 – We don’t actually want any results, we just want to know what all the refiners would have been so we can fill our drop-down menu

 

The result is XML which you can do what you want with – note that even with 0 RowLimit the refiners are still retrieved – bonus!

image

Hope that helps! 🙂


Posted

in

,

by

Comments

2 responses to “Querying SharePoint 2013 Search Index for Managed Property Values / Refiners using REST API”

  1. siva

    Can we get list of all managed properties on a given source id , also I need the managed properties which are sort enabled

  2. siva

    can I get sort enabled managed properties??

Leave a Reply

Your email address will not be published. Required fields are marked *