0

I'm searching for list items using the /search/query endpoint of MS Graph. I want to use aggregations and spell checking. This is my request

{
    "requests": [
        {
            "entityTypes": [
                "listItem"
            ],
            "query": {
                "queryString": "inspring"
            },
            "fields": [
                "title"
            ],
            "aggregations": [
                {
                    "field": "fileType",
                    "size": 20,
                    "bucketDefinition": {
                        "sortBy": "count",
                        "isDescending": "true",
                        "minimumCount": 0
                    }
                }
            ],
            "queryAlterationOptions": {
                "enableModification": true
            }
        }
    ]
}

It returns no results, since the search term was not spell checked and modified:

{
    "value": [
        {
            "searchTerms": [
                "inspring"
            ],
            "hitsContainers": [
                {
                    "total": 0,
                    "moreResultsAvailable": false
                }
            ]
        }
    ],
    "@odata.context": "https://graph.microsoft.com/beta/$metadata#Collection(microsoft.graph.searchResponse)"
}

However, when I remove the aggregations and use the following request, it works:

{
    "requests": [
        {
            "entityTypes": [
                "listItem"
            ],
            "query": {
                "queryString": "inspring"
            },
            "fields": [
                "title"
            ],
            "queryAlterationOptions": {
                "enableModification": true
            }
        }
    ]
}

Response:

{
    {
    "value": [
        {
            "searchTerms": [
                "inspiring"
            ],
            "hitsContainers": [
                {
                    "hits": [...],
                    "total": 64,
                    "moreResultsAvailable": true
                }
            ],
            "queryAlterationResponse": {
                "originalQueryString": "inspring",
                "queryAlteration": {
                    "alteredQueryString": "inspiring",
                    "alteredHighlightedQueryString": "inspiring",
                    "alteredQueryTokens": [
                        {
                            "offset": 0,
                            "length": 8,
                            "suggestion": "inspiring"
                        }
                    ]
                },
                "queryAlterationType": "modification"
            }
        }
    ],
    "@odata.context": "https://graph.microsoft.com/v1.0/$metadata#Collection(microsoft.graph.searchResponse)"
}

How do I have to change my request to make query alterations work with aggregations?

T_J
  • 75
  • 7
  • Please refer this document to use the Microsoft Search API to refine queries with aggregations: https://learn.microsoft.com/en-us/graph/search-concept-aggregation – Mehtab Siddique Sep 02 '22 at 09:07
  • I know how to refine querie with aggregations. The problem is that spell checking stops working as soon as a query is refined with aggregations. How does your link help with this problem? – T_J Sep 02 '22 at 13:53

0 Answers0