我正在使用Elasticsearch Index API https://www.elastic.co/guide/en/elasticsearch/reference/current/docs-index_.html将简单文档插入Elastic搜索。就像上一个链接中显示的示例一样,如果我使用如下所示的未转义json,则一切正常:
PUT twitter/_doc/1
{
"user" : "kimchy",
"post_date" : "2009-11-15T14:12:12",
"message" : "trying out Elasticsearch"
}
但是如果我转义了json(这对我来说是必需的):
PUT twitter/_doc/1
{
\"user\" : \"kimchy\",
\"post_date\" : \"2009-11-15T14:12:12\",
\"message\" : \"trying out Elasticsearch\"
}
然后Elasticsearch给出以下错误响应:
{ “错误”:{ “根本原因”: [ { “ type”:“ mapper_parsing_exception”, “ reason”:“解析失败” } ], “ type”:“ mapper_parsing_exception”, “ reason”:“解析失败”, “ caused_by”:{ “ type”:“ json_parse_exception”, “ reason”:“意外字符('\'(代码92)):期望双引号在[Source: org.elasticsearch.common.bytes.BytesReference$MarkSupportingStreamInputWrapper@6b8b84bb; 行:1,列:5]“ } }, “状态”:400}
或者我可能会得到:
{ “错误”:{ “根本原因”: [ { “ type”:“ mapper_parsing_exception”, “ reason”:“解析失败” } ], “ type”:“ mapper_parsing_exception”, “ reason”:“解析失败”, “ caused_by”:{ “ type”:“ json_parse_exception”, “ reason”:“意外字符('\'(代码92)):预期为有效值(数字,String,数组,对象,'true','false'或 'null')\ n,位于[来源: org.elasticsearch.common.bytes.BytesReference$MarkSupportingStreamInputWrapper@4a06b59f; 行:1,列:13]“ } }, “状态”:400}
好的,我理解它的意思,但是我看不到如何用转义的json实现这一目标。