1、安装
window安装版
9200是http通讯接口,9300是程序间调用接口
2、体系结构(与mysql对比)
Elasticsearch | mysql |
索引index | 数据库db |
类型type | 表table |
档案document | 行row |
3、使用语法
先建立索引,再type,document
增索引:http://127.0.0.1:9200/index 用post方式在postman内提交
增document:http://127.0.0.1:9200/index/type 用post提交,加上请求体body
{
"title":"spring内容"
}
查询全部:http://127.0.0.1:9200/index/type/_search
按id查询:(看_id字段)
http://127.0.0.1:9200/index/type/1
(删除操作类似查询操作,改操作类似增操作)
=========更细粒度的查询===========
精准查询:
http://127.0.0.1:9200/index/type/_search?q=title:spring内容
模糊查询:
http://127.0.0.1:9200/index/type/_search?q=title:*s*
4、elasticSearch插件使用
head插件
ik分词器
head插件:
步骤 1:
下载 head 插件: https://github.com/mobz/elasticsearch-head
步骤 2:
解压到任意目录, 但是要和 elasticsearch 的安装目录区别开。
步骤3(可选):
安装NodeJS软件,把nodejs的安装目录配置到PATH环境变量中,在cmd可以输入npm命令
步骤 4(可选):
安装 node js ,安装 cnpm
npm install -g cnpm --registry=https://registry.npm.taobao.org
// 可以不装cnpm
(国内安装慢,修改配置 npm config set registry https://registry.npm.taobao.org)
步骤 5:
将 grunt 安装为全局命令 。 Grunt 是基于 Node.js 的项目构建工具。 它可以自动运行你所设定的任务
npm install -g grunt-cli
(国内安装慢,修改配置 npm config set registry https://registry.npm.taobao.org)
步骤 6: 安装依赖
先进入head插件目录
npm install
步骤 7:
进入 head 目录启动 head, 在命令提示符下输入命令
grunt server
步骤 8:
打开浏览器, 输入 http://localhost:9100
ik分词器使用
下载地址: https://github.com/medcl/elasticsearch-analysis-ik/releases
(1) 先将其解压, 将解压后的 elasticsearch 文件夹重命名文件夹为 ik
(2) 将 ik 文件夹拷贝到 elasticsearch/plugins 目录下。
(3) 重新启动es, 即可加载 IK 分词器
5、简单查询
dao继承elasticSearchRepository<类,id的类型>
可以使用里面的增删改查方法,这里查询需要注意一下,使用方法: dao.方法名
6、自定义查询
用springdata里的nativeSearchQueryBuilder 类