Does the Microsoft Search API query or paginate first?

Lee Campbell 1 Reputation point
2022-08-18T11:18:41.967+00:00

The Microsoft Search API, as described here in this link (https://learn.microsoft.com/en-us/graph/api/resources/search-api-overview?view=graph-rest-1.0#page-search-results) seems to paginate first, then apply my query when I'm searching for drive items. I (rightly or wrongly) have found this very counterintuitive. Is this the expected behaviour?

Microsoft Graph
Microsoft Graph
A Microsoft programmability model that exposes REST APIs and client libraries to access data on Microsoft 365 services.
10,564 questions
{count} votes

1 answer

Sort by: Most helpful
  1. HarmeetSingh7172 4,811 Reputation points
    2022-08-23T07:23:36.757+00:00

    Hi @Lee Campbell

    Hope you're doing well.

    I've tested this scenario at my end and based on my understanding, this API works as per design. You can use from & size property in request body to control pagination of your Search results.

    Here's below sample request, -

    POST https://graph.microsoft.com/v1.0/search/query  
      
    {  
      "requests": [  
        {  
          "entityTypes": [  
            "driveItem"  
          ],  
          "query": {  
            "queryString": "docx"  
          },  
          "from": 0,  
          "size": 5  
        }  
      ]  
    }  
    

    The above request will list only 5 results (as size=5).

    Please note that size is different for different resources. Refer this documentation.

    You can modify from & size to change set of results (as per new range).

        {  
          "requests": [  
            {  
              "entityTypes": [  
                "driveItem"  
              ],  
              "query": {  
                "queryString": "docx"  
              },  
              "from": 10,  
              "size": 30  
            }  
          ]  
        }  
    

    The above request will fetch the results in between given range (i.e., 10 - 30).

    You can always check moreResultsAvailable property in response. If moreResultsAvailable is true, then there are more results that you can query.

    Hope this helps.

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