Searching special characters by regex does not work?

Hi,

I’ve been trying to search by regex but I can’t figure out how to use it exactly?

I created an index having a field title and this is the configuration of the index and title field.

{
  "mappings": {
    "dynamic": false,
    "fields": {
      "_id": {
        "type": "objectId"
      }
      "title": {
        "type": "string"
      }
    }
  }
}

For example, the value title is Jon test shared?
At the moment, my current query return nothing.

$search: {
      index: "default",
      regex: {
        query: "(.*)jon test(.*)",
        path: "title",
        allowAnalyzedField: true
      }
    }

Atlas search even through error when I was trying to search a special character.

$search: {
      index: "default",
      regex: {
        query: "(.*)shared\?(.*)",
        path: "title",
        allowAnalyzedField: true
      }
    }

—> Failed to run this query. Invalid pipeline

When you use ‘string’ as the field type, in your case uses lucene.standard as the analyzer, which splits (and removes) whitespace. You will need to choose a different analyzer, like lucene.keyword (note that it does not lowercase) to have the whitespace and other special characters available within a token that comes out of the analyzer.

1 Like

@Erik_Hatcher Many thanks for the answer. It works for me!

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