Microsoft Graph Search returning duplicates

435 Views Asked by At

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.

3

There are 3 best solutions below

0
rlv-dan On BEST ANSWER

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.

0
Zella_msft On

per my test, unfortunately, I cannot reproduce your issue. In my tests, I can use the following Graph API well and return only one result:

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

My test result: enter image description here

I suggest you can create a feedback on this issue, more professional will help you. Thank you for your understanding.

Feedback: https://feedbackportal.microsoft.com/feedback/forum/ebe2edae-97d1-ec11-a7b5-0022481f3c80

0
Cosme Benito On

I can reproduce the problem when I add "sortProperties"

Has duplicates:

{
    "requests": [{
            "entityTypes": ["driveItem"],
            "query": {
                "queryString": "<UNIQUE ID HERE>"
            },
            "fields": ["id", "name", "uniqueId"],
            "trimDuplicates": true,
            "sortProperties": [{
                    "name": "FileName",
                    "isDescending": false
                }
            ]
        }
    ]
}

Does not have duplicates:

{
    "requests": [{
            "entityTypes": ["driveItem"],
            "query": {
                "queryString": "<UNIQUE ID HERE>"
            },
            "fields": ["id", "name", "uniqueId"],
            "trimDuplicates": true
        }
    ]
}

Unfortunately it seems I have to choose between unsorted or duplicated results.