Pagination for Sharepoint search through Micosoft Graph has strange behavior

Ossian Sandberg 20 Reputation points
2024-06-14T12:32:50.25+00:00

Hi,

I have this application that lists files from Sharepoint for the current user based on a query string together with pagination, aggregationfilters and sorting.

For the pagination I use the recommended (and only available) method for the search/query endpoint: "from" and "size". I have 10 results per page. When i navigate/paginate though the result it usually works fine and I get the expected result, but on certain pages i get less hits (8 or 9) and sometimes the hits[] array is completely non-existing but the "total"-property shows there are hits in the result.

Endpoint: https://graph.microsoft.com/v1.0/search/query

This is the initial request giving correct number of hits:

{
    "requests": [
      {
        "entityTypes": ["driveItem"],
        "query": {
          "queryString": "dokument AND isDocument=true AND path:\"https://sharepointURL\""
        },
        "aggregations": [
          {
            "field": "fileType",
            "size": 20,
            "bucketDefinition": {
              "sortBy": "count",
              "isDescending": "true",
              "minimumCount": 0
            }
          },
          {
            "field": "lastModifiedTime",
            "size": 2,
            "bucketDefinition": {
              "sortBy": "KeyAsString",
              "isDescending": "false",
              "minimumCount": 0,
              "ranges": [
                { "to": "2023-06-13T22:00:00.000Z" },
                { "from": "2023-06-13T22:00:00.000Z" },
                { "from": "2024-05-13T22:00:00.000Z" },
                { "from": "2024-06-06T22:00:00.000Z" }
              ]
            }
          }
        ],
        "from": 0,
        "size": 10,
        "fields": [
          "id",
          "name",
          "summary",
          "parentReference",
          "fileType",
          "lastModifiedDateTime",
          "lastModifiedBy",
          "webUrl",
          "size"
        ]
      }
    ]
  }


The response:

{
  "value": [
    {
      "searchTerms": ["dokument"],
      "hitsContainers": [
        {
          "hits": [
            ...hits
          ],
          "total": 648,
          "moreResultsAvailable": true,
          "aggregations": [
            {
              "field": "fileType",
              "buckets": [
                ...buckets
              ]
            },
            {
              "field": "lastModifiedTime",
              "buckets": [
                ...buckets
              ]
            }
          ]
        }
      ]
    }
  ],
  "@odata.context": "https://graph.microsoft.com/v1.0/$metadata#Collection(microsoft.graph.searchResponse)"
}

The request giving only 9 hits:

{
    "requests": [
      {
        "entityTypes": ["driveItem"],
        "query": {
          "queryString": "dokument AND isDocument=true AND path:\"https://sharepointURL\""
        },
        "aggregations": [
          {
            "field": "fileType",
            "size": 20,
            "bucketDefinition": {
              "sortBy": "count",
              "isDescending": "true",
              "minimumCount": 0
            }
          },
          {
            "field": "lastModifiedTime",
            "size": 2,
            "bucketDefinition": {
              "sortBy": "KeyAsString",
              "isDescending": "false",
              "minimumCount": 0,
              "ranges": [
                { "to": "2023-06-13T22:00:00.000Z" },
                { "from": "2023-06-13T22:00:00.000Z" },
                { "from": "2024-05-13T22:00:00.000Z" },
                { "from": "2024-06-06T22:00:00.000Z" }
              ]
            }
          }
        ],
        "from": 20,
        "size": 10,
        "fields": [
          "id",
          "name",
          "summary",
          "parentReference",
          "fileType",
          "lastModifiedDateTime",
          "lastModifiedBy",
          "webUrl",
          "size"
        ]
      }
    ]
  }

The request where "hits" gets undefined in the response:

{
    "requests": [
      {
        "entityTypes": ["driveItem"],
        "query": {
          "queryString": "dokument AND isDocument=true AND path:\"https://sharepointURL.com\""
        },
        "aggregations": [
          {
            "field": "fileType",
            "size": 20,
            "bucketDefinition": {
              "sortBy": "count",
              "isDescending": "true",
              "minimumCount": 0
            }
          },
          {
            "field": "lastModifiedTime",
            "size": 2,
            "bucketDefinition": {
              "sortBy": "KeyAsString",
              "isDescending": "false",
              "minimumCount": 0,
              "ranges": [
                { "to": "2023-06-13T22:00:00.000Z" },
                { "from": "2023-06-13T22:00:00.000Z" },
                { "from": "2024-05-13T22:00:00.000Z" },
                { "from": "2024-06-06T22:00:00.000Z" }
              ]
            }
          }
        ],
        "from": 110,
        "size": 10,
        "fields": [
          "id",
          "name",
          "summary",
          "parentReference",
          "fileType",
          "lastModifiedDateTime",
          "lastModifiedBy",
          "webUrl",
          "size"
        ]
      }
    ]
  }


The response:
"hits" is non-existing but the total tells us there should be hits

{
  "value": [
    {
      "searchTerms": ["dokument"],
      "hitsContainers": [
        {
          "total": 642,
          "moreResultsAvailable": true,
          "aggregations": [
            {
              "field": "fileType",
              "buckets": [
                ...buckets
              ]
            },
            {
              "field": "lastModifiedTime",
              "buckets": [
                ...buckets
              ]
            }
          ]
        }
      ]
    }
  ],
  "@odata.context": "https://graph.microsoft.com/v1.0/$metadata#Collection(microsoft.graph.searchResponse)"
}
Microsoft Graph
Microsoft Graph
A Microsoft programmability model that exposes REST APIs and client libraries to access data on Microsoft 365 services.
12,825 questions
SharePoint
SharePoint
A group of Microsoft Products and technologies used for sharing and managing content, knowledge, and applications.
11,087 questions
0 comments No comments
{count} votes

Accepted answer
  1. RaytheonXie_MSFT 38,016 Reputation points Microsoft Vendor
    2024-06-17T02:14:33.65+00:00

    Hi @Ossian Sandberg,

    There is some issue in sharepoint backend, Users' SharePoint Online content search results may be missing. You could refer to the report in Service health

    https://admin.microsoft.com/adminportal/home?#/servicehealth/:/alerts/SP709902

    The repair job to ensure content search results populate as expected is around 40 percent to completion. We estimate that this process should take approximately two weeks to complete and fully resolve this issue for all affected users.


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

    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

    0 comments No comments

0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.