Exact word only on Atlas Search

Is it possible to use search to match on an exact phrase?

For example, say I want to query a movie database for the title of “Red”. There are lots of movies I’d have to parse through that contain the word “red”. I just want the exact phrase.

I could just do something like db.movies.find({title: "Red"}) but suppose there is no index on title, but there is a search index. Can I make use of the search index with an exact match like that?

I would assume I could do it with regex, but I noticed that ^ and $ are not supported.

Hi @djedi,

Welcome to the MongoDB Atlas Search forum. I’d like to recommend a lucene.keyword analyzer for single-word exact match queries and phrase query for multi-word exact match queries.

Of course, you need to create an index, and then you can do something like:

{
  $search: {
     "index": "movies_search_index"
     "phrase": {
       "query": "Red Robin",
       "path": "title"
     }
  }
}
1 Like