$search: 'equals' filter returns nothing, while 'text' does

We have a search index with a few fields defined. One of those fields has path: ‘meta.meta.Status’. This can have a few values, one of them being: “Cancelled”.

Now we are trying to query this in a following way:

{
      'index': 'search-all-sparse',
      "compound": {
        "must": {
          "equals": {
            "value": "Cancelled",
            "path": "meta.meta.Status"
          }
        }
      }
}

This returns zero results, while this (from this does a ‘contains’) does give result. But what we are after is exact match.

{
      'index': 'search-all-sparse',
      "compound": {
        "must": {
          "text": {
            "query": "Cancelled",
            "path": "meta.meta.Status"
          }
        }
      }
}

We are sure that an exact match should work, considering the following does return results

db.collectionName.find({meta.meta.Status: { $eq: "Cancelled" }})

Regex doesn’t seem to work either, even a (.*) regex returns nothing:

"compound": {
        "must": {
          "regex": {
            "query": '(.*)',
            "path": "meta.meta.Status",
            "allowAnalyzedField": true
          }
        }
      }

So the question here is: How to get the equals and regex filter to work?

Hi @Jacob_van_Pouderoijen , welcome to the MongoDB Community! To use the $search equals operator, you must index the field as a token field mapping type. Can you add

{
   "type": "token"
}

to the index definition for meta.meta.Status? If you are not sure where to add it, please feel free to share your search index definition and I can provide guidance. You should get the results you are expecting once the search index has this.

Hi @amyjian,

Thank you for the fast reply, excuses for my late one.
This was indeed the solution and both equals and regex now work :smiley:

This topic was automatically closed 5 days after the last reply. New replies are no longer allowed.