springboot+ElasticSearch

开源ElasticSearch

  1. 目前全文搜索引擎的首选。
  2. 可以快速的存储、搜索和分析海量数据。
  3. 是一个分布式搜索服务,提供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

http://192.168.1.103:9200/ 

资料地址

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

 

 

 

 

 

 

 

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值