Logstash http_poller body escape double and single quotation marks

Hi
I used logstash http_ poller calls the SQL API of elasticsearch. There are double quotation marks and single quotation marks in the body.
Here is the body I tested.
body => '{"query": "SELECT * FROM test WHERE name = '123'"}'
If \ is used to escape single quotation marks, an error will be reported.
The following is the error message.

{
"status" => 400,
"@version" => "1",
"@timestamp" => 2021-08-20T06:30:05.298Z,
"error" => {
"caused_by" => {
"type" => "json_parse_exception",
"reason" => "Unrecognized character escape ''' (code 39)\n at [Source: (org.elasticsearch.common.io.stream.InputStreamStreamInput); line: 1, column: 46]"
},
"root_cause" => [
[0] {
"type" => "x_content_parse_exception",
"reason" => "[1:11] [sql/query] failed to parse field [query]"
}
],
"type" => "x_content_parse_exception",
"reason" => "[1:11] [sql/query] failed to parse field [query]"
}
}

Try this
body => '{"query": "SELECT * FROM test WHERE name = \u0027123\u0027"}'

:slightly_smiling_face: Thank you for your reply. You are right.

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