Lucene query with equal sign (not a special char)

Hello,

how to search for a string containing the equal sign? path:code= gives me all logs containing “code” without taking the = into consideration. The equal sign is not considered a special character so I don’t get why it’s skipped as a search criteria.

Hi @elge,

Have you tried rapping it into quotes(") or using an escaping():

i.e:

 {
  "query": {
    "term": { "path": "code=" }
  }
}

or
path:code\=

Best,
Mantas

yes I did try that, but it doesn’t change anything.
not sure about the double-quotes but as I understood, those can be avoided as long as the string is just one word (not a phrase).
besides, = is not considered a special char by Lucene so it doesn’t need escaping.

Looks to me like = is taken as range evaluation as with numeric operators such as >=. Maybe it is a special char in the end? Anyhow, escaping it doesn’t help.

I also tried using regexp. Result is different. path:/code=/ and path:/code\=/ don’t find anything while path: /code.+/ matches literal chars only after code. Namely codename for example. Not code=. Looks like even the regex search doesn’t like the equal sign.

Hi @elge, is the equal sign returned if you try to analyze your query? Depending on the field type, it may use the standard analyzer, which typically removes all symbols.
You can try sending a multi_match query with both your original field and its keyword field for the exact match or use match_phrase to broaden the scope of your search to see if it matches your desired results:

{
  "query": {
    "multi_match": {
      "query": "code=",
      "fields": ["path", "path.keyword"],
      "operator": "or"
    }
  }
}
{
  "query": {
    "match_phrase": {
      "path": "code="
    }
  }
}