How to ignore OneDrive Files in Sharepoint files search?

524 Views Asked by At

I'm trying to search Sharepoint & Teams files through POST https://graph.microsoft.com/v1.0/search/query. I passed the entityType as listItem in the request body so that I could able to search Sharepoint, Teams & Onedrive files.

But in my case, I should ignore the files from Onedrive.

Is there a way to filter OneDrive files & search only Sharepoint & Teams files?

1

There are 1 best solutions below

2
Michael Han On BEST ANSWER

The url of OneDrive files starts with https://contoso-my.sharepoint.com/, and the url of SharePoint files starts with https://contoso.sharepoint.com/.

So you could add filter in th query like this to ignore Onedrive files:

path:\"https://contoso.sharepoint.com/*\\"

Reference: https://learn.microsoft.com/en-us/graph/search-concept-files#example-5-use-filters-in-search-queries

https://learn.microsoft.com/en-us/sharepoint/dev/general-development/keyword-query-language-kql-syntax-reference