Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Identical Search Requests for SharePoint Sites via Microsoft Graph API returns different result sets with duplicates #2759

Open
tmaestrini opened this issue Aug 29, 2023 · 0 comments

Comments

@tmaestrini
Copy link

tmaestrini commented Aug 29, 2023

Describe the bug
I'm getting different results on two different systems by calling the identical search query. While the Graph Explorer returns the result set as expected, the identical query that was requested in an Azure Function (via the @microsoft/microsoft-graph-client NPM package) returns a result set with duplicates. The hitId of several duplicated records are identical.

To Reproduce
Steps to reproduce the behavior:

  1. Go to Graph Explorer
  2. Run query https://graph.microsoft.com/beta/search/query (POST) with this request body:
{
    "requests": [
        {
            "entityTypes": [
                "site"
            ],
            "query": {
                "queryString": "*",
                "queryTemplate": "(Path:https://tenant.sharepoint.com/sites/x.* OR Path:https://tenant.sharepoint.com/sites/x-*) AND RefinableDate01=2023-02-28"
            },
            "from": 0,
            "size": 50
        }
    ]
}
  1. Run query from the Azure Function:
    const dateLimit = '2023-02-28';
    const searchPayload = {
        "requests": [
            {
                "entityTypes": [
                    "site"
                ],
                "query": {
                    "queryString": "*",
                    "queryTemplate": `(Path:https://tenant.sharepoint.com/sites/x.* OR Path:https://tenant.sharepoint.com/sites/x-*) AND RefinableDate01=${dateLimit}`
                },
                "from": 0,
                "size": 50
            }
        ]
    };

    try {
        const results = (await graphClient.api('/search/query')
            .post(searchPayload));
        const { hits, total, moreResultsAvailable } = results?.value[0]?.hitsContainers[0] ?? undefined;
   } catch(err) {
      // intentionally omitted
   }
  1. The result sets contain different outputs:
  • Graph Explorer: 4 records
{
    "hits": [
        {
            "hitId": "tenant.sharepoint.com,c761e32f-dcad-461c-bf20-38c84595524a,01f04a12-5499-4943-b2a7-4449a9a09bc0",
            "rank": 1,
            "resource": {
                "@odata.type": "#microsoft.graph.site"
            }
        },
        {
            "hitId": "tenant.sharepoint.com,8fe83955-167f-4c95-a21c-744fe3a8ac02,f1d89c6a-d474-4ad3-b9a7-aa1d81371193",
            "rank": 2,
            "resource": {
                "@odata.type": "#microsoft.graph.site"
            }
        },
        {
            "hitId": "tenant.sharepoint.com,789b60ae-25c0-425f-9f39-cd849cda7343,380417c3-5e62-43c5-a63c-eae14166cfed",
            "rank": 3,
            "resource": {
                "@odata.type": "#microsoft.graph.site"
            }
        },
        {
            "hitId": "tenant.sharepoint.com,81331480-eec6-4c11-b77c-50619504ae02,f1d89c6a-d474-4ad3-b9a7-aa1d81371193",
            "rank": 4,
            "resource": {
                "@odata.type": "#microsoft.graph.site"
            }
        }
    ],
    "total": 4,
    "moreResultsAvailable": false
}
  • Azure Function Graph API Call: 6 records (with duplicated hitId)
{
  "hits": [
    {
      "hitId": "tenant.sharepoint.com,c761e32f-dcad-461c-bf20-38c84595524a,01f04a12-5499-4943-b2a7-4449a9a09bc0",
      "rank": 1,
      "resource": {
        "@odata.type": "#microsoft.graph.site"
      }
    },
    {
      "hitId": "tenant.sharepoint.com,c761e32f-dcad-461c-bf20-38c84595524a,01f04a12-5499-4943-b2a7-4449a9a09bc0",
      "rank": 2,
      "resource": {
        "@odata.type": "#microsoft.graph.site"
      }
    },
    {
      "hitId": "tenant.sharepoint.com,8fe83955-167f-4c95-a21c-744fe3a8ac02,f1d89c6a-d474-4ad3-b9a7-aa1d81371193",
      "rank": 3,
      "resource": {
        "@odata.type": "#microsoft.graph.site"
      }
    },
    {
      "hitId": "tenant.sharepoint.com,789b60ae-25c0-425f-9f39-cd849cda7343,380417c3-5e62-43c5-a63c-eae14166cfed",
      "rank": 4,
      "resource": {
        "@odata.type": "#microsoft.graph.site"
      }
    },
    {
      "hitId": "tenant.sharepoint.com,789b60ae-25c0-425f-9f39-cd849cda7343,380417c3-5e62-43c5-a63c-eae14166cfed",
      "rank": 5,
      "resource": {
        "@odata.type": "#microsoft.graph.site"
      }
    },
    {
      "hitId": "tenant.sharepoint.com,81331480-eec6-4c11-b77c-50619504ae02,f1d89c6a-d474-4ad3-b9a7-aa1d81371193",
      "rank": 6,
      "resource": {
        "@odata.type": "#microsoft.graph.site"
      }
    }
  ],
    "total": 4,
    "moreResultsAvailable": false

}

Expected behavior
The same request payloads have to lead to the same output. No duplicates are allowed.

Desktop (please complete the following information):

  • OS: MacOS
  • Browser: Chrome, Edge, Safari (always same behaviour)
  • Azure Functions: Azure Function Core Tools 4.x, Azure Function Runtime, 4.x, NodeJS 16.x

Additional context
All Graph Permissions are correctly set in the registered Azure AD App

@tmaestrini tmaestrini changed the title Identical Search Requests via Microsoft Graph API returning different result sets with duplicates Identical Search Requests for SharePoint Sites via Microsoft Graph API returning different result sets with duplicates Aug 29, 2023
@tmaestrini tmaestrini changed the title Identical Search Requests for SharePoint Sites via Microsoft Graph API returning different result sets with duplicates Identical Search Requests for SharePoint Sites via Microsoft Graph API returns different result sets with duplicates Aug 29, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant