ES的安装和RestClient的操作
目录
初识elasticsearch
什么是elasticsearch
elasticsearch的发展
Lucene的优缺点
elasticsearch的优势
倒排索引
es与mysql的概念对比
文档
索引
概念对比
架构
安装es
安装kibana
安装ik分词器
分词器
安装ik分词器
ik分词器的拓展和停用词典
操作索引库
mapping属性
创建索引库
查询、删除、修改索引库
文档操作
新增查询删除文档
修改文档
方法一:全量修改
方法二:增量修改
RestClient的操作
什么是RestClient
hotel数据结构分析
索引库操作
初始化JavaRestClient
创建索引库
删除索引库
判断索引库是否存在
文档操作
初始化JavaRestClient
添加文档
查询文档
修改文档
删除文档
批量导入文档
什么是elasticsearch?
1、一个开源的分布式搜索引擎,可以用来实现搜索、日志统计、分析、系统监控等功能
什么是elastic stack (ELK) ?
2、是以elasticsearch为核心的技术栈,包括beats、Logstash、kibana、elasticsearch
什么是Lucene?
3、是Apache的开源搜索引擎类库,提供了搜索引擎的核心API
什么是文档和词条?
1、每一条数据就是一个文档
2、对文档中的内容分词,得到的词语就是词条
什么是正向索引?
1、基于文档id创建索引。查询词条时必须先找到文档,而后判断是否包含词条
什么是倒排索引?
1、对文档内容分词,对词条创建索引,并记录词条所在文档的信息。查询时先根据词条查询到文档id,而后获取到文档
文档:一条数据就是一个文档,es中是Json格式
字段:Json文档中的字段
索引:同类型文档的集合
映射:索引中文档的约束,比如字段名称、类型
elasticsearch与数据库的关系:
1、数据库负责事务类型操作
2、elasticsearch负责海量数据的搜索、分析、计算
分词器的作用是什么?
1、创建倒排索引时对文档分词
2、用户搜索时,对输入的内容分词
IK分词器有几种模式?
1、ik_smart:智能切分,粗粒度2、ik_max_word:最细切分,细粒度
IK分词器如何拓展词条?如何停用词条?
1、利用config目录的lkAnalyzer.cfg.xml文件添加拓展词典和停用词典2、在词典中添加拓展词条或者停用词条
mapping常见属性有哪些?
1、type:数据类型
2、index:是否索引3、analyzer:分词器
4、properties:子字段
type常见的有哪些?
1、字符串:text、keyword
2、数字:long、integer、short、 byte、double、float3、布尔:boolean
4、日期:date
5、对象:object
索引库操作有哪些?
1、创建索引库:PUT/索引库名
2、查询索引库:GET/索引库名
3、删除索引库:DELETE/索引库名
4、添加字段:PUT/索引库名/_mapping
文档操作有哪些?
1、创建文档:POST/索引库名/_doc/文档id { json文档}
2、查询文档:GET/索引库名/_doc/文档id
3、删除文档:DELETE/索引库名/_doc/文档id
4、修改文档:
全量修改:PUT/索引库名/_doc/文档id { json文档}
增量修改:POST/索引库名/_update/文档id { "doc":{字段}}
索引库操作的基本步骤:
1、初始化RestHighLevelClient
2、创建XxxIndexRequest。XXX是CREATE、Get、Delete
3、准备DSL ( CREATE时需要)
4、发送请求。调用RestHighLevelClient#tindices().xxx()方法,xxx是create、exists、delete
文档操作的基本步骤:
1、初始化RestHighLevelClient
2、创建XxxRequest。XXX是Index、Get、Update、Delete
3、准备参数((Index和Update时需要)
4、发送请求。调用RestHighLevelClient#t.xxx()方法,xxx是index、get、update、delete
5、解析结果(Get时需要)
初识elasticsearch
什么是elasticsearch
elasticsearch是一款非常强大的开源搜索引擎,可以帮助我们从海量数据中快速找到需要的内容。
elasticsearch结合kibana、Logstash、Beats,也就是elastic stack (ELK)。被广泛应用在日志数据分析、实时监控等领域。
elasticsearch是elastic stack的核心,负责存储、搜索、分析数据。
elasticsearch的发展
Lucene的优缺点
Lucene的优势:
1、易扩展
2、高性能(基于倒排索引)Lucene的缺点:
1、只限于Java语言开发2、学习曲线陡峭
3、不支持水平扩展
elasticsearch的优势
相比与lucene, elasticsearch具备下列优势:
1、支持分布式,可水平扩展
2、提供Restful接口,可被任何语言调用
倒排索引
elasticsearch采用倒排索引:
1、文档(document):每条数据就是一个文档2、词条(term):文档按照语义分成的词语
es与mysql的概念对比
文档
1、elasticsearch是面向文档存储的,可以是数据库中的一条商品数据,一个订单信息。
2、文档数据会被序列化为json格式后存储在elasticsearch中。
索引
索引 ( index):相同类型的文档的集合
映射(mapping):索引中文档的字段约束信息,类似表的结构约束
概念对比
MySQL | Elasticsearch | 说明 |
Table | Index | 索引(index),就是文档的集合,类似数据库的表(table) |
Row | Document | 文档(Document),就是一条条的数据,类似数据库中的行(ROW),文档都是JSON格式 |
Column | Field | 字段(Field),就是JSON文档中的字段,类似数据库中的列(Column) |
Schema | Mapping | Mapping(映射)是索引中文档的约束,例如字段类型约束。类似数据库的表结构(Schema) |
SQL | DSL | DSL是elasticsearch提供的JSON风格的请求语句,用来操作elasticsearch,实现CRUD |
架构
Mysql:擅长事务类型操作,可以确保数据的安全和一致性
Elasticsearch:擅长海量数据的搜索、分析、计算
安装es
创建网络:es-net是自己取的名字,随便取
docker network create es-net
加载镜像:使用提供的es.tar,拖到虚拟机的tmp目录下
es.tarhttps://pan.baidu.com/s/13Z74D-liQaDL0_tM-Rl7Rg?pwd=47qm运行加载命令:
docker load -i es.tar
运行docker命令:
docker run -d \
--name es \
-e "ES_JAVA_OPTS=-Xms512m -Xmx512m" \
-e "discovery.type=single-node" \
-v es-data:/usr/share/elasticsearch/data \
-v es-plugins:/usr/share/elasticsearch/plugins \
--privileged \
--network es-net \
-p 9200:9200 \
-p 9300:9300 \
elasticsearch:7.12.1
访问网页:虚拟机ip和9200端口。成功
安装kibana
加载镜像:使用提供的es.tar,拖到虚拟机的tmp目录下
kibanahttps://pan.baidu.com/s/1N3NiLRxLzX42jMxkK9ackQ?pwd=lh2y运行docker命令
docker run -d \
--name kibana \
-e ELASTICSEARCH_HOSTS=http://es:9200 \
--network=es-net \
-p 5601:5601 \
kibana:7.12.1
访问网页:虚拟机ip和5601端口。成功
点击主页的Explore on my own后,打开Dev Tools
模拟一次请求:可以看到右边的数据和端口9200的数据一模一样
安装ik分词器
分词器
es在创建倒排索引时需要对文档分词;在搜索时,需要对用户输入内容分词。但默认的分词规则对中文处理并不友好。
语法说明:
POST:请求方式
/_analyze:请求路径请求参数,json风格:analyzer:分词器类型。text:要分词的内容
我们可以看到:右边的数据分词并不友好,比如:世界本应该是一起的,它却分开了
安装ik分词器
查看es-plugins数据卷所在的位置
docker volume inspect es-plugins
把ik文件夹放到该路径:Mountpoint就是要的位置
ik文件夹https://pan.baidu.com/s/1EIkGJDvVjcGx06hDUo34Eg?pwd=dads重启es
docker restart es
测试
ik_smart:最少切分
ik_max_word:最细切分
ik_smart:从最多字开始判断是否切分,若切分,则不会再继续判断已被切分的词是否继续切分
ik_max_word:会判断每个词是否能再继续分
ik分词器的拓展和停用词典
修改一个ik分词器目录中的config目录中的lkAnalyzer.cfg.xml文件
在第一个箭头这行,添加ext.dic:这是要用来拓展词典的文件,要在lkAnalyzer.cfg.xml所在的同级目录下创建出来。
在第二个箭头这行,添加stopword.dic:这是要用来停用词典的文件,在lkAnalyzer.cfg.xml所在的同级目录已经创建好了,不需要再创建。
在ext.dic添加要拓展的词典
在stopword.dic添加要停用的词典
重启es:这次重启后,需要几十秒的时间才能访问网站,否则网站会报错
docker restart es
再次访问网站,可以看到这次测试“奥利给”并没有被分开,并且“的”字并没有出现在右边。
是因为“奥利给”被写进了ext.dic, “的”被写进了stopword.dic
操作索引库
mapping属性
mapping是对索引库中文档的约束,常见的mapping属性包括:
1、type:字段数据类型,常见的简单类型有:
1.1、字符串:text(可分词的文本)、keyword(精确值,例如:品牌、国家、ip地址)1.2、数值:long、integer、short、byte、double、float
1.3、布尔:boolean
1.4、日期:date1.5、对象:object
2、index:是否创建索引,默认为true
3、analyzer:使用哪种分词器
4、properties:该字段的子字段
创建索引库
这里创建了一个名叫heima的索引库,mappings代表它是做映射的,properties代表里面是具体的字段,type代表该字段的数据类型,analyzer代表该字段的分词器,index代表该字段是否创建索引
PUT /heima
{
"mappings": {
"properties": {
"info":{
"type": "text",
"analyzer": "ik_smart"
},
"email": {
"type": "keyword",
"index": false
},
"name": {
"type": "object",
"properties": {
"firstName": {
"type": "keyword"
},
"lastName": {
"type": "keyword"
}
}
}
}
}
}
运行该DSL语句后,右边会出现创建的索引库名字,代表创建成功
查询、删除、修改索引库
查看索引库语法
GET /索引库名称
删除索引库语法
DELETE /索引库名
索引库和mapping一旦创建无法修改,但是可以添加新的字段
PUT /索引库名称/_mapping
{
"properties": {
"新字段名": {
}
}
}
文档操作
新增查询删除文档
新增文档语法
POST /索引库名/_doc/文档id
{
"字段1": "值1",
"字段2": "值2",
"字段3": {
"子属性1": "值3",
"子属性2": "值4"
}
}
新增文档,右边的数据result为created。成功
查询文档语法
GET /索引库名/_doc/文档id
查询文档,右边会出现文档的数据。成功
删除文档语法
DELETE /索引库名/_doc/文档id
删除文档,右边数据result为deleted,成功
修改文档
方法一:全量修改
会删除旧文档,添加新文档
PUT /索引库名/_doc/文档id
{
"字段1": "值1",
"字段2": "值2"
}
当文档存在时:修改后,右边的数据result为updated。修改成功
当文档不存在时:修改变成了创建。
方法二:增量修改
修改指定的字段,注意只能写指定的字段,而不是把所有字段都写上
POST /索引库名/_update/文档id
{
"doc": {
"字段1": "值1"
}
}
修改后,右边的result为updated。修改成功
RestClient的操作
什么是RestClient
ES官方提供了各种不同语言的客户端,用来操作ES。这些客户端的本质就是组装DSL语句,通过http请求发送给ES。
下载提供的资料
hotel的demo和sqlhttps://pan.baidu.com/s/1uxl7PzshHu09PXsd9zDWbA?pwd=v8bf在本地新建一个数据库:heima,若使用其他数据库名,记得在demo里修改yml文件
hotel数据结构分析
写出数据库中该表的DSL语句,但是不要执行。我们要使用java来执行
PUT /hotel
{
"mappings": {
"properties": {
"id": {
"type": "keyword"
},
"name": {
"type": "text",
"analyzer": "ik_max_word",
"copy_to": "all"
},
"address": {
"type": "keyword",
"index": false
},
"price": {
"type": "integer"
},
"score": {
"type": "integer"
},
"brand": {
"type": "keyword",
"copy_to": "all"
},
"city": {
"type": "keyword"
},
"starName": {
"type": "keyword"
},
"business": {
"type": "keyword",
"copy_to": "all"
},
"location": {
"type": "geo_point"
},
"pic": {
"type": "keyword",
"index": false
},
"all": {
"type": "text",
"analyzer": "ik_max_word"
}
}
}
}
索引库操作
初始化JavaRestClient
在hotel.pom文件中引入es的RestHighLevelclient依赖
<!--elasticsearch--> <dependency><groupId>org.elasticsearch.client</groupId><artifactId>elasticsearch-rest-high-level-client</artifactId> </dependency>
因为SpringBoot默认的ES版本是7.6.2,所以我们需要覆盖默认的ES版本
<properties><java.version>1.8</java.version><elasticsearch.version>7.12.1</elasticsearch.version> </properties>
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd"><modelVersion>4.0.0</modelVersion><parent><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-parent</artifactId><version>2.3.10.RELEASE</version><relativePath/> <!-- lookup parent from repository --></parent><groupId>cn.itcast.demo</groupId><artifactId>hotel-demo</artifactId><version>0.0.1-SNAPSHOT</version><name>hotel-demo</name><description>Demo project for Spring Boot</description><properties><java.version>1.8</java.version><elasticsearch.version>7.12.1</elasticsearch.version></properties><dependencies><!--elasticsearch--><dependency><groupId>org.elasticsearch.client</groupId><artifactId>elasticsearch-rest-high-level-client</artifactId></dependency><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-web</artifactId></dependency><dependency><groupId>com.baomidou</groupId><artifactId>mybatis-plus-boot-starter</artifactId><version>3.4.2</version></dependency><dependency><groupId>mysql</groupId><artifactId>mysql-connector-java</artifactId><scope>runtime</scope></dependency><dependency><groupId>org.projectlombok</groupId><artifactId>lombok</artifactId><optional>true</optional></dependency><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-test</artifactId><scope>test</scope><exclusions><exclusion><groupId>org.junit.vintage</groupId><artifactId>junit-vintage-engine</artifactId></exclusion></exclusions></dependency><!--FastJson--><dependency><groupId>com.alibaba</groupId><artifactId>fastjson</artifactId><version>1.2.71</version></dependency><dependency><groupId>org.apache.commons</groupId><artifactId>commons-lang3</artifactId></dependency></dependencies><build><plugins><plugin><groupId>org.springframework.boot</groupId><artifactId>spring-boot-maven-plugin</artifactId><configuration><excludes><exclude><groupId>org.projectlombok</groupId><artifactId>lombok</artifactId></exclude></excludes></configuration></plugin></plugins></build></project>
初始化RestHighLevelClient:xxx填虚拟机ip
RestHighLevelclient client = new RestHighLevelclgent(RestClient.builder(
HttpHost.create( "http://xxx.xxx.xxx.xxx:9200")
) );
该代码我写成了
@BeforeEach void setUp() {this.client = new RestHighLevelClient(RestClient.builder(HttpHost.create("http://xxx.xxx.xxx.xxx:9200"))); }@AfterEach void tearDown() throws IOException {this.client.close(); }
package cn.itcast.hotel;import net.sf.jsqlparser.statement.create.index.CreateIndex;
import org.apache.http.HttpHost;
import org.elasticsearch.action.admin.indices.delete.DeleteIndexRequest;
import org.elasticsearch.client.RequestOptions;
import org.elasticsearch.client.RestClient;
import org.elasticsearch.client.RestHighLevelClient;
import org.elasticsearch.client.indices.CreateIndexRequest;
import org.elasticsearch.client.indices.GetIndexRequest;
import org.elasticsearch.common.xcontent.XContentType;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;import java.io.IOException;import static cn.itcast.hotel.constants.HotelConstants.MAPPING_TEMPLATE;public class HotelIndexTest {private RestHighLevelClient client;@Testvoid testInit() {System.out.println(client);}@BeforeEachvoid setUp() {this.client = new RestHighLevelClient(RestClient.builder(HttpHost.create("http://xxx.xxx.xxx.xxx:9200")));}@AfterEachvoid tearDown() throws IOException {this.client.close();}
}
创建索引库
这个MAPPING_TEMPLATE的位置是要填写DSL语句,但因为太长,我就把它写成了常量
@Test void createHotelIndex() throws IOException {//1、创建Request对象CreateIndexRequest request = new CreateIndexRequest("hotel");//2、准备请求的参数,DSL语句request.source(MAPPING_TEMPLATE, XContentType.JSON);//3、发送请求client.indices().create(request, RequestOptions.DEFAULT); }
package cn.itcast.hotel;import net.sf.jsqlparser.statement.create.index.CreateIndex;
import org.apache.http.HttpHost;
import org.elasticsearch.action.admin.indices.delete.DeleteIndexRequest;
import org.elasticsearch.client.RequestOptions;
import org.elasticsearch.client.RestClient;
import org.elasticsearch.client.RestHighLevelClient;
import org.elasticsearch.client.indices.CreateIndexRequest;
import org.elasticsearch.client.indices.GetIndexRequest;
import org.elasticsearch.common.xcontent.XContentType;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;import java.io.IOException;import static cn.itcast.hotel.constants.HotelConstants.MAPPING_TEMPLATE;public class HotelIndexTest {private RestHighLevelClient client;@Testvoid testInit() {System.out.println(client);}@Testvoid createHotelIndex() throws IOException {//1、创建Request对象CreateIndexRequest request = new CreateIndexRequest("hotel");//2、准备请求的参数,DSL语句request.source(MAPPING_TEMPLATE, XContentType.JSON);//3、发送请求client.indices().create(request, RequestOptions.DEFAULT);}@BeforeEachvoid setUp() {this.client = new RestHighLevelClient(RestClient.builder(HttpHost.create("http://xxx.xxx.xxx.xxx:9200")));}@AfterEachvoid tearDown() throws IOException {this.client.close();}
}
public static final String MAPPING_TEMPLATE = "";
package cn.itcast.hotel.constants;public class HotelConstants {public static final String MAPPING_TEMPLATE = "{\n" +" \"mappings\": {\n" +" \"properties\": {\n" +" \"id\": {\n" +" \"type\": \"keyword\"\n" +" },\n" +" \"name\": {\n" +" \"type\": \"text\",\n" +" \"analyzer\": \"ik_max_word\",\n" +" \"copy_to\": \"all\"\n" +" },\n" +" \"address\": {\n" +" \"type\": \"keyword\",\n" +" \"index\": false\n" +" },\n" +" \"price\": {\n" +" \"type\": \"integer\"\n" +" },\n" +" \"score\": {\n" +" \"type\": \"integer\"\n" +" },\n" +" \"brand\": {\n" +" \"type\": \"keyword\",\n" +" \"copy_to\": \"all\"\n" +" },\n" +" \"city\": {\n" +" \"type\": \"keyword\"\n" +" },\n" +" \"starName\": {\n" +" \"type\": \"keyword\"\n" +" },\n" +" \"business\": {\n" +" \"type\": \"keyword\",\n" +" \"copy_to\": \"all\"\n" +" },\n" +" \"location\": {\n" +" \"type\": \"geo_point\"\n" +" },\n" +" \"pic\": {\n" +" \"type\": \"keyword\",\n" +" \"index\": false\n" +" },\n" +" \"all\": {\n" +" \"type\": \"text\",\n" +" \"analyzer\": \"ik_max_word\"\n" +" }\n" +" }\n" +" }\n" +"}";
}
运行测试代码,可以看到控制台运行成功。
删除索引库
@Test void testDeleteHotelIndex() throws IOException {//1、创建Request对象DeleteIndexRequest request = new DeleteIndexRequest("hotel");//2、发送请求client.indices().delete(request, RequestOptions.DEFAULT); }
package cn.itcast.hotel;import net.sf.jsqlparser.statement.create.index.CreateIndex;
import org.apache.http.HttpHost;
import org.elasticsearch.action.admin.indices.delete.DeleteIndexRequest;
import org.elasticsearch.client.RequestOptions;
import org.elasticsearch.client.RestClient;
import org.elasticsearch.client.RestHighLevelClient;
import org.elasticsearch.client.indices.CreateIndexRequest;
import org.elasticsearch.client.indices.GetIndexRequest;
import org.elasticsearch.common.xcontent.XContentType;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;import java.io.IOException;import static cn.itcast.hotel.constants.HotelConstants.MAPPING_TEMPLATE;public class HotelIndexTest {private RestHighLevelClient client;@Testvoid testInit() {System.out.println(client);}@Testvoid createHotelIndex() throws IOException {//1、创建Request对象CreateIndexRequest request = new CreateIndexRequest("hotel");//2、准备请求的参数,DSL语句request.source(MAPPING_TEMPLATE, XContentType.JSON);//3、发送请求client.indices().create(request, RequestOptions.DEFAULT);}@Testvoid testDeleteHotelIndex() throws IOException {//1、创建Request对象DeleteIndexRequest request = new DeleteIndexRequest("hotel");//2、发送请求client.indices().delete(request, RequestOptions.DEFAULT);}@BeforeEachvoid setUp() {this.client = new RestHighLevelClient(RestClient.builder(HttpHost.create("http://xxx.xxx.xxx.xxx:9200")));}@AfterEachvoid tearDown() throws IOException {this.client.close();}
}
点击该测试,控制台运行成功。
判断索引库是否存在
@Test void testExistsHotelIndex() throws IOException {//1、创建Request对象GetIndexRequest request = new GetIndexRequest("hotel");//2、发送请求boolean exists = client.indices().exists(request, RequestOptions.DEFAULT);//3、输出System.err.println(exists ? "索引库存在" : "索引库不存在"); }
package cn.itcast.hotel;import net.sf.jsqlparser.statement.create.index.CreateIndex;
import org.apache.http.HttpHost;
import org.elasticsearch.action.admin.indices.delete.DeleteIndexRequest;
import org.elasticsearch.client.RequestOptions;
import org.elasticsearch.client.RestClient;
import org.elasticsearch.client.RestHighLevelClient;
import org.elasticsearch.client.indices.CreateIndexRequest;
import org.elasticsearch.client.indices.GetIndexRequest;
import org.elasticsearch.common.xcontent.XContentType;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;import java.io.IOException;import static cn.itcast.hotel.constants.HotelConstants.MAPPING_TEMPLATE;public class HotelIndexTest {private RestHighLevelClient client;@Testvoid testInit() {System.out.println(client);}@Testvoid createHotelIndex() throws IOException {//1、创建Request对象CreateIndexRequest request = new CreateIndexRequest("hotel");//2、准备请求的参数,DSL语句request.source(MAPPING_TEMPLATE, XContentType.JSON);//3、发送请求client.indices().create(request, RequestOptions.DEFAULT);}@Testvoid testDeleteHotelIndex() throws IOException {//1、创建Request对象DeleteIndexRequest request = new DeleteIndexRequest("hotel");//2、发送请求client.indices().delete(request, RequestOptions.DEFAULT);}@Testvoid testExistsHotelIndex() throws IOException {//1、创建Request对象GetIndexRequest request = new GetIndexRequest("hotel");//2、发送请求boolean exists = client.indices().exists(request, RequestOptions.DEFAULT);//3、输出System.err.println(exists ? "索引库存在" : "索引库不存在");}@BeforeEachvoid setUp() {this.client = new RestHighLevelClient(RestClient.builder(HttpHost.create("http://xxx.xxx.xxx.xxx:9200")));}@AfterEachvoid tearDown() throws IOException {this.client.close();}
}
运行该测试,控制台运行成功,并且打印了“索引库不存在”,因为刚刚删除了索引库
文档操作
初始化JavaRestClient
xxx写虚拟机ip
@BeforeEachvoid setUp() {this.client = new RestHighLevelClient(RestClient.builder(HttpHost.create("http://xxx.xxx.xxx.xxx:9200")));}@AfterEachvoid tearDown() throws IOException {this.client.close();}
@SpringBootTest
public class HotelDocumentTest {@Autowiredprivate IHotelService hotelService;private RestHighLevelClient client;@BeforeEachvoid setUp() {this.client = new RestHighLevelClient(RestClient.builder(HttpHost.create("http://xxx.xxx.xxx.xxx:9200")));}@AfterEachvoid tearDown() throws IOException {this.client.close();}
}
添加文档
@Test void testAddDocument() throws IOException {//根据id查询酒店数据Hotel hotel = hotelService.getById(61083L);//转换成文档类型HotelDoc hotelDoc = new HotelDoc(hotel);//1、准备Request对象IndexRequest request = new IndexRequest("hotel").id(hotel.getId().toString());//2、准备json文档request.source("{\"name"\:\"Jack\",\"age\":21}",XContentType.JSON);//3、发送请求client.index(request,RequestOptions.DEFAULT); }
我这里的第二步用的是实体类转JSON的方式
package cn.itcast.hotel;import cn.itcast.hotel.pojo.Hotel;
import cn.itcast.hotel.pojo.HotelDoc;
import cn.itcast.hotel.service.IHotelService;
import com.alibaba.fastjson.JSON;
import org.apache.http.HttpHost;
import org.elasticsearch.action.admin.indices.delete.DeleteIndexRequest;
import org.elasticsearch.action.bulk.BulkRequest;
import org.elasticsearch.action.delete.DeleteRequest;
import org.elasticsearch.action.get.GetRequest;
import org.elasticsearch.action.get.GetResponse;
import org.elasticsearch.action.index.IndexRequest;
import org.elasticsearch.action.update.UpdateRequest;
import org.elasticsearch.client.RequestOptions;
import org.elasticsearch.client.RestClient;
import org.elasticsearch.client.RestHighLevelClient;
import org.elasticsearch.client.indices.CreateIndexRequest;
import org.elasticsearch.client.indices.GetIndexRequest;
import org.elasticsearch.common.xcontent.XContentType;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;import java.io.IOException;
import java.util.List;import static cn.itcast.hotel.constants.HotelConstants.MAPPING_TEMPLATE;@SpringBootTest
public class HotelDocumentTest {@Autowiredprivate IHotelService hotelService;private RestHighLevelClient client;@Testvoid testAddDocument() throws IOException {//根据id查询酒店数据Hotel hotel = hotelService.getById(61083L);//转换成文档类型HotelDoc hotelDoc = new HotelDoc(hotel);//1、准备Request对象IndexRequest request = new IndexRequest("hotel").id(hotel.getId().toString());//2、准备json文档request.source(JSON.toJSONString(hotelDoc),XContentType.JSON);//3、发送请求client.index(request,RequestOptions.DEFAULT);}@BeforeEachvoid setUp() {this.client = new RestHighLevelClient(RestClient.builder(HttpHost.create("http://xxx.xxx.xxx.xxx:9200")));}@AfterEachvoid tearDown() throws IOException {this.client.close();}
}
实体类
package cn.itcast.hotel.pojo;import lombok.Data;
import lombok.NoArgsConstructor;@Data
@NoArgsConstructor
public class HotelDoc {private Long id;private String name;private String address;private Integer price;private Integer score;private String brand;private String city;private String starName;private String business;private String location;private String pic;public HotelDoc(Hotel hotel) {this.id = hotel.getId();this.name = hotel.getName();this.address = hotel.getAddress();this.price = hotel.getPrice();this.score = hotel.getScore();this.brand = hotel.getBrand();this.city = hotel.getCity();this.starName = hotel.getStarName();this.business = hotel.getBusiness();this.location = hotel.getLatitude() + ", " + hotel.getLongitude();this.pic = hotel.getPic();}
}
运行该测试,控制台运行成功
查询文档
@Test void testGetDocumentById() throws IOException {//1、准备RequestGetRequest request = new GetRequest("hotel", "61083");//2、发送请求,得到响应GetResponse response = client.get(request, RequestOptions.DEFAULT);//3、解析响应结果String json = response.getSourceAsString();//反序列化HotelDoc hotelDoc = JSON.parseObject(json,HotelDoc.class);System.out.println(hotelDoc); }
package cn.itcast.hotel;import cn.itcast.hotel.pojo.Hotel;
import cn.itcast.hotel.pojo.HotelDoc;
import cn.itcast.hotel.service.IHotelService;
import com.alibaba.fastjson.JSON;
import org.apache.http.HttpHost;
import org.elasticsearch.action.admin.indices.delete.DeleteIndexRequest;
import org.elasticsearch.action.bulk.BulkRequest;
import org.elasticsearch.action.delete.DeleteRequest;
import org.elasticsearch.action.get.GetRequest;
import org.elasticsearch.action.get.GetResponse;
import org.elasticsearch.action.index.IndexRequest;
import org.elasticsearch.action.update.UpdateRequest;
import org.elasticsearch.client.RequestOptions;
import org.elasticsearch.client.RestClient;
import org.elasticsearch.client.RestHighLevelClient;
import org.elasticsearch.client.indices.CreateIndexRequest;
import org.elasticsearch.client.indices.GetIndexRequest;
import org.elasticsearch.common.xcontent.XContentType;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;import java.io.IOException;
import java.util.List;import static cn.itcast.hotel.constants.HotelConstants.MAPPING_TEMPLATE;@SpringBootTest
public class HotelDocumentTest {@Autowiredprivate IHotelService hotelService;private RestHighLevelClient client;@Testvoid testAddDocument() throws IOException {//根据id查询酒店数据Hotel hotel = hotelService.getById(61083L);//转换成文档类型HotelDoc hotelDoc = new HotelDoc(hotel);//1、准备Request对象IndexRequest request = new IndexRequest("hotel").id(hotel.getId().toString());//2、准备json文档request.source(JSON.toJSONString(hotelDoc),XContentType.JSON);//3、发送请求client.index(request,RequestOptions.DEFAULT);}@Testvoid testGetDocumentById() throws IOException {//1、准备RequestGetRequest request = new GetRequest("hotel", "61083");//2、发送请求,得到响应GetResponse response = client.get(request, RequestOptions.DEFAULT);//3、解析响应结果String json = response.getSourceAsString();//反序列化HotelDoc hotelDoc = JSON.parseObject(json,HotelDoc.class);System.out.println(hotelDoc);}@BeforeEachvoid setUp() {this.client = new RestHighLevelClient(RestClient.builder(HttpHost.create("http://xxx.xxx.xxx.xxx:9200")));}@AfterEachvoid tearDown() throws IOException {this.client.close();}
}
运行该测试,控制台运行成功,并且把数据打印了出来
修改文档
这里我只演示局部更新
@Test void testUpdateDocument() throws IOException {//1、准备RequestUpdateRequest request = new UpdateRequest("hotel", "61083");//2、准备请求参数request.doc("price", "952","starName", "四钻");//3、发送请求client.update(request,RequestOptions.DEFAULT); }
package cn.itcast.hotel;import cn.itcast.hotel.pojo.Hotel;
import cn.itcast.hotel.pojo.HotelDoc;
import cn.itcast.hotel.service.IHotelService;
import com.alibaba.fastjson.JSON;
import org.apache.http.HttpHost;
import org.elasticsearch.action.admin.indices.delete.DeleteIndexRequest;
import org.elasticsearch.action.bulk.BulkRequest;
import org.elasticsearch.action.delete.DeleteRequest;
import org.elasticsearch.action.get.GetRequest;
import org.elasticsearch.action.get.GetResponse;
import org.elasticsearch.action.index.IndexRequest;
import org.elasticsearch.action.update.UpdateRequest;
import org.elasticsearch.client.RequestOptions;
import org.elasticsearch.client.RestClient;
import org.elasticsearch.client.RestHighLevelClient;
import org.elasticsearch.client.indices.CreateIndexRequest;
import org.elasticsearch.client.indices.GetIndexRequest;
import org.elasticsearch.common.xcontent.XContentType;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;import java.io.IOException;
import java.util.List;import static cn.itcast.hotel.constants.HotelConstants.MAPPING_TEMPLATE;@SpringBootTest
public class HotelDocumentTest {@Autowiredprivate IHotelService hotelService;private RestHighLevelClient client;@Testvoid testAddDocument() throws IOException {//根据id查询酒店数据Hotel hotel = hotelService.getById(61083L);//转换成文档类型HotelDoc hotelDoc = new HotelDoc(hotel);//1、准备Request对象IndexRequest request = new IndexRequest("hotel").id(hotel.getId().toString());//2、准备json文档request.source(JSON.toJSONString(hotelDoc),XContentType.JSON);//3、发送请求client.index(request,RequestOptions.DEFAULT);}@Testvoid testGetDocumentById() throws IOException {//1、准备RequestGetRequest request = new GetRequest("hotel", "61083");//2、发送请求,得到响应GetResponse response = client.get(request, RequestOptions.DEFAULT);//3、解析响应结果String json = response.getSourceAsString();//反序列化HotelDoc hotelDoc = JSON.parseObject(json,HotelDoc.class);System.out.println(hotelDoc);}@Testvoid testUpdateDocument() throws IOException {//1、准备RequestUpdateRequest request = new UpdateRequest("hotel", "61083");//2、准备请求参数request.doc("price", "952","starName", "四钻");//3、发送请求client.update(request,RequestOptions.DEFAULT);}@BeforeEachvoid setUp() {this.client = new RestHighLevelClient(RestClient.builder(HttpHost.create("http://xxx.xxx.xxx.xxx:9200")));}@AfterEachvoid tearDown() throws IOException {this.client.close();}
}
运行该测试,控制台运行成功
删除文档
@Test void testDeleteDocument() throws IOException {//1、准备RequestDeleteRequest request = new DeleteRequest("hotel", "61083");//2、发送请求client.delete(request,RequestOptions.DEFAULT); }
package cn.itcast.hotel;import cn.itcast.hotel.pojo.Hotel;
import cn.itcast.hotel.pojo.HotelDoc;
import cn.itcast.hotel.service.IHotelService;
import com.alibaba.fastjson.JSON;
import org.apache.http.HttpHost;
import org.elasticsearch.action.admin.indices.delete.DeleteIndexRequest;
import org.elasticsearch.action.bulk.BulkRequest;
import org.elasticsearch.action.delete.DeleteRequest;
import org.elasticsearch.action.get.GetRequest;
import org.elasticsearch.action.get.GetResponse;
import org.elasticsearch.action.index.IndexRequest;
import org.elasticsearch.action.update.UpdateRequest;
import org.elasticsearch.client.RequestOptions;
import org.elasticsearch.client.RestClient;
import org.elasticsearch.client.RestHighLevelClient;
import org.elasticsearch.client.indices.CreateIndexRequest;
import org.elasticsearch.client.indices.GetIndexRequest;
import org.elasticsearch.common.xcontent.XContentType;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;import java.io.IOException;
import java.util.List;import static cn.itcast.hotel.constants.HotelConstants.MAPPING_TEMPLATE;@SpringBootTest
public class HotelDocumentTest {@Autowiredprivate IHotelService hotelService;private RestHighLevelClient client;@Testvoid testAddDocument() throws IOException {//根据id查询酒店数据Hotel hotel = hotelService.getById(61083L);//转换成文档类型HotelDoc hotelDoc = new HotelDoc(hotel);//1、准备Request对象IndexRequest request = new IndexRequest("hotel").id(hotel.getId().toString());//2、准备json文档request.source(JSON.toJSONString(hotelDoc),XContentType.JSON);//3、发送请求client.index(request,RequestOptions.DEFAULT);}@Testvoid testGetDocumentById() throws IOException {//1、准备RequestGetRequest request = new GetRequest("hotel", "61083");//2、发送请求,得到响应GetResponse response = client.get(request, RequestOptions.DEFAULT);//3、解析响应结果String json = response.getSourceAsString();//反序列化HotelDoc hotelDoc = JSON.parseObject(json,HotelDoc.class);System.out.println(hotelDoc);}@Testvoid testUpdateDocument() throws IOException {//1、准备RequestUpdateRequest request = new UpdateRequest("hotel", "61083");//2、准备请求参数request.doc("price", "952","starName", "四钻");//3、发送请求client.update(request,RequestOptions.DEFAULT);}@Testvoid testDeleteDocument() throws IOException {//1、准备RequestDeleteRequest request = new DeleteRequest("hotel", "61083");//2、发送请求client.delete(request,RequestOptions.DEFAULT);}@BeforeEachvoid setUp() {this.client = new RestHighLevelClient(RestClient.builder(HttpHost.create("http://xxx.xxx.xxx.xxx:9200")));}@AfterEachvoid tearDown() throws IOException {this.client.close();}
}
运行该测试,控制台运行成功
批量导入文档
@Test void testBulkRequest() throws IOException {//1、创建RequestBulkRequest request = new BulkRequest();//2、准备参数,添加多个新增的Request,这里添加两个数据,分别是id为101和102的数据request.add(new IndexRequest("hotel").id("101").source("json source", XContentType.JSON));request.add(new IndexRequest("hotel").id("102").source("json source", XContentType.JSON));//3、发送请求client.bulk(request,RequestOptions.DEFAULT); }
我这里改成这样,是因为我要把该表的所有数据都导入文档
@Test
void testBulkRequest() throws IOException {
//批量查询酒店数据
List<Hotel> hotels = hotelService.list();
//1、创建Request
BulkRequest request = new BulkRequest();
//2、准备参数,添加多个新增的Request
for(Hotel hotel:hotels){
//转换为文档类型HotelDoc
HotelDoc hotelDoc = new HotelDoc(hotel);
//创建新增文档的Request对象
request.add(new IndexRequest("hotel")
.id(hotelDoc.getId().toString())
.source(JSON.toJSONString(hotelDoc),XContentType.JSON));
}
//3、发送请求
client.bulk(request,RequestOptions.DEFAULT);
}
package cn.itcast.hotel;import cn.itcast.hotel.pojo.Hotel;
import cn.itcast.hotel.pojo.HotelDoc;
import cn.itcast.hotel.service.IHotelService;
import com.alibaba.fastjson.JSON;
import org.apache.http.HttpHost;
import org.elasticsearch.action.admin.indices.delete.DeleteIndexRequest;
import org.elasticsearch.action.bulk.BulkRequest;
import org.elasticsearch.action.delete.DeleteRequest;
import org.elasticsearch.action.get.GetRequest;
import org.elasticsearch.action.get.GetResponse;
import org.elasticsearch.action.index.IndexRequest;
import org.elasticsearch.action.update.UpdateRequest;
import org.elasticsearch.client.RequestOptions;
import org.elasticsearch.client.RestClient;
import org.elasticsearch.client.RestHighLevelClient;
import org.elasticsearch.client.indices.CreateIndexRequest;
import org.elasticsearch.client.indices.GetIndexRequest;
import org.elasticsearch.common.xcontent.XContentType;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;import java.io.IOException;
import java.util.List;import static cn.itcast.hotel.constants.HotelConstants.MAPPING_TEMPLATE;@SpringBootTest
public class HotelDocumentTest {@Autowiredprivate IHotelService hotelService;private RestHighLevelClient client;@Testvoid testAddDocument() throws IOException {//根据id查询酒店数据Hotel hotel = hotelService.getById(61083L);//转换成文档类型HotelDoc hotelDoc = new HotelDoc(hotel);//1、准备Request对象IndexRequest request = new IndexRequest("hotel").id(hotel.getId().toString());//2、准备json文档request.source(JSON.toJSONString(hotelDoc),XContentType.JSON);//3、发送请求client.index(request,RequestOptions.DEFAULT);}@Testvoid testGetDocumentById() throws IOException {//1、准备RequestGetRequest request = new GetRequest("hotel", "61083");//2、发送请求,得到响应GetResponse response = client.get(request, RequestOptions.DEFAULT);//3、解析响应结果String json = response.getSourceAsString();//反序列化HotelDoc hotelDoc = JSON.parseObject(json,HotelDoc.class);System.out.println(hotelDoc);}@Testvoid testUpdateDocument() throws IOException {//1、准备RequestUpdateRequest request = new UpdateRequest("hotel", "61083");//2、准备请求参数request.doc("price", "952","starName", "四钻");//3、发送请求client.update(request,RequestOptions.DEFAULT);}@Testvoid testDeleteDocument() throws IOException {//1、准备RequestDeleteRequest request = new DeleteRequest("hotel", "61083");//2、发送请求client.delete(request,RequestOptions.DEFAULT);}@Testvoid testBulkRequest() throws IOException {//批量查询酒店数据List<Hotel> hotels = hotelService.list();//1、创建RequestBulkRequest request = new BulkRequest();//2、准备参数,添加多个新增的Requestfor(Hotel hotel:hotels){//转换为文档类型HotelDocHotelDoc hotelDoc = new HotelDoc(hotel);//创建新增文档的Request对象request.add(new IndexRequest("hotel").id(hotelDoc.getId().toString()).source(JSON.toJSONString(hotelDoc),XContentType.JSON));}//3、发送请求client.bulk(request,RequestOptions.DEFAULT);}@BeforeEachvoid setUp() {this.client = new RestHighLevelClient(RestClient.builder(HttpHost.create("http://xxx.xxx.xxx.xxx:9200")));}@AfterEachvoid tearDown() throws IOException {this.client.close();}
}
运行该测试,控制台运行成功,并且可以看到导入了201条数据,正好表的数据量
代码文件点击下载https://pan.baidu.com/s/1NJnwlfThymqPRhqWqqP0FQ?pwd=6c0n 上一篇:SpringAMQP的配置和使用
相关文章:
ES的安装和RestClient的操作
目录 初识elasticsearch 什么是elasticsearch elasticsearch的发展 Lucene的优缺点 elasticsearch的优势 倒排索引 es与mysql的概念对比 文档 索引 概念对比 架构 安装es 安装kibana 安装ik分词器 分词器 安装ik分词器 ik分词器的拓展和停用词典 操作索引库…...
访问者模式(Visitor)
访问者模式(Visitor Pattern)是一种将算法与对象结构分离的行为型设计模式。这种模式主要用于对一个由许多不同类型的对象构成的复杂对象结构(如组合结构)进行操作,而不需要对这些对象的类进行修改。 访问者模式涉及以下几个角色: 访问者(Visitor):为每一个具体元素类…...
ATTCK红队评估一
一、环境搭建 主机 ip地址 win7外网服务器(两张网卡) 外网:192.168.92.135 内网:192.168.52.143 server2003域成员主机 内网:192.168.52.141 server2008域空主机 内网:192.168.52.138 kali攻击机 …...
W5500-EVB-Pico评估版介绍
文章目录 1 概述2 板载资源2.1 硬件规格2.2 硬件规格2.3 工作条件 3 参考资料3.2 原理图3.3 尺寸图 (单位 : mm)3.4 参考例程 4 硬件协议栈优势 1 概述 W5500-EVB-Pico是基于树莓派RP2040和完全硬连线TCP/IP控制器W5500的微控制器开发板-基本上与树莓派Pico板相同,但…...
单聊和群聊
TCP协议单聊 服务端: import java.awt.BorderLayout; import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.io.PrintWriter; import java.net.ServerSocket; import java.net.Socket; import java.util.Vec…...
Swift 检测 iCloud状态
Show me the code: func isICloudContainerAvailable() -> Bool {if let _ FileManager.default.ubiquityIdentityToken {return true} else {return false} }推荐一下刚上线的 App 熊猫小账本,里面有用到这篇博客讲的内容 熊猫小账本 一个简洁的记账 App&…...
使用Windi CSS(基于vue-cli)
1、先创建vue项目 利用脚手架vue-cli创建,根据需求设置vue版本、babel等,无特别要求直接用默认的vue2或vue3就行 vue create 项目名 2、运行vue项目,利用vue-cli安装Windi CSS 官网指导:Vue CLI 集成 | Windi CSS 我的经历&a…...
操作无法完成(错误 0x000006ba),Windows 11 PDF打印机无法使用解决办法
操作无法完成(错误 0x000006ba),Windows 11 PDF打印机无法使用解决办法 解决方式一 先重启一次电脑,看看是否可以解决问题。 解决方式二 重新启动 Printer Spooler 服务...
Settings中电池选项-Android13
Settings中电池选项-Android13 1、设置中界面2、电池计算2.1 充电时间计算2.1.1 BatteryUsageStats获取2.1.2 BatteryStatsImpl计算 2.2 电池剩余使用时间2.2.1 Estimate获取2.2.2 BatteryStatsImpl计算 3、电池信息来源4、命令模拟* 日志 [电池]Android 9.0 电池未充电与充电字…...
解密 Java ForEach 提前终止问题
目录 前言:场景复现分析与解决方案解决方案详解总结 前言: 你是否曾在使用 Java 8 的 forEach 迭代集合时遇到过提前终止循环的问题?在这篇博客中,我们将深入探讨这一问题,并提供多种解决方案。通过场景复现、分析源码…...
7_js_dom编程入门1
Objective(本课目标) 掌握获取页面元素的常用方法 掌握事件触发案例 能够区分innerText和innerHTML的区别 综合案例训练 1 DOM 介绍 1.1 什么是DOM 文档对象模型(Document Object Model,简称DOM),是 …...
使用 Elasticsearch 检测抄袭 (一)
作者:Priscilla Parodi 抄袭可以是直接的,涉及复制部分或全部内容,也可以是释义的,即通过更改一些单词或短语来重新表述作者的作品。 灵感和释义之间是有区别的。 即使你得出类似的结论,也可以阅读内容,获得…...
STM32 cubeMX 直流电机控制风扇转动
本文使用的是 HAL 库。 文章目录 前言一、直流电机介绍二、直流电机原理图三、直流电机控制方法四、STM32CubeMX 配置直流电机五、代码编写总结 前言 实验开发板:STM32F051K8。所需软件:keil5 , cubeMX 。实验目的:了解 直流电机…...
我在 VSCode 插件里接入了 ChatGPT,解决了Bug无法定位的难题
作为一名软件开发者,我时常面临着代码中Bug的定位和解决问题。这个过程往往既费时又充满挑战。然而,最近我在我的VSCode插件中接入了ChatGPT,这个决定彻底改变了我处理Bug的方式。 Bug:开发者的噩梦 在开发过程中,遇…...
学Java的第四天
一、switch语句 switch (表达式) { case 1: 语句体1; break; case 2: 语句体2; break; ... default: 语句体n1; break; } 首先计算表达式的值,然后和case 比较,有对应的值就执行对应的语句,遇到 break 就结束。 最后如果所有的cas…...
[内功修炼]函数栈帧的创建与销毁
文章目录 1:什么是函数栈帧2:理解函数栈帧能解决什么问题呢3:函数栈帧的创建与销毁的解析3.1:什么是栈3.2:认识相关寄存器与汇编指令相关寄存器相关汇编指令 3.3 解析函数栈帧的创建和销毁3.3.1 预备知识3.3.2 详细解析一:调用main函数,为main函数开辟函数栈帧First:push前push…...
【深度学习-目标检测】03 - Faster R-CNN 论文学习与总结
论文地址:Faster R-CNN: Towards Real-Time ObjectDetection with Region Proposal Networks 论文学习 1. 摘要与引言 研究背景与挑战:当前最先进的目标检测网络依赖于 区域提议(Region Proposals)来假设目标的位置,…...
oracle11体系结构二-存储结构
数据区: 数据区(数据扩展区)由一组连续的oracle数据块所构成的存储结构,一个或多个数据块组成一个数据区,一个或多个数据区组成一个段。当段中所有空间被使用完后,oracle系统将自动为该段分配一个新的数据…...
如何通过内网穿透实现远程访问本地Linux SVN服务
文章目录 前言1. Ubuntu安装SVN服务2. 修改配置文件2.1 修改svnserve.conf文件2.2 修改passwd文件2.3 修改authz文件 3. 启动svn服务4. 内网穿透4.1 安装cpolar内网穿透4.2 创建隧道映射本地端口 5. 测试公网访问6. 配置固定公网TCP端口地址6.1 保留一个固定的公网TCP端口地址6…...
网页乱码问题(edge浏览器)
网页乱码问题(edge) 文章目录 网页乱码问题(edge)前言一、网页乱码问题1.是什么:(描述)2.解决方法:(针对edge浏览器)(1)下载charset插…...
泛微OA xmlrpcServlet接口任意文件读取漏洞(CNVD-2022-43245)
CNVD-2022-43245 泛微e-cology XmlRpcServlet接口处存在任意文件读取漏洞,攻击者可利用漏洞获取敏感信息。 1.漏洞级别 中危 2.影响范围 e-office < 9.5 202201133.漏洞搜索 fofa 搜索 app"泛微-OA(e-cology)"4.漏洞复现 …...
MATLAB ga函数的使用方法
一、ga句法结构 x ga(fitnessfcn,nvars) x ga(fitnessfcn,nvars,A,b) x ga(fitnessfcn,nvars,A,b,Aeq,beq) x ga(fitnessfcn,nvars,A,b,Aeq,beg,IB,UB) x ga(fitnessfcn,nvars,A,b,Aeq,beq,LB,UB,nonlcon) x ga(fitnessfcn,nvars,A,b,Aeq,beq,LB,UB,nonlcon,options) x …...
基于STM32和MQ-2传感器的无线烟雾检测系统设计
随着科技的不断发展,人们对生活安全的要求也越来越高。其中,烟雾检测系统在预防火灾方面起着至关重要的作用。本文将介绍一种基于STM32和MQ-2传感器的无线烟雾检测系统设计,旨在实时检测环境中的烟雾,并及时发出警报,以…...
华为vrrp+mstp+ospf+dhcp+dhcp relay配置案例
1、左边是vlan 10主桥,右边是vlan 20的主桥,并且互为备桥 2、 vlan 10 vrrp网关默认用左边,vlan 20的vrrp 网关默认用右边,对应mstp生成树 3、两边都track检测,不通就把vrrp减掉60,这样就会自动切另一边了 …...
5-Docker实例-tomcat application
1.安装如下树形结构创建目录及文件,内容如下: 目录结构: [root@centos79 ~]# tree demo demo ├── index.html └── WEB-INF└── web.xml1 directory, 2 files [root@centos79 ~]# index.html文件内容 [root@centos79 demo]# cat index.html <h1>hello dock…...
Pikachu靶场 “Http Header”SQL注入
1. 先在 pikachu 打开 Http Header 注入模块,点击提示 查看登录 账号 和 密码,登陆后去 Burp 中找到登陆的 GET请求 2. 设置payload1 :在 User-Agent最后 输入 查看 数据库名 or updatexml(1,concat(0x7e,database()),0) or 查看 用户名…...
OpenEuler安装内网穿透工具实现ssh连接openEuler系统
文章目录 1. 本地SSH连接测试2. openEuler安装Cpolar3. 配置 SSH公网地址4. 公网远程SSH连接5. 固定连接SSH公网地址6. SSH固定地址连接测试 本文主要介绍在openEuler中安装Cpolar内网穿透工具实现远程也可以ssh 连接openEuler系统使用. 欧拉操作系统(openEuler, 简称“欧拉”…...
【效率工具】利用python进行本地知识库(PDF和WORK文件内容)的批量模糊搜索
目录 前言 一、为什么要进行本地文档的批量搜索? 二、如何去做呢?...
快速入门学习定时任务框架-xxljob
定时任务框架-xxljob 简介 主要用于分布式任务调度,可以将任务调度和执行分布在多个节点上。它提供了一个集中式的管理平台,支持动态添加、修改、删除任务,以及任务的分片执行,确保任务在分布式环境中的高可用性的一个框架 spr…...
Floyd(弗洛伊德)算法总结
知识概览 Floyd算法适合解决多源汇最短路问题,其中源点是起点,汇点是终点。时间复杂度是。 例题展示 题目链接 活动 - AcWing 系统讲解常用算法与数据结构,给出相应代码模板,并会布置、讲解相应的基础算法题目。https://www.acw…...
西南科技大学计算机网络实验二 (IP协议分析与以太网协议分析)
一、实验目的 通过分析由跟踪执行traceroute程序发送和接收捕获得到的IP 数据报,深入研究在IP 数据报中的各种字段,理解IP协议。基于ARP命令和Ethereal进行以太网帧捕获与分析,理解和熟悉ARP协议原理以及以太网帧格式。 二、实验环境 与因特网连接的计算机网络系统;主机操…...
SICP : The Elements of Programming
好的计算机编程语言应具备的三个特性 基础单元表达式,计算机编程语言最最最基础单元,理应具备的表达式组合的能力,能够通过基础单元表达式组合成更复杂的元素抽象的能力,能通过复杂的元素抽象成更高层的单元 基础单元表达式 加 …...
支付宝、学习强国小程序input、textarea数据双向绑定
前言 和 vue 的绑定有些区别,需要注意。直接 value"{{inputValue}}" 是无法双向绑定的。 正确思路 文档说的比较详细,不过没有组合使用的案例,需要自行理解。这里正确的方法是先用 value 绑定数据,再使用 onInput 事件…...
AI“百模大战”现状:向垂直、B端谋场景,算力仍是主要制约因素
文章目录 每日一句正能量前言AI(人工智能)大模型正“飞入”百姓家和行业中。向垂直、B端谋场景算力仍是主要制约因素构建“数据-模型-应用”飞轮后记 每日一句正能量 我们必须在失败中寻找胜利,在绝望中寻求希望。 前言 在当前快速发展的人工…...
手机上的软件怎么修改网络IP地址
在手机上修改网络IP地址通常需要通过以下两种方法: 1. 使用VPN(虚拟私人网络)或代理软件: 步骤如下: - 下载并安装一个可靠的VPN或代理软件到你的手机上。 - 打开VPN或代理软件,选择一个你希望获取IP地址…...
返回按钮点击坐标
返回按钮的点击坐标(按钮本身的相对位置)主要用于自绘控件时响应点击对应的数据变化。效果如下图: 代码实现 private void button1_MouseClick(object sender, MouseEventArgs e){Point p e.Location;this.Text p.ToString();} 利用 Mouse…...
arm32 arm64 读取PMCCNTR cpu cycle counter
ARM 的时钟周期计数保存在PMCCNTR 寄存器,不像x86用户态可以直接读取,需内核态使能,一种是在内核中使能,比如init,比较简单的是在模块中使能。 本来写了两个,arm32一个,arm64一个,方…...
vue 项目/备案网页/ip网页打包成 apk 安装到平板/手机(含vue项目跨域代理打包成apk后无法访问接口的解决方案)
下载安装HBuilder X编辑器 https://www.dcloud.io/hbuilderx.html 新建 5APP 项目 打开 HBuilder X,新建项目 此处项目名以 ‘test’ 为例 含跨域代理的vue项目改造 若 vue 项目中含跨域代理,如 vue.config.js module.exports {publicPath: "./&…...
面试复盘4——后端开发——一面
前言 本文主要用于个人复盘学习,因此为保障公平,所以本文不指出公司名,题目编号只是为了自己区别而已。对待面经,望读者还是更多从其中学习总结,而不是去碰原题。 面试岗位信息 北京某初创,go开发&#…...
使用 Postman 进行并发请求:实用教程与最佳实践
背景介绍 最近,我们发起了一个在线图书管理系统的项目。我负责的一个关键模块包括三个主要后台接口: 实现对books数据的检索。实施对likes数据的获取。通过collections端点访问数据。 应对高流量的挑战 在设计并部署接口时,我们不可避免地…...
河南工程学院第六届程序设计竞赛-A组-题解
更好的阅读体验 \color{red}{更好的阅读体验} 更好的阅读体验 远古时期的签到题 原题链接 描述: 远古时期奇妙的事情… 远古时期有一个比赛,里面有这样一道签到题: 给定一个正整数 N N N求这个整数转化为二进制后的数有多少位是 0 0 0。…...
韩版传奇 2 源码分析与 Unity 重制(二)客户端启动与交互流程
专题介绍 该专题将会分析 LOMCN 基于韩版传奇 2,使用 .NET 重写的传奇源码(服务端 客户端),分析数据交互、状态管理和客户端渲染等技术,此外笔者还会分享将客户端部分移植到 Unity 和服务端用现代编程语言重写的全过…...
JVM面试——运行时数据区
一:JVM的运行时内存区域是怎样的? 根据Java虚拟机规范的定义,JVM的运行时内存区域主要由程序计数器、虚拟机栈、本地方法 栈、Java堆、方法区和以及运行时常量池组成。其中堆、方法区以及运行时常量池是线程之间共享的区域,而栈(…...
ssh工具 向指定的ssh服务器配置公钥
此文分享一个python脚本,用于向指定的ssh服务器配置公钥,以达到免密登录ssh服务器的目的。 效果演示 🔥完整演示效果 👇第一步,显然,我们需要选择功能 👇第二步,确认 or 选择ssh服务器 👇第三步,输入ssh登录密码,以完成公钥配置 👇验证,我们通过ssh登录…...
uni-app pages.json之globalStyle全局页面样式配置
锋哥原创的uni-app视频教程: 2023版uniapp从入门到上天视频教程(Java后端无废话版),火爆更新中..._哔哩哔哩_bilibili2023版uniapp从入门到上天视频教程(Java后端无废话版),火爆更新中...共计23条视频,包括:第1讲 uni…...
Blazor 混合开发_MAUI+Vue_WPF+Vue
Blazor 混合开发_MAUIVue_WPFVue 背景混合开发的核心为什么必须使用 wwwroot 文件夹放置 Web 项目文件 创建 MAUI 项目创建 wwwroot 文件夹服务注册创建 _import.razor添加 Main.razor 组件修改 MainPage.xaml 文件 创建 WPF 项目创建 wwwroot 文件夹服务注册创建 _import.razo…...
udp异步方式接收消息
C#实现 //定义结构体 public struct UdpState { public UdpClient u; public IPEndPoint e; } private UdpClient _client; //_client的初始化请参考其他资料 IPEndPoint remoteEP null; //TODO //public static bool mess…...
【RocketMQ笔记01】安装RocketMQ消息队列运行环境
这篇文章,主要介绍如何安装RocketMQ消息队列运行环境。 目录 一、RocketMQ消息队列 1.1、下载RocketMQ 1.2、解压安装包 1.3、配置RocketMQ环境变量 1.4、修改启动脚本 1.5、启动RocketMQ (1)启动NameServer (2࿰…...
使用 Privoxy 实现对多域名的定向转发
需求与思路 内网一台主机想要访问公网的两个不同站点, 想要实现访问两个站点时表现出不同的公网 IP 地址. 即在公网的站点服务器端看到的客户端 IP 是不同的. 思路是搭建两台具有不同公网 IP 的服务器, 分别安装配置 Privoxy 后进行串联, 并将其中一台作为主服务器暴露给内网…...
《PySpark大数据分析实战》-19.NumPy介绍ndarray介绍
📋 博主简介 💖 作者简介:大家好,我是wux_labs。😜 热衷于各种主流技术,热爱数据科学、机器学习、云计算、人工智能。 通过了TiDB数据库专员(PCTA)、TiDB数据库专家(PCTP…...