logstash http_poller body 转义双引号和单引号

Logstash | 作者 zhuyangping | 发布于2021年08月20日 | 阅读数:349

我用了logstash http_poller 调用了es 的 sql API , body里有双引号和单引号,怎么转义
下面是我测试的body,如果用\会报错
body => '{"query": "SELECT * FROM test WHERE name = \'123\'"}'
错误信息
{
"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]"
}
}
已邀请:

zhuyangping - 人不能一直幼稚下去

赞同来自:

自己试了一下,用 \u0027 转义 '
body => '{"query": "SELECT * FROM test WHERE name = \u0027123\u0027"}'

要回复问题请先登录注册