我正在使用Curl将数据放入ES。我已经创建了一个customer
索引。
以下命令来自ES document。
curl -X PUT "localhost:9200/customer/_doc/1?pretty" -H 'Content-Type: application/json' -d'
{
"name": "John Doe"
}
'
当我这样做时,我得到一个错误。
{
"error" : {
"root_cause" : [
{
"type" : "mapper_parsing_exception",
"reason" : "failed to parse"
}
],
"type" : "mapper_parsing_exception",
"reason" : "failed to parse",
"caused_by" : {
"type" : "json_parse_exception",
"reason" : "Unexpected character ('n' (code 110)): was expecting double-quote to start field name\n at [Source: org.elasticsearch.common.bytes.BytesReference$MarkSupportingStreamInputWrapper@1ec5236e; line: 3, column: 4]"
}
},
"status" : 400
}
我认为,以下是我出错的主要原因。
reason" : "Unexpected character ('n' (code 110)): was expecting double-quote to start field name
我觉得我需要使用(反斜杠)逃脱。但是,我的尝试
\'
效果不佳。有什么建议吗?
最佳答案
我使它像下面一样工作。
curl -X PUT "localhost:9200/customer/_doc/1?pretty" -H 'Content-Type: application/json' -d '
{
\"name\": \"John Doe\" <==== I used "backslash" in front of all the "
}
'
回答不加评论:
curl -X PUT "localhost:9200/customer/_doc/1?pretty" -H 'Content-Type: application/json' -d '
{
\"name\": \"John Doe\"
}
'
关于elasticsearch - 使用Curl将数据放入ES中并获得意外字符('n'(代码110)),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57001174/