question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Not able to query with reserved characters

See original GitHub issue

I’m using the following query string.

query_string : { fields : [“field1”, “field2”], query : "*testing\(*" }

But getting the following error:

“msg”: “[query_parsing_exception] Failed to parse query [testing(], with { index=someindex line=1 col=166 }”, “path”: “/somepath”, “query”: {}, “body”: “{"query":{"bool":{"must":[{"query_string":{"fields":["buildName","programName","sites","taskName","assignedTo","currentStatus","name","dueDate"],"query":"testing("}},{"missing":{"field":"deleted"}}],"must_not":{"match":{"currentStatus":"Completed"}}}},"from":0,"size":"10","sort":[{"dueDate":{"order":"asc"}}]}”, “statusCode”: 400, “response”: “{"error":{"root_cause":[{"type":"query_parsing_exception","reason":"Failed to parse query [testing(]","index":"someindex","line":1,"col":166}],"type":"search_phase_execution_exception","reason":"all shards failed","phase":"query","grouped":true,"failed_shards":[{"shard":0,"index":"someindex","node":"0v5EQ99oRWeZfN0WIU59wA","reason":{"type":"query_parsing_exception","reason":"Failed to parse query [testing(]","index":"someindex","line":1,"col":166,"caused_by":{"type":"parse_exception","reason":"Cannot parse ‘testing(’: Encountered \"<EOF>\" at line 1, column 10.\nWas expecting one of:\n <AND> …\n <OR> …\n <NOT> …\n \"+\" …\n \"-\" …\n <BAREOPER> …\n \"(\" …\n \")\" …\n \"\" …\n \"^\" …\n <QUOTED> …\n <TERM> …\n <FUZZY_SLOP> …\n <PREFIXTERM> …\n <WILDTERM> …\n <REGEXPTERM> …\n \"[\" …\n \"{\" …\n <NUMBER> …\n ","caused_by":{"type":"parse_exception","reason":"Encountered \"<EOF>\" at line 1, column 10.\nWas expecting one of:\n <AND> …\n <OR> …\n <NOT> …\n \"+\" …\n \"-\" …\n <BAREOPER> …\n \"(\" …\n \")\" …\n \"\" …\n \"^\" …\n <QUOTED> …\n <TERM> …\n <FUZZY_SLOP> …\n <PREFIXTERM> …\n <WILDTERM> …\n <REGEXPTERM> …\n \"[\" …\n \"{\" …\n <NUMBER> …\n "}}}}]},"status":400}” }

I’ve used "" to escape the special character “(”. Can’t I use special characters with wildcards? Any suggestions?

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

4reactions
bevacquacommented, Jan 17, 2018

@kaustav1992 I just ran into this need and built this function to escape user-provided values going into query_string. I think it’s what you were asking for.

function sanitizeValue(value) {
  return value
    .replace(/[<>]/g, ``)
    .replace(/([+-=&|><!(){}[\]^"~*?:\\/])/g, '\\$1')
}
1reaction
spalgercommented, Jan 17, 2018

Kibana should only be using the JSON search DSL when consuming user input.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Errors using special characters in Access databases - Office
To work around this problem, do not use special characters. If you must use special characters in query expressions, enclose the special ...
Read more >
SOQL query to fetch records with reserved characters ('*', '/', '(', ')')
This works for a SOSL query with reserved characters, such as the above example, but the functionality does not appear to exist in...
Read more >
Elasticsearch cannot find standalone reserved characters
When i search a word include escapable characters (reserved characters like: '\', '+', '-', '&&', '||', '!', '(', ')', '{', '}', '[', ']',...
Read more >
Search: Queries that include special characters return no results
Search yields no results or suggestions when special characters like hyphens ('-') or columns (':') are included in the search term.
Read more >
Avoid special characters and reserved words
Do not use special characters such as ( ) - & @ * $ | % ~ except for underscore (_). Also do...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found