microsoft-graph-apisharepoint-onlinesharepoint-search

Microsoft Graph Search returning duplicates


I am querying https://graph.microsoft.com/v1.0/search/query with the following payload:

{
    "requests": [
        {
            "entityTypes": [
                "listItem"
            ],
            "query": {
                "queryString": "uniqueid:925211fd-fc7e-4ed8-95fb-0bd00f378e8b"
            },
            "trimDuplicates": true,
            "fields": [
                "uniqueid",
                "originalpath"
            ]
        }
    ]
}

Searching for UniqueID I would expect a single result, but instead I get the same item twice:

{
    "value": [
        {
            "searchTerms": [],
            "hitsContainers": [
                {
                    "hits": [
                        {
                            "hitId": "925211fd-fc7e-4ed8-95fb-0bd00f378e8b",
                            "rank": 1,
                            "summary": "",
                            "resource": {
                                "@odata.type": "#microsoft.graph.listItem",
                                "fields": {
                                    "uniqueid": "{925211fd-fc7e-4ed8-95fb-0bd00f378e8b}",
                                    "originalpath": "https://tenant.sharepoint.com/sites/POC/POC Docs/Employee Contracts/JohnD Employee Contract.docx"
                                }
                            }
                        },
                        {
                            "hitId": "925211fd-fc7e-4ed8-95fb-0bd00f378e8b",
                            "rank": 2,
                            "summary": "",
                            "resource": {
                                "@odata.type": "#microsoft.graph.listItem",
                                "fields": {
                                    "uniqueid": "{925211fd-fc7e-4ed8-95fb-0bd00f378e8b}",
                                    "originalpath": "https://tenant.sharepoint.com/sites/POC/POC Docs/Employee Contracts/JohnD Employee Contract.docx"
                                }
                            }
                        }
                    ],
                    "total": 2,
                    "moreResultsAvailable": false
                }
            ]
        }
    ],
    "@odata.context": "https://graph.microsoft.com/v1.0/$metadata#Collection(microsoft.graph.searchResponse)"
}

I get duplicate results with other queries as well. It is not limited to a specific file or site. If I do the same search directly against SharePoint search I only get a single result as expected.

Am I doing something wrong, or is this a bug?

Edit:

After digging in the SharePoint home search (which also uses graph and gives me multiple results), I found an interesting detail indicating that the duplicate item comes from OneDrive. My hypothesis is that when I edit an item and it is put in "Recent" in OneDrive, the item is then returned by Graph. But I have not yet found a way to filter out these since they "look" identical. My solution for now is to simply filter out duplicate items before using the result.

Edit 2:

After 6 months dealing with various support instances I was finally able to contact MS Graph support by submitting a request in Azure Portal (instead of M365 support). They sort of acknowledged the problem. The problem was then partially fixed, however if i added paging to the request with more than 50 items per request the problem remained. After reporting this too, a bit later everything now appears to work.


Solution

  • By contacting Microsoft Graph support via Azure Portal the issue was eventually fixed silently. I can only conclude that this was an issue in MS Graph.