Elasticsearch的使用以及一些坑

1.安装

环境:阿里云centOS7、elasticsearch-6.2.3
下载:https://www.elastic.co/downloads/past-releases
上传到服务器并解压。解压命令:tar -zxvf elasticsearch-6.2.3.tar.gz
启动:./elasticsearch-6.2.3/bin/elasticsearch
(1)
启动报错:Caused by: java.lang.RuntimeException: can not run elasticsearch as root
解决:es设置了保护机制,禁止使用root账号进行操作。新建一个用户并且使用这个用户启动即可解决

 adduser es
 passwd es

建好用户后别忘记给新用户赋权限:chown es /mnt/elasticsearch -R
否则会报错:Exception in thread “main” java.nio.file.AccessDeniedException: /mnt/elasticsearch/config/jvm

2.使用

1.开启远程访问
修改elasticsearch.yml文件

network.host: 0.0.0.0
http.port: 9200

注意,要开启服务器的9200端口
2.创建索引:curl -XPUT '[服务器IP]:9200/[索引名]?[返回json格式:pretty 美化的格式]'
eg:curl -XPUT ‘localhost:9200/chose?pretty’
3.插入数据:curl -XPUT '[服务器IP]:9200/[索引名]/[类型名]/[指定id]' -d '{"key":"value","key":"value",...}'
eg:curl -XPUT 'http://localhost:9200/shose/product/1' -H 'Content-Type: application/json' -d '{"name":"John","id":"se3uierca7"}'
4.查询数据:curl -XGET [服务器IP]:9200/[索引名]/[类型名]/_search?pretty -H 'Content-Type:application/json' -d '{"key":"value","key":"value",...}'
eg:curl -XGET http://localhost:9200/chose/product/_search?pretty -H 'Content-Type:application/json' -d '{"query" : {"match" : {"name" : "john"}}}'
5.集成到Springboot中的话,需要Springboot2.2.X以上的版本才支持es的7.2版本。
待补充;

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值