Velin Georgiev Blog

CSOM Search Keyword query with custom managed metadata properties in Office365 / SharePoint

17 Jul 2015
Tags: SharePoint, Office365, CSOM, KeywordQuery, Provider-hosted app, CSharp
In order to access the custom managed properties we have to add them under SharePoint -> SharePoint admin center -> Manage Search Schema
Velin Georgiev blog image
You simply add your new managed property and associate it with the crawled property.

Velin Georgiev blog image

so when the next search crawl is finished you can get it via CSOM keyword query. The newly created property should look like this in the managed properties list:

Velin Georgiev blog image

Then your CSOM C# code should look like this:


KeywordQuery keywordQuery = new KeywordQuery(clientContext);
                    keywordQuery.QueryText = "path:\"https://onebitchh.sharepoint.com/sites/ilm/lists/Retention Rules\" AND ContentType:Item";
                    keywordQuery.ClientType = "CSOM";
                    keywordQuery.SelectProperties.Add("CountryOWSCHCS");
                    keywordQuery.SelectProperties.Add("CountryLegalRetentionPeriodStatus");
                    keywordQuery.SelectProperties.Add("CCHDocClassOWSTEXT");
                    keywordQuery.SelectProperties.Add("CCHDocumentDescripOWSMTXT");
                    keywordQuery.SelectProperties.Add("ContentType");
                    keywordQuery.SelectProperties.Add("ContentTypeId");
                    keywordQuery.SelectProperties.Add("SPContentType");
                    
                    
                    SearchExecutor searchExecutor = new SearchExecutor(clientContext);
                    ClientResult<ResultTableCollection> results = searchExecutor.ExecuteQuery(keywordQuery);
                    clientContext.ExecuteQuery();


If the  crawl is finished you should be able to see the results from your new managed property associated with site/list column:

Velin Georgiev blog image

Comments (0):

There are no comments yet! Be the first to comment this. We value your feedback!

Add comment