我用了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]"
}
}
下面是我测试的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]"
}
}
1 个回复
zhuyangping - 人不能一直幼稚下去
赞同来自:
body => '{"query": "SELECT * FROM test WHERE name = \u0027123\u0027"}'