Search code examples
azureodataazure-cognitive-search

Azure Search how to make highlight response shorter using odata query syntax?


i am working with Azure Cognitive Search and this is my odata query expression:

...docs/?api-version=2021-04-30-Preview&search="budget+plan"|"business+plan"&queryType=simple&searchMode=all&$top=20&$skip=0&highlight=merged_content

And this is response:

4" :
{
    "@search.score" :
        0.20703253,
    "@search.highlights" :
    {
        "merged_content" :
        [
            "0" : "... 1500 characters here! Highlight is on the end ...."
        ]
    },

},

And my response from merged_content contains lines of couple thousands of chars. My question is, how to limit the chars number in response of Azure Search using odata query syntax and still get highlighted text?


Solution

  • Unfortunately, you have no control over the OData query syntax for what is hit highlighted other than your search query. See docs below:

    https://learn.microsoft.com/en-us/azure/search/search-pagination-page-layout#hit-highlighting

    However, you can implement some client-side logic to only return the highlighted tags since the hit highlights are in <em> tags.