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)"
}