string - 我们如何在 Elastic Search 中插入文档?‽‽?
问题描述
我正在关注教程: 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
我读:
Elasticsearch 不支持 Content-Type 标头 [application/x-www-form-urlencoded]
我检查了我是否已经写过:-H 'Content-Type: application/json'
除了我读到:
不支持 Content-Type 标头 [application/x-www-form-urlencoded]
我试图在 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 并使用开发工具
推荐阅读
- android - Meteor APK 构建被帐户破坏-谷歌
- sql - 为什么我的用户权限 SQL 代码会导致创建用户架构?
- shell - shell 中 ((a++)) 的返回值
- openstack - 安装 DevStack 的依赖问题
- javascript - 承诺和异步操作的问题
- c - 为什么使用wake_up_all() 而不是wake_up_interruptible()?
- ffmpeg - ffprobe/ffmpeg 报告通过标准输入提供文件时的不同视频持续时间
- java - 如何为开源服务器端(java)文件开发服务器端(jsp)代码?
- python - 如何获取正在使用的 ipython 笔记本的文件路径?(相当于 __file__)
- xcode - 如何让我的 SwiftUI UIViewRepresentable 在预览中尊重intrinsicContentSize?