Microsoft Search API search in mentioned sites only

captain_atharv 511 Reputation points
2022-06-15T07:34:11.597+00:00

Hi,

I'm using Microsoft Search API(https://learn.microsoft.com/en-us/graph/search-concept-overview) to search for files in drive. This returns results from multiple sites. I would like to search only in mentioned sites ie mentioned site ids. How can this be achieved?
This is my current request body
{
"requests": [
{
"entityTypes": [
"driveItem"
],
"query": {
"queryString": "sample"
}
}
]
}

Microsoft Graph
Microsoft Graph
A Microsoft programmability model that exposes REST APIs and client libraries to access data on Microsoft 365 services.
10,620 questions
SharePoint
SharePoint
A group of Microsoft Products and technologies used for sharing and managing content, knowledge, and applications.
9,664 questions
SharePoint Development
SharePoint Development
SharePoint: A group of Microsoft Products and technologies used for sharing and managing content, knowledge, and applications.Development: The process of researching, productizing, and refining new or existing technologies.
2,673 questions
0 comments No comments
{count} votes

Accepted answer
  1. HarmeetSingh7172 4,811 Reputation points
    2022-06-15T10:40:28.81+00:00

    Hi @captain_atharv

    Can you please try "queryString": "sample AND (Path:https://contoso.sharepoint.com/sites/sitename1 OR Path:https://contoso.sharepoint.com/sites/sitename2)" in queryString to get the files.

    Option 1-

    Below is the sample request:

    POST /search/query  
      
     {  
         "requests": [  
             {  
                 "entityTypes": [  
                     "driveItem"  
                 ],  
                 "query": {  
                     "queryString": "sample AND (Path:https://contoso.sharepoint.com/sites/sitename1 OR Path:https://contoso.sharepoint.com/sites/sitename2)"  
                 }  
             }  
         ]  
     }  
    

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

    Option 2-

    Below is the sample request:

    POST/search/query  
      
    {  
        "requests": [  
            {  
                "entityTypes": [  
                    "driveItem"  
                ],  
                "query": {  
                    "queryString": "may AND (SiteId:a6424d2a-39c1-471d-af44-5b65d1611889 OR SiteId:e3a2252f-d91d-4c03-a670-682e77bbe8ba)"  
                }  
            }  
        ]  
    }  
    

    Please use Site Collection unique ID (GUID) in queryString to get the files.
    Documentation reference-https://learn.microsoft.com/en-us/graph/api/resources/site?view=graph-rest-1.0#id-property

    Hope this helps.

    If the answer is helpful, please click "Accept Answer" and kindly upvote it. If you have further questions about this answer, please click "Comment".

    1 person found this answer helpful.

0 additional answers

Sort by: Most helpful