elasticsearch加载默认数据的问题
最近学习使用es+kibana,由于源码一直在更新,但说明文档没有跟上步伐,使用官网示例数据时遇到了无法加载的问题。网上查找问题时竟然看到了某道友以高额积分“贩卖”示例数据,很是无语。一下总结所遇问题及解决办法,解决方式是在官网说明的基础上略作调整。( Windows环境)
1、指令格式问题
输入cmd指令前,先在文本编辑器中编辑为单行模式,例如Sublime Text中,Edit->Line->Join Lines。然后同时将引号’改为”,将”改为\”。
2、es更新说明
有时间的道友可以去看一下es的更新说明,这里引用官网的一个说明,7.4版本后不再支持指定索引类型,如默认索引类型_doc,由此产生报错“Root mapping definition has unsupported parameters”,将这一键删除即可,也可以通过配置“include_type_name: true”来解决,但官方更新文档不建议这么做,因为es8以后不提供。
curl -H "Content-Type: application/json" -XPUT http://127.0.0.1:9200/shakespeare -d "{\"mappings\": {\"properties\": {\"speaker\": {\"type\": \"keyword\"}, \"play_name\": {\"type\": \"keyword\"}, \"line_id\": {\"type\": \"integer\"}, \"speech_number\": {\"type\": \"integer\"} } } } ";
以上将"doc"键删掉。
3、使用curl的问题
安装windows下choco包管理工具(类似yum的工具,非必要但建议安装),安装windows下curl工具(ftp的命令行工具)。出现“Content-Type header [application/x-www-form-urlencoded] is not supported”问题,在curl时指定header头即可解决,即curl -H “Content-Type: application/json”。
curl -H "Content-Type: application/json" -XPOST "localhost:9200/bank/account/_bulk?pretty" --data-binary @accounts.json
以上加载数据时,指定header头。