Can't escape single quote in json input in kibana visualization

I'm using kibana data table visualization and i need to make an aggregation that counts all fields that contains a specific message THAT contains single-quote, the problem is that i'm using painless lang in json input field and I can't escape this single quote, i've tried backslash and double single-quotes but nothing worked, here is an example of what i have:

{
"script": {
"inline": "doc['<field name>'].value == 'I can't escape single quote' ? 1 : 0", 
"lang": "painless"
}
}

@WAFA_Mardiney have u tried to do something like ?

...
"inline": 'doc["<field name>"].value == "I can't escape single quote" ? 1 : 0', 
....

There is also some mentions to examples here https://www.elastic.co/guide/en/elasticsearch/painless/current/painless-literals.html#string-literals

hi @tiagocosta,I tried the way you mentioned but it didn't work also i tried using backslash and all I get is error in json input like this:
image

Have you tried to escape every single quote you have inside the main double quote string?

thanks @tiagocosta for your replies, and yes i tried that also but nothing worked unfortunately.

@markov00 do you have any idea here?

1 Like

Hi, could you please try:

{
  "script": {
    "inline": "doc['<field name>'].value == \"I can't escape single quote\" ? 1 : 0", 
    "lang": "painless"
  }
}

you should just escape double quote around your string

1 Like

Thank you @markov00 and @tiagocosta , finally!! it worked.

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