Search

$text and MongoDB Search with indexes that see every committed write.

TeselaDB implements $text and MongoDB Search (formerly Atlas Search): $search, $searchMeta, the search index commands. From MongoDB Search it also has the operators and the analyzers, as well as synonyms and field types. Search indexes live on the same nodes as the data, so you do not need a separate process.

Requirements

  • A user that can create search indexes on the collection.
JavaScript
db.articles.createSearchIndex({
  name: "default",
  definition: { mappings: { dynamic: true } },
});

db.articles.aggregate([
  { $search: { text: { query: "automatic replication", path: ["title", "body"] } } },
  { $limit: 10 },
  { $project: { title: 1, score: { $meta: "searchScore" } } },
]);

What changes from MongoDB

  • A search sees the writes committed before it, because search indexes are consistent. In MongoDB they can take a while to appear.
  • Scores come from the statistics of the whole collection, across all its ranges. They are the same on every replica and match those of a MongoDB replica set with the same documents.

Classic text

$text with a text index is the same as in MongoDB, with its score ($meta: "textScore"). For semantic search with vectors, see Vector search.

Check

The aggregation of the example returns the documents with their score, from highest to lowest.

Common problems

  • A $text query fails because the collection has no text index.

See also