Add spell check to queries in Azure AI Search

Important

Spell correction is in public preview under supplemental terms of use. It's available through the Azure portal, preview REST APIs, and beta versions of Azure SDK libraries.

You can improve recall by spell-correcting words in a query before they reach the search engine. The speller parameter is supported for all text (non-vector) query types.

Prerequisites

  • A search service at the Basic tier or higher, in any region.

  • An existing search index with content in a supported language.

  • A query request that has speller=lexicon and queryLanguage set to a supported language. Spell check works on strings passed in the search parameter. It's not supported for filters, fuzzy search, wildcard search, regular expressions, or vector queries.

Use a search client that supports preview APIs on the query request. You can use a REST client or beta releases of the Azure SDKs.

Client library Versions
REST API Versions 2020-06-30-Preview and later. We recommend the latest preview API. 2024-05-01-preview
Azure SDK for .NET version 11.5.0-beta.5
Azure SDK for Java version 11.6.0-beta.5
Azure SDK for JavaScript version 11.3.0-beta.8
Azure SDK for Python version 11.4.0b3

The following example uses the built-in hotels-sample index to demonstrate spell correction on a simple text query. Without spell correction, the query returns zero results. With correction, the query returns one result for Johnson's family-oriented resort.

POST https://[service name].search.azure.cn/indexes/hotels-sample-index/docs/search?api-version=2024-05-01-preview
{
    "search": "famly acitvites",
    "speller": "lexicon",
    "queryLanguage": "en-us",
    "queryType": "simple",
    "select": "HotelId,HotelName,Description,Category,Tags",
    "count": true
}

Spell correction with full Lucene

Spelling correction occurs on individual query terms that undergo text analysis, which is why you can use the speller parameter with some Lucene queries, but not others.

  • Incompatible query forms that bypass text analysis include: wildcard, regex, fuzzy
  • Compatible query forms include: fielded search, proximity, term boosting

This example uses fielded search over the Category field, with full Lucene syntax, and a misspelled query term. By including speller, the typo in "Suiite" is corrected and the query succeeds.

POST https://[service name].search.azure.cn/indexes/hotels-sample-index/docs/search?api-version=2024-05-01-preview
{
    "search": "Category:(Resort and Spa) OR Category:Suiite",
    "queryType": "full",
    "speller": "lexicon",
    "queryLanguage": "en-us",
    "select": "Category",
    "count": true
}

Next steps