es
2020-02-06 本文已影响0人
我是啵啵
简介:
分布式 restful 风格
各种数据类型
收索快 实时查询
水平拓展
术语
索引 类型 文档 字段
数据库 表 行 列
后来 类型淡化 用索引 标识 表
版本 用6.4.3 用7 和spring boot不兼容
config
elasticsearch.yarm 是他的配置文件
配置文件
集群名字
cluster.name: nowcoder
存数据的地方
path.data: d:\work\data\elasticsearch-6.4.3\data
path.logs: d:\work\data\elasticsearch-6.4.3\logs
- 配置一个环境变量
bin 目录 -
装一个中文分词的插件 英文不用 英文有空格
插件在github上
版本对应
image.png
下载
image.png
下6.4.3
.zip
D:\es\elasticsearch-6.4.3\plugins 在这个目录下新建ik 文件夹
将插件解压到这里

字典配置 还能自定义字典 然后配置到
IKAnalyzer.cfg.config

还能配置拓展停止词
postman
安装postman
启动
bin 目录下
cmd 命令
查看健康状态
curl -X GET "localhost:9200/_cat/health?v"
节点
curl -X GET "localhost:9200/_cat/nodes?v"
有集群 节点 状态和分片
有堆内存 内存 cpu 占用量

建立索引 删除索引 put 改为 delete
curl -X PUT "localhost:9200/test"

postman 发送

发送请求
body
raw json
test 是索引 _doc 是类型占位
localhost:9200/test/_doc/1

结果

查询出来

删除

localhost:9200/test/_search
get
搜索
test 中的全部
localhost:9200/test/_search?q=title:互联网学习
分词收索条件

还能通过请求体构造条件

整合spring
导包
配yml
spring.data.elasticsearch.cluster-name=nowcoder
spring.data.elasticsearch.cluster-nodes=127.0.0.1:9300
用9300 端口 tcp 的
9200是http的 解决冲突 netty 和redis 的netty 冲突
在启动类上
@PostConstruct
public void init() {
// 解决netty启动冲突问题
// see Netty4Utils.setAvailableProcessors()
System.setProperty("es.set.netty.runtime.available.processors", "false");
}
实体类上加上注解就能存到es 里
@Document(indexName = "discusspost", type = "_doc", shards = 6, replicas = 3)
public class DiscussPost {
@Id
private int id;
@Field(type = FieldType.Integer)
private int userId;
// 互联网校招
@Field(type = FieldType.Text, analyzer = "ik_max_word", searchAnalyzer = "ik_smart")
private String title;
@Field(type = FieldType.Text, analyzer = "ik_max_word", searchAnalyzer = "ik_smart")
private String content;
@Field(type = FieldType.Integer)
private int type;
@Field(type = FieldType.Integer)
private int status;
@Field(type = FieldType.Date)
private Date createTime;
@Field(type = FieldType.Integer)
private int commentCount;
@Field(type = FieldType.Double)
private double score;