elasticsearch - 使用Curl将数据放入ES中并获得意外字符('n'(代码110))

标签 elasticsearch curl

我正在使用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/

相关文章:

elasticsearch - 有没有一种方法可以对现有数据启用_source?

unit-testing - 如何知道添加新数据后 Elasticsearch 何时准备好进行查询?

amazon-web-services - AWS-尝试在EC2实例上为Elasticsearch安装kopf插件

php - 为什么 get_headers() 返回 400 Bad request,而 CLI curl 返回 200 OK?

c++ - 在 Debug模式下 curl CURLE_COULDNT_RESOLVE_HOST

curl - 访问在 Vagrant 中运行的 Docker 容器

docker - 使用docker-compose将Elasticsearch请求/查询记录到docker实例的stdout中

elasticsearch - Elasticsearch 在 Mac 上存储数据的位置

PHP curl : Read a specific response header

php - 将 cURL 命令行翻译成 PHP cURL