Using regular expression

(ümmügülsüm Göktaş) #1

I have a question regarding a query.

I have a file named 'file121.docx', I am using the following query to search for the file:

GET demoindex/_search
{
  "_source": "documentName", 
  "query": {
    "regexp": {
      "documentName":{
       "value": "file121.docx"
       }
    }
  }
}

The query above does not return a result?

However when I run the query with a wildcard like so it returns the file?

GET demoindex/_search
{
  "_source": "documentName", 
  "query": {
    "regexp": {
      "documentName":{
       "value": "file121.*"
       }
    }
  }
}

When I run the same query with the full file name against another file from the list of files in my elastic search index it returns the result fine...

For Example:

GET demoindex/_search
{
  "_source": "documentName", 
  "query": {
    "regexp": {
      "documentName":{
       "value": "yjmnsdfs.exe"
      }
    }
  }
}

It seems to be an issue with files that contain numeric characters in the filename?

Does anybody have a solution for this?

(David Pilato) #2

Note that regex queries might be slow.
But if you really want to use this, you should define a proper mapping with a keyword or lowercase analyzer.

(system) closed #3

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