Add single quotation to curl xpost in shell script

I add this code in my shell script. But every time I add single quotation in painless( 'hello' )
It keeps giving me errors. I don't know what is wrong with my code. I hope you will be able to help with this. Thank you in advance.

cmd="curl -XPOST 'http://localhost:9200/_reindex' -H 'Content-Type: application/json'
-d '
{
"source": {
"index": "aaa"
},
"dest": {
"index": "bbb"
},
"script": {
"inline": "ctx._source.col1 = ctx._source.col2 + 'hello' ",
"lang": "painless"
}

}'
"
eval $cmd

this is more of a shell escaping question rather than an elasticsearch question.

As you havent mentioned your shell, the most important part is to read about escaping roles for your shell. Sometimes it is as easy as prepending the tick with a backslash, like \' when doing the quotation. You could also use double tickes and escape them properly, so that those are JSON escaped when being sent to Elasticsearch.

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