Elasticsearch 阮一峰教程 实验
发布时间
阅读量:
阅读量
刚开始学习Elasticsearch的基础知识时,请参考阮一峰老师的教程《_elasticsearch基础入门》,并完成实验流程以巩固所学内容。
实验环境:
linux-16.04
java-oracle-jdk8
Elasticsearch-6.3.0
在中文分词设置阶段:
安装IK中文分词插件:
./bin/elasticsearch-plugin install https://github.com/medcl/elasticsearch-analysis-ik/releases/download/v6.3.0/elasticsearch-analysis-ik-6.3.0.zip
出现:
Error on thread java.net.NoRouteToHostException: 无法连接到指定主机 (Host unreachable)
该错误表明在公司网络代理环境中运行会导致无法访问外部资源;安装过程会首先下载相关文件以完成配置。
解决方案:
本地安装。
./bin/elasticsearch-plugin install file:~/Downloads/elasticsearch-analysis-ik-6.3.0.zip
新建带分词的index时运行:
$ curl -X PUT 'localhost:9200/accounts' -d '
{
"mappings": {
"person": {
"properties": {
"user": {
"type": "text",
"analyzer": "ik_max_word",
"search_analyzer": "ik_max_word"
},
"title": {
"type": "text",
"analyzer": "ik_max_word",
"search_analyzer": "ik_max_word"
},
"desc": {
"type": "text",
"analyzer": "ik_max_word",
"search_analyzer": "ik_max_word"
}
}
}
}
}'
报错:
错误信息指出指定字段[application/x-www-form-urlencoded]不支持
可以在建立index时,加入:-H 'Content-Type: application/json'
如
$ curl -X PUT 'localhost:9200/accounts' -H 'Content-Type: application/json' -d '
{
"mappings": {
"person": {
"properties": {
"user": {
"type": "text",
"analyzer": "ik_max_word",
"search_analyzer": "ik_max_word"
},
"title": {
"type": "text",
"analyzer": "ik_max_word",
"search_analyzer": "ik_max_word"
},
"desc": {
"type": "text",
"analyzer": "ik_max_word",
"search_analyzer": "ik_max_word"
}
}
}
}
}'
类似的,插入记录
$ curl -X PUT 'localhost:9200/accounts/person/1' -d '
{
"user": "张三",
"title": "工程师",
"desc": "数据库管理"
}'
转为
$ curl -X PUT 'localhost:9200/accounts/person/1' -H 'Content-Type: application/json' -d '
{
"user": "张三",
"title": "工程师",
"desc": "数据库管理"
}'
全部评论 (0)
还没有任何评论哟~
