I'm using graph (Graph Explorer as well as my custom Azure Application which utilizes Graph API with the appropriate grants of Files.ReadWrite.All, Sites.ReadWrite.All) to search for specific files within a folder in a drive as documented here: https://learn.microsoft.com/en-us/graph/api/driveitem-search?view=graph-rest-1.0&tabs=http.
If I specify as follows it works:
/drives/{drive-id}/root/search(q='{search-text}')
However, if I specify the parent folder's Id, it returns empty or misses files (it seems it misses mostly png, jpg, adobe files):
/drives/{drive-id}/items/{folder-id}/search(q='{search-text}')
{
"@odata.context": "https://graph.microsoft.com/v1.0/$metadata#Collection(driveItem)",
"value": []
}
This is also true when I use the https://graph.microsoft.com/v1.0/search/query endpoint.
If I specify a path, it will not return results.
"query": {
"queryString": "myfile path:\"https://contoso.sharepoint.com/sites/Library/Shared Documents/PATH\""
}
But if specify no path, or the Document library level, it will return the image files.
"query": {
"queryString": "myfile path:\"https://contoso.sharepoint.com/sites/Library/Shared Documents\""
}
Funny thing is that it usually does actually successfully bring up text or PDF documents, but images like PNG and JPG often get lost. That is confusing to me as well. However if I do the drive root search, those images can be found. Is there a reason why when I specify the parent folder the graph api doesn't work properly? I've given it some time to index, but doesn't seem to change. Any help would be appreciated.
I also noticed that the webUrl on an image file is something like:
https://contoso.sharepoint.com/sites/LIBRARY/Shared Documents/Forms/DispForm.aspx?ID=2702
but a docx file is
https://contoso.sharepoint.com/sites/LIBRARY/Shared Documents/My Path/myfile.docx
I would appreciate any help on this.
Hi @Rei ,
As the documentation search-concept-files-use-filters-in-search-queries,
In order to be valid, properties restriction should specify a valid, queryable managed property name in the condition.
Please refer SharePoint crawled-and-managed-properties-overview.
Hope this helps.
Hi @Rei , I'm trying to search for Files within Folders via ParentId as well, but no luck. Did you figure out a way to get it to work?
I have tried:
ParentLink:/QRH12ZKP56Y2GOVW7725BZO354PWSJTSQN
ParentLink:QRH12ZKP56Y2GOVW7725BZO354PWSJTSQN
ParentLink:\"QRH12ZKP56Y2GOVW7725BZO354PWSJTSQN\"
ParentId:/QRH12ZKP56Y2GOVW7725BZO354PWSJTSQN
ParentId:QRH12ZKP56Y2GOVW7725BZO354PWSJTSQN
ParentId:\"QRH12ZKP56Y2GOVW7725BZO354PWSJTSQN\"
I was just hypothesizing how it would be neat to be able to use an ID for ParentLink. But as per the answer, the ParentLink only works if you have the Parent Folder Name or path.
Sign in to comment