November 17th, 2026
0 reactions

Go beyond exact matches with full-text search in Azure DocumentDB

Product Manager

A customer searches for “waterprof jacket.” They expect your application to understand the typo, find relevant products, and show options they can buy. Someone searching a knowledge base for “connection timeout” needs a different kind of precision: those words should appear together, not somewhere in an unrelated article.

Azure DocumentDB full-text search, currently in preview, helps you build both experiences without adding and syncing a separate search service, such as Elasticsearch or OpenSearch. Combine relevance-ranked keyword search, typo tolerance, phrase and proximity matching, custom analyzers, and structured conditions through MongoDB-compatible commands and aggregation pipelines.

When your application also needs semantic retrieval, combine full-text and vector search against the same collection.

Azure DocumentDB Beyond Exact Matches image

Rank keyword matches by relevance

Finding a matching document is only the first step. Your application also needs to decide which results to show first.

Azure DocumentDB uses BM25 to rank text matches. BM25 considers how often query terms appear, how common those terms are across the collection, and document length. Your application can read each result’s score through searchScore.

Search a single field or query multiple mapped fields, such as a product’s title and description. Set matchCriteria to "all" when every analyzed query term must match, or "any" when one matching term is enough.

Learn more about BM25 keyword search.

Handle typos with fuzzy search

A misspelled word shouldn’t send customers to an empty results page.

Fuzzy search lets a text query match terms within a specified edit distance. For example, “waterprof” can match “waterproof” with fuzzy: { maxEdits: 1 }.

Choose one or two character edits, depending on how much tolerance your application needs. Start with one edit for stricter matching. Broader tolerance can help with longer words, but it can also introduce unrelated results, especially for short inputs.

Use fuzzy search for customer search boxes, knowledge bases, and other workloads where people enter imperfect text.

Learn more about fuzzy search.

Preserve word order with phrase and proximity matching

Sometimes the relationship between words matters as much as the words themselves.

Phrase search lets you require query terms in order. With slop: 0, a query for “waterproof jacket” requires adjacent terms. With slop: 1, it can also match “waterproof hiking jacket”.

Use proximity matching when titles or descriptions insert useful words between the terms your customer enters. Keep strict phrase matching for quoted searches, product names, or error messages where adjacency matters.

The preview supports slop values from 0 through 10. The phrase operator doesn’t accept fuzzy. You can combine separate phrase and fuzzy-text clauses, but that combination doesn’t create typo-tolerant phrase matching.

See the phrase and proximity guide.

Combine search relevance with business requirements

A relevant product still needs to meet the customer’s requirements. Structured search lets you combine text matching with exact values, numeric or date ranges, field existence, and membership conditions.

For example, find waterproof jackets while requiring available stock and a price below $100.

First, enable the preview on your cluster. In the Azure portal, open Settings > Features > Full-text search, then select Enable. Wait 10 minutes before creating a search index or running queries.

Connect through MongoDB Shell and create a new collection:

db.createCollection("searchBlogProducts");

db.searchBlogProducts.insertMany([
  {
    _id: 1,
    title: "Waterproof hiking jacket",
    price: 79,
    inStock: true
  },
  {
    _id: 2,
    title: "Waterproof alpine jacket",
    price: 149,
    inStock: true
  },
  {
    _id: 3,
    title: "Waterproof trail jacket",
    price: 59,
    inStock: false
  }
]);

Create a named search index with explicit mappings for the fields:

db.runCommand({
  createSearchIndexes: "searchBlogProducts",
  indexes: [
    {
      name: "product_search",
      definition: {
        mappings: {
          dynamic: false,
          fields: {
            title: { type: "string" },
            price: { type: "number", representation: "double" },
            inStock: { type: "boolean" }
          }
        }
      }
    }
  ]
});

Check the index and wait until it reports status: "READY" and queryable: true:

db.searchBlogProducts.aggregate([
  { $listSearchIndexes: { name: "product_search" } }
]);

Now combine fuzzy text matching, a phrase preference, and purchase requirements:

db.searchBlogProducts.aggregate([
  {
    $search: {
      index: "product_search",
      compound: {
        must: [
          {
            text: {
              query: "waterprof jacket",
              path: "title",
              matchCriteria: "all",
              fuzzy: { maxEdits: 1 }
            }
          }
        ],
        should: [
          {
            phrase: {
              query: "waterproof jacket",
              path: "title",
              slop: 1
            }
          }
        ],
        filter: [
          { equals: { path: "inStock", value: true } },
          { range: { path: "price", lt: 100 } }
        ]
      }
    }
  },
  { $limit: 10 },
  {
    $project: {
      _id: 0,
      title: 1,
      price: 1,
      score: { $meta: "searchScore" }
    }
  }
]);

For this sample, the query returns the waterproof hiking jacket. Fuzzy matching accommodates the missing letter. The price condition excludes the alpine jacket, and the availability condition excludes the trail jacket.

The should clause favors the phrase match but doesn’t require it. Move a phrase condition into must when every result must satisfy proximity requirements.

Keep $search first in the pipeline. The preview can let compound.filter conditions affect relevance scores, so don’t assume those conditions leave scores unchanged.

Adapt text analysis to your data

Natural-language descriptions, SKUs, and catalog paths need different matching rules. Custom analyzers let you choose how Azure DocumentDB splits and normalizes text at index time and query time.

Use an edgeGram analyzer to generate prefixes for identifiers. A customer entering sku-shoe can find SKU-SHOE-001 without typing the complete value. Choose prefix lengths for your workload, since generating more prefixes increases index size.

For hierarchical identifiers, use pathHierarchy. A path such as catalog/outdoor/running produces searchable hierarchy levels, allowing a query for catalog/outdoor to match entries beneath that path.

Analyzer pipelines also support case and accent normalization, stemming, stop-word removal, and pattern processing. Built-in analyzers handle Chinese, Japanese, Korean, and Thai.

One index can cover multiple fields with different analysis rules. Named multi mappings also let you apply alternate analyzers to the same field without duplicating the source data.

Choose how results appear

Relevance isn’t always the only ordering your application needs.

Use inline $search.sort to order results by mapped scalar fields, such as price or publication date. Keep the default relevance order when the best text match should appear first.

Place $limit immediately after $search when possible so the engine can push top-N retrieval into search execution. If you need a downstream business filter, apply it before the final limit so your application doesn’t discard eligible results too early.

Combine keyword and vector search

Keywords help retrieve specific terminology. Vector search helps connect different wording with similar meaning.

For a knowledge base, that combination can retrieve passages that contain a particular error name alongside passages that explain the same problem in different words.

Azure DocumentDB supports full-text and vector indexes on the same collection. Your application supplies embeddings, runs both retrieval queries, and combines the ranked results through Reciprocal Rank Fusion. Implement fusion in application code or an aggregation pipeline.

Follow the hybrid search guide for examples.

Get started with the preview

Azure DocumentDB includes full-text search with your cluster at no extra feature charge. Your cluster charges still apply.

The preview requires explicit field mappings and doesn’t currently support synonyms, facets, highlighting, or the autocomplete operator. Custom analyzers provide prefix matching through text queries instead.

Existing $text queries and text indexes keep their behavior. Create a separate search index to evaluate $search alongside your current application.

About Azure DocumentDB

Azure DocumentDB is a fully managed document database service for building and modernizing MongoDB-compatible applications. Powered by the open-source DocumentDB engine, it combines familiar APIs, tools, and workflows with Azure’s security, scalability, and operational simplicity. Whether you’re developing new applications or migrating existing MongoDB workloads, Azure DocumentDB helps you get started quickly and scale with confidence.

Category

Author

Khelan Modi
Product Manager

Hey there! I'm Khelan Modi, Product Manager at Azure Cosmos DB. My mission is to build a better MongoDB service for our cosmic universe! Join me on this cosmic journey from Redmond, and together, we'll shoot for the stars! 🌠 Let's connect and explore the wonders of cloud tech!

0 comments