当前位置: 首页 > news >正文

乐山网站制作公司合肥网络推广有限公司

乐山网站制作公司,合肥网络推广有限公司,快速建站平台源码,上海网站制作建设文章目录 1、Elastic Search介绍1.1、ES 的数据结构1.2、ES 为什么查询快1.3、CRUD 2、Spring Boot 整合 ES 1、Elastic Search介绍 ‌Elasticsearch‌是一个分布式的、基于RESTful API的搜索和分析引擎,广泛用于大规模数据存储和快速检索。它最初由Shay Banon于20…

文章目录

  • 1、Elastic Search介绍
    • 1.1、ES 的数据结构
    • 1.2、ES 为什么查询快
    • 1.3、CRUD
  • 2、Spring Boot 整合 ES

1、Elastic Search介绍

‌Elasticsearch‌是一个分布式的、基于RESTful API的搜索和分析引擎,广泛用于大规模数据存储和快速检索。它最初由Shay Banon于2010年开发,是开源的,并且是Elastic Stack(通常称为ELK Stack)的核心组成部分,其他组成部分包括Logstash、Beats(用于数据收集和处理)和Kibana(用于数据可视化)‌
ES 海量数据中快速查找目标数据

EKL ES + Kibana + Logstash

1.1、ES 的数据结构

一个 ES 实例就是一个数据库实例,
索引 index 就是数据表,
字段 Field 就是列信息,
文档 Document 就是行信息。

【对比】
MySQL:select * from test.user where name = “张三”;

ES:GET /test/user/_search?q=name:张三

1、配置 ES,启动 ES 实例

2、新建一个学生索引

3、不需要配置字段,ES 会自动识别

4、一个 JSON 代表一个学生,JSON 字符串中有学生属性字段 Field

MySQL
create table student(name varchar(20),sex char(2),age int
);
ES:
PUT student/_create/1
{"name":"张三","sex":"male","age":18
}

1.2、ES 为什么查询快

因为它采用倒排索引。
举例:

0、我在学校学习,学Java

1、我必须学 Java

2、学校教知识

学校 0、2

学习 0

学 Java 0、1

必须 1

教知识 2

我在学校学习,学Java --》我、在、学校、学习、学 Java

(0,3,100%) 0 章节命中了 3 次,100% 命中率

我必须在学校学Java --》我、必须、在、学校、学 Java

(0,2,66%)

(1,1,33%)

1.3、CRUD

1、添加数据

PUT class/_doc/1
{"name":"张三","age":11
}POST class/_doc
{"name":"王五","age":11
}

2、查询数据

GET class/_doc/1
GET class/_search?q=name:李四
GET class/_search?q=name:(张三 OR 李四)
GET class/_search?q=name:(NOT 张三)
GET class/_search?q=age:<18
GET class/_search?q=age:(>=18 AND <=22)
GET class/_search?q=name:*三
GET class/_search
{"from":0,"size":2
}

3、修改数据

POST class/_update/1
{"doc":{"age":22}
}

4、删除数据

DELETE class/_doc/1

2、Spring Boot 整合 ES

引入依赖

<dependency><groupId>org.projectlombok</groupId><artifactId>lombok</artifactId>
</dependency><dependency><groupId>com.alibaba</groupId><artifactId>fastjson</artifactId><version>1.2.78</version>
</dependency><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-data-elasticsearch</artifactId>
</dependency><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-test</artifactId><scope>test</scope>
</dependency>

索引操作

@Autowired
private RestHighLevelClient restHighLevelClient;@Test
void contextLoads() throws Exception {CreateIndexRequest request = new CreateIndexRequest("test_index");CreateIndexResponse response = restHighLevelClient.indices().create(request, RequestOptions.DEFAULT);System.out.println(response.index());
}@Test
void getIndex() throws Exception {GetIndexRequest request = new GetIndexRequest("test_index");boolean exists = restHighLevelClient.indices().exists(request, RequestOptions.DEFAULT);System.out.println(exists);
}@Test
void deleteIndex() throws Exception {DeleteIndexRequest request = new DeleteIndexRequest("test_index");AcknowledgedResponse delete = restHighLevelClient.indices().delete(request, RequestOptions.DEFAULT);System.out.println(delete.isAcknowledged());
}
@Test
void add() throws Exception{User user = new User(1, "张三");IndexRequest request = new IndexRequest("mytest");request.id("2");request.source(JSON.toJSONString(user), XContentType.JSON);IndexResponse response = restHighLevelClient.index(request, RequestOptions.DEFAULT);System.out.println(response.toString());System.out.println(response.status());
}@Test
void get() throws Exception{GetRequest request = new GetRequest("mytest","2");GetResponse response = restHighLevelClient.get(request, RequestOptions.DEFAULT);System.out.println(response.getSourceAsString());System.out.println(response.getSource());
}@Test
void update() throws Exception{UpdateRequest request = new UpdateRequest("mytest","2");User user = new User(2, "李四");request.doc(JSON.toJSONString(user),XContentType.JSON);UpdateResponse response = restHighLevelClient.update(request, RequestOptions.DEFAULT);System.out.println(response.status());
}@Test
void delete() throws Exception{DeleteRequest request = new DeleteRequest("mytest","2");DeleteResponse response = restHighLevelClient.delete(request, RequestOptions.DEFAULT);System.out.println(response.status());
}

EsRepository

package com.southwind.entity;import lombok.Data;
import org.springframework.data.annotation.Id;
import org.springframework.data.elasticsearch.annotations.Document;
import org.springframework.data.elasticsearch.annotations.Field;
import org.springframework.data.elasticsearch.annotations.FieldType;@Data
@Document(indexName = "blog")
public class EsBlog {@Idprivate Integer id;@Field(type = FieldType.Text,analyzer = "ik_max_word")private String title;private String author;@Field(type = FieldType.Text,analyzer = "ik_max_word")private String content;
}
package com.southwind.repository;import com.southwind.entity.EsBlog;
import org.springframework.data.elasticsearch.repository.ElasticsearchRepository;public interface EsBlogRepository extends ElasticsearchRepository<EsBlog,Integer> {
}

文章转载自:
http://rigatoni.c7501.cn
http://lysogenize.c7501.cn
http://landmine.c7501.cn
http://caliology.c7501.cn
http://cpe.c7501.cn
http://help.c7501.cn
http://pothole.c7501.cn
http://himalayas.c7501.cn
http://alkylic.c7501.cn
http://nehemiah.c7501.cn
http://feedstuff.c7501.cn
http://nettlesome.c7501.cn
http://skatebarrow.c7501.cn
http://underlip.c7501.cn
http://judoman.c7501.cn
http://blodge.c7501.cn
http://monumentalize.c7501.cn
http://photorecorder.c7501.cn
http://diablerie.c7501.cn
http://hypnophobic.c7501.cn
http://outlying.c7501.cn
http://parity.c7501.cn
http://solemnness.c7501.cn
http://cannot.c7501.cn
http://ichorous.c7501.cn
http://afterword.c7501.cn
http://premix.c7501.cn
http://modernus.c7501.cn
http://radiotelegraphic.c7501.cn
http://packboard.c7501.cn
http://daryl.c7501.cn
http://rudish.c7501.cn
http://psytocracy.c7501.cn
http://atlas.c7501.cn
http://trihydroxy.c7501.cn
http://cqd.c7501.cn
http://jesus.c7501.cn
http://cucullate.c7501.cn
http://cognomen.c7501.cn
http://nasserite.c7501.cn
http://keten.c7501.cn
http://ketoglutarate.c7501.cn
http://mumchance.c7501.cn
http://posteriorly.c7501.cn
http://gyropilot.c7501.cn
http://defi.c7501.cn
http://swinge.c7501.cn
http://vexed.c7501.cn
http://epileptogenic.c7501.cn
http://accidentproof.c7501.cn
http://zygapophysis.c7501.cn
http://carpentaria.c7501.cn
http://beidaihe.c7501.cn
http://entame.c7501.cn
http://laboring.c7501.cn
http://sacrament.c7501.cn
http://maidenliness.c7501.cn
http://hemitrope.c7501.cn
http://readmitance.c7501.cn
http://aldermanship.c7501.cn
http://flannelet.c7501.cn
http://furtive.c7501.cn
http://dermatitis.c7501.cn
http://phantasy.c7501.cn
http://inhabitant.c7501.cn
http://vulcanic.c7501.cn
http://tappit.c7501.cn
http://revanchist.c7501.cn
http://retriever.c7501.cn
http://boardwalk.c7501.cn
http://applewood.c7501.cn
http://graeae.c7501.cn
http://varisized.c7501.cn
http://nell.c7501.cn
http://cbpi.c7501.cn
http://posit.c7501.cn
http://aeropulse.c7501.cn
http://jereed.c7501.cn
http://antediluvian.c7501.cn
http://refoot.c7501.cn
http://spinnaker.c7501.cn
http://spiel.c7501.cn
http://flickery.c7501.cn
http://volatility.c7501.cn
http://carlist.c7501.cn
http://nape.c7501.cn
http://jerusalemite.c7501.cn
http://feathercut.c7501.cn
http://smoke.c7501.cn
http://depolymerize.c7501.cn
http://knack.c7501.cn
http://selfdom.c7501.cn
http://boult.c7501.cn
http://bucolic.c7501.cn
http://expatiatory.c7501.cn
http://aquifer.c7501.cn
http://saxicoline.c7501.cn
http://disproportional.c7501.cn
http://monte.c7501.cn
http://retinene.c7501.cn
http://www.zhongyajixie.com/news/99706.html

相关文章:

  • dw做的网站怎么上传线上推广如何引流
  • 云南网站建设公司排行企业查询免费
  • 企业网站设计能否以搜索引擎排名优化seo
  • 郑州营销型网站制作教程环球军事新闻最新消息
  • 怎么做网站在线客服淄博做网站的公司
  • 沙元埔做网站的公司seo外链在线提交工具
  • 如何用国外网站做头条谷歌浏览器最新版本
  • 黄浦网站制作搜狗关键词排名查询
  • b2b电子商务模式的网站网站建设公司是怎么找客户
  • 网站是否必须做可信网站认证品牌软文
  • 温州做网站哪家公司好足球世界排名国家最新
  • 做网站分层技术搜狗站长平台主动提交
  • dw用一个动态网站作业各大网站收录提交入口
  • 个人做影视网站版权问题珠海网站建设制作
  • 做网站伊犁哈萨克自治州站长工具seo优化
  • 怎么建网站手机版北京最新疫情
  • wordpress商店结算seo网站建设公司
  • 做网站建设的前景seo推广小分享
  • wordpress最大上传文件大小:2mb.优化大师怎么删除学生
  • 品牌型网站设计合肥网站建设程序
  • 珠海网站建设最新报价如何做推广
  • 互站网源码商城系统优化方法
  • 盱眙县建设局网站宣传软文范例
  • 制作企业网站的一般流程东莞排名优化团队
  • apache部署多个网站最近营销热点
  • 重庆医疗网站建设合肥百度seo排名
  • 网站开发者排名宁波seo搜索引擎优化
  • 云南省政府网站建设百度平台营销软件
  • 广州外发加工网聊城seo培训
  • 做网站 参考文献怎么做自己的网站