SharePoint Search REST API - PrimaryQueryResult is null

JeromeMZK 1 Reputation point
2021-09-01T09:27:34.597+00:00

I develop a SPFX WebPart that uses the SharePoint Search REST API. This SPFX WP is used in several tenants.

The request is this below:

{
    "request": {
        "__metadata": {
            "type": "Microsoft.Office.Server.Search.REST.SearchRequest"
        },
        "Querytext": "ContentClass:STS_Site AND WebTemplate:GROUP (NOT PrivacyIndicator:4) Title:test* ",
        "RowLimit": 20,
        "TrimDuplicates": false,
        "SortList": {
            "results": [
                {
                    "Direction": 1,
                    "Property": "LastModifiedTime"
                }
            ]
        },
        "SelectProperties": {
            "results": [
                "LastModifiedTime",
                "Description",
                "Title",
                "Author",
                "OriginalPath",
                "UniqueId",
                "SiteID",
                "WebId",
                "SiteLogo",
                "People",
                "AuthorOWSUSER",
                "Created",
                "WebTemplate",
                "GroupId",
                "PrivacyIndicator"
            ]
        },
        "Properties": {
            "results": [
                {
                    "Name": "EnableDynamicGroups",
                    "Value": {
                        "BoolVal": true,
                        "QueryPropertyValueTypeIndex": 3
                    }
                }
            ]
        },
        "HitHighlightedProperties": {
            "results": []
        },
        "RefinementFilters": {
            "results": []
        }
    }
}

A. When the response has some results, there is no problem.

B. When this request has no result, for all tenants except one, the response has this body:

    {
        "odata.metadata": ".../_api/$metadata#Microsoft.Office.Server.Search.REST.SearchResult",
        "ElapsedTime": 32,
        "PrimaryQueryResult": {
            "CustomResults": [],
            "QueryId": "762be03b-ae4f-438e-984d-4f81d2416506",
            "QueryRuleId": "00000000-0000-0000-0000-000000000000",
            "RefinementResults": null,
            "RelevantResults": {
                "GroupTemplateId": null,
                "ItemTemplateId": null,
                "Properties": [ ... ],
                "ResultTitle": null,
                "ResultTitleUrl": null,
                "RowCount": 0,
                "Table": {
                    "Rows": []
                },
                "TotalRows": 0,
                "TotalRowsIncludingDuplicates": 0
            },
            "SpecialTermResults": null
        },
        "Properties": [ ... ],
        "SecondaryQueryResults": [],
        "SpellingSuggestion": "",
        "TriggeredRules": []
    }

=> PrimaryQueryResult has a correct value and specifies that there are no result (TotalRows is 0).

C. When this request has no result, for one specific tenant, the response has this unexpected body:

    {
        "odata.metadata": ".../_api/$metadata#Microsoft.Office.Server.Search.REST.SearchResult",
        "ElapsedTime": 35,
        "PrimaryQueryResult": null,
        "Properties": [ ... ],
        "SecondaryQueryResults": [ ... ],
        "SpellingSuggestion": "",
        "TriggeredRules": [ ... ]
    }

=> The problem here is that PrimaryQueryResult is null, unlike all other tenants.

What could cause this behavior?
In what cases can PrimaryQueryResult be null?

SharePoint
SharePoint
A group of Microsoft Products and technologies used for sharing and managing content, knowledge, and applications.
9,682 questions
SharePoint Development
SharePoint Development
SharePoint: A group of Microsoft Products and technologies used for sharing and managing content, knowledge, and applications.Development: The process of researching, productizing, and refining new or existing technologies.
2,675 questions
0 comments No comments
{count} votes

4 answers

Sort by: Most helpful
  1. RaytheonXie_MSFT 31,606 Reputation points Microsoft Vendor
    2021-09-02T08:28:20.447+00:00

    Hi @JeromeMZK ,
    Could you confirm that the different tenants take different permissions?Permission will affect the result of query.


    If an Answer is helpful, please click "Accept Answer" and upvote it.
    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

  2. JeromeMZK 1 Reputation point
    2021-09-02T09:38:02.883+00:00

    Thank you for your answer.

    I'm not sure to understand your question: what kind of permissions are you talking about?
    These different tenants are those of my different customers.


  3. 杨建宇 11 Reputation points MVP
    2021-09-09T07:54:37.073+00:00

    Please make sure your account has read permission in the talent.
    You can crawled items after you have permission in the site.
    You can't get any items if you don't have permission in the site.


  4. JeromeMZK 1 Reputation point
    2021-09-29T12:24:26.95+00:00

    @Wendy Li_MSFT I'm sorry but this answer doesn't answer my problem.
    I have all the rights I need at all levels.
    The problem is something else.

    The problem is not about having access to elements or not but that the search service returns a PrimaryQueryResult to null for a single tenant when there is no result to a query.