elasticsearch入门

1、安装

window安装版

9200是http通讯接口,9300是程序间调用接口

2、体系结构(与mysql对比)

Elasticsearchmysql
索引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 类

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值