string - 我们如何将文档插入到 Elastic Search 中?‽‽?

标签 string elasticsearch cmd

我正在关注教程:
https://www.elastic.co/guide/en/elasticsearch/reference/current/getting-started-index.html

当我复制插入文档的命令,然后将其粘贴到 windows cmd 中时,我们会看到以下内容:

C:\Users\ymorenoj\Downloads\elasticsearch-7.5.2-windows-x86_64\elasticsearch-7.5.2\bin>curl -X PUT "localhost:9200/customer/_doc/1?pretty" -H 'Content-Type: application/json' -d'
{
  "error" : "Content-Type header [application/x-www-form-urlencoded] is not supported",
  "status" : 406
}
curl: (6) Could not resolve host: application

C:\Users\ymorenoj\Downloads\elasticsearch-7.5.2-windows-x86_64\elasticsearch-7.5.2\bin>{
"{" no se reconoce como un comando interno o externo,
programa o archivo por lotes ejecutable.

C:\Users\ymorenoj\Downloads\elasticsearch-7.5.2-windows-x86_64\elasticsearch-7.5.2\bin>  "name": "John Doe"
""name":" no se reconoce como un comando interno o externo,
programa o archivo por lotes ejecutable.

C:\Users\ymorenoj\Downloads\elasticsearch-7.5.2-windows-x86_64\elasticsearch-7.5.2\bin>}
"}" no se reconoce como un comando interno o externo,
programa o archivo por lotes ejecutable.

C:\Users\ymorenoj\Downloads\elasticsearch-7.5.2-windows-x86_64\elasticsearch-7.5.2\bin>'
"'" no se reconoce como un comando interno o externo,
programa o archivo por lotes ejecutable.

因此,我编辑了命令以将其放入一行中:
curl -XPUT "localhost:9200/customer/_doc/1?pretty" -H 'Content-Type: application/json' -d '{"name":"John Doe"}'

当我们执行它时, cmd 输出:
C:\Users\ymorenoj\Downloads\elasticsearch-7.5.2-windows-x86_64\elasticsearch-7.5.2\bin>curl -XPUT "localhost:9200/customer/_doc/1?pretty" -H 'Content-Type: application/json' -d '{"name":"John Doe"}'
{
  "error" : "Content-Type header [application/x-www-form-urlencoded] is not supported",
  "status" : 406
}
curl: (6) Could not resolve host: application

我读:

Content-Type header [application/x-www-form-urlencoded] is not supported on Elasticsearch

我检查了我已经写了:-H 'Content-Type: application/json'
除了我读到:

Content-Type header [application/x-www-form-urlencoded] is not supported

我试图在 localhost 和 content-type 周围加上双引号:
curl -XPUT "localhost:9200/customer/_doc/1?pretty" -H "Content-Type: application/json" -d '{"name":"John Doe"}'

执行后我们观察到:
C:\Users\ymorenoj\Downloads\elasticsearch-7.5.2-windows-x86_64\elasticsearch-7.5.2\bin>curl -XPUT "localhost:9200/customer/_doc/1?pretty" -H "Content-Type: application/json" -d '{"name":"John Doe"}'
{
  "error" : {
    "root_cause" : [
      {
        "type" : "not_x_content_exception",
        "reason" : "not_x_content_exception: Compressor detection can only be called on some xcontent bytes or compressed xcontent bytes"
      }
    ],
    "type" : "mapper_parsing_exception",
    "reason" : "failed to parse",
    "caused_by" : {
      "type" : "not_x_content_exception",
      "reason" : "not_x_content_exception: Compressor detection can only be called on some xcontent bytes or compressed xcontent bytes"
    }
  },
  "status" : 400
}

另外我尝试用单引号替换两个引号,然后在这里我们有我们的 cmd 跟踪:
C:\Users\ymorenoj\Downloads\elasticsearch-7.5.2-windows-x86_64\elasticsearch-7.5.2\bin>curl -XPUT 'localhost:9200/customer/_doc/1?pretty' -H 'Content-Type: application/json' -d '{"name":"John Doe"}'
curl: (6) Could not resolve host: 'localhost
curl: (6) Could not resolve host: application

另外要检查我们是否已启动并运行 Elastic Search:
C:\Users\ymorenoj\Downloads\elasticsearch-7.5.2-windows-x86_64\elasticsearch-7.5.2\bin>curl -X GET "localhost:9200/_cat/health?v&pretty"
epoch      timestamp cluster       status node.total node.data shards pri relo init unassign pending_tasks max_task_wait_time active_shards_percent
1580922144 17:02:24  elasticsearch green           2         2      2   1    0    0        0             0                  -                100.0%

怎么解决?‽‽?

最佳答案

哈哈,windows 和 curl 可能很麻烦...

在 Windows 中,此版本有效:

curl -XPUT "localhost:9200/customer/_doc/1?pretty" -H "Content-Type: application/json" -d "{""name"":""John Doe""}"

请注意 json 中的双引号。

如果您在 Windows 下工作,请尝试使用 Windows Linux 子系统 (WSL) 或 Cygwin。这会对你有很大帮助。另一种选择是安装 kibana 并使用开发工具

关于string - 我们如何将文档插入到 Elastic Search 中?‽‽?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60080740/

相关文章:

string - 同构字符串

php - 如何在 Elasticsearch 中进行多字段匹配

java - 字符串解析机制获取值

arrays - Swift Alamofire 将值赋给字符串

ElasticSearch - 创建模板以通过实体名称模式匹配实体?

elasticsearch - Beats 和 jdbc 插件有什么区别?

java - 为什么当我使用 "mvn -v"时我的电脑中有两个java路径

SQL 使用 CMD 将数据从 .sql 文件插入到表中

c++ - 使用 C++ 在 cmd 上绘图

java - 如何在java中读取循环内带有空格的字符串?