开源ElasticSearch
- 目前全文搜索引擎的首选。
- 可以快速的存储、搜索和分析海量数据。
- 是一个分布式搜索服务,提供Restful API,底层基于Lucene,采用多shard(分片)的方式保证数据安全,并且提供自动resharding的功能,github等大型的站点也是采用了ElasticSearch作为其搜索服务.
三 ElasticSearch安装
[root@bogon ~]# systemctl enable docker
[root@bogon ~]# docker pull docker.elastic.co/elasticsearch/elasticsearch:6.3.2
[root@bogon ~]# docker run -d --name es -p 9200:9200 -p 9300:9300 -e "discovery.type=single-node" docker.elastic.co/elasticsearch/elasticsearch:6.3.2
资料地址
https://www.elastic.co/guide/cn/elasticsearch/guide/current/index.html
四简单测试
curl -X PUT "localhost:9200/megacorp/employee/1" -H 'Content-Type: application/json' -d'
{
"first_name" : "John",
"last_name" : "Smith",
"age" : 25,
"about" : "I love to go rock climbing",
"interests": [ "sports", "music" ]
}PUT /megacorp/employee/2 { "first_name" : "Jane", "last_name" : "Smith", "age" : 32, "about" : "I like to collect rock albums", "interests": [ "music" ] }
PUT /megacorp/employee/3 { "first_name" : "Douglas", "last_name" : "Fir", "age" : 35, "about": "I like to build cabinets", "interests": [ "forestry" ] }
新增
检索文档
GET
:检索文档,
DELETE
:删除文档,
HEAD
:检查文档是否存在。
PUT
:更新已存在的文档
GET /megacorp/employee/2
轻量搜索
搜索所有雇员
GET /megacorp/employee/_search
尝试下搜索姓氏为 ``Smith`` 的雇员
GET /megacorp/employee/_search?q=last_name:Smith
使用查询表达式搜索
GET /megacorp/employee/_search { "query" : { "match" : { "last_name" : "Smith" } } }
具体的去官方文档那边操作
springboot+ElasticSearch
jest操作
查询
全文搜索
核心配置
SpringData ElasticSearch
核心配置
启动失败
SpringData ElasticSearch【ES版本有可能不合适】
版本适配说明:https://github.com/spring-projects/spring-data-elasticsearch
如果版本不适配:2.4.6
1)、升级SpringBoot版本
2)、安装对应版本的ES
设置elasticsearch为2.4
[root@bogon ~]# docker pull elasticsearch:2.4.4
[root@bogon ~]# docker run -d --name es2 -p 9201:9200 -p 9301:9300 -e "discovery.type=single-node" docker.io/elasticsearch:2.4.4
修改代码配置
启动项目
测试
新增
查询
代码位置
https://gitee.com/DanShenGuiZu/GongKaiZiYuan.git
springboot-03-elastic