SpringBoot-2.X 學習筆記06 整合ElasticSearch-6.5.0 實現簡單增刪改查
- 1 修改 SpringBoot-2.X
- 2 修改 ElasticSearch-6.5.0
- 2.1 配置 ElasticSearch-6.5.0 elasticsearch.yml
- 2.2 啓動 ElasticSearch-6.5.0
- 2.3 查看 ElasticSearch-6.5.0 啓動結果
- 2.4 查看 ElasticSearch-6.5.0 集羣狀態
- 2.5 查看 ElasticSearch-6.5.0 索引列表
- 3 測試代碼
- 3.0 測試項目
- 3.1 測試 Entity 類
- 3.2 測試 Repository 類
- 3.3 測試 Service 類
- 3.4 測試 ServiceImpl 類
- 3.5 測試 ElasticSearchController 類
- 3.6 測試 Application 類
- 3.6 啓動測試項目
- 4 測試結果
ElasticSearch-7.3.0 需要 JDK11 否則無法啓動,這裏測試的是 ElasticSearch-6.5.0 ,如果使用 ElasticSearch-7.3.0 配置也是一樣
1 修改 SpringBoot-2.X
1.1 修改 SpringBoot-2.X applocation.properties
############################################################
# springboot-2.x 整合 elasticsearch-7.3.0 配置
############################################################
#開啓 Elasticsearch 倉庫(默認值:true)
spring.data.elasticsearch.repositories.enabled=true
#默認 9300 是 Java 客戶端的端口。9200 是支持 Restful HTTP 的接口
spring.data.elasticsearch.cluster-nodes = 127.0.0.1:9300
# Elasticsearch 集羣名(默認值: elasticsearch)
spring.data.elasticsearch.cluster-name=my-application
#集羣節點地址列表,用逗號分隔。如果沒有指定,就啓動一個客戶端節點
#spring.data.elasticsearch.cluster-nodes=
#用來配置客戶端的額外屬性
#spring.data.elasticsearch.propertie=
#存儲索引的位置
#spring.data.elasticsearch.properties.path.home=/data/project/target/elastic
#連接超時的時間
spring.data.elasticsearch.properties.transport.tcp.connect_timeout=120s
1.2 修改 SpringBoot-2.X pom.xml
<?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.1.9.RELEASE</version>
<relativePath /> <!-- lookup parent from repository -->
</parent>
<groupId>com.xu.springboot</groupId>
<artifactId>ElasticSearch</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>ElasticSearch</name>
<description>Demo project for Spring Boot</description>
<properties>
<java.version>1.8</java.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<!-- elasticsearch 全文搜索 -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-elasticsearch</artifactId>
</dependency>
<!-- elasticsearch 全文搜索 -->
<dependency>
<groupId>org.elasticsearch.client</groupId>
<artifactId>transport</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-devtools</artifactId>
<scope>runtime</scope>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<optional>true</optional>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>
2 修改 ElasticSearch-6.5.0
2.1 配置 ElasticSearch-6.5.0 elasticsearch.yml
# ======================== Elasticsearch Configuration =========================
#
# NOTE: Elasticsearch comes with reasonable defaults for most settings.
# Before you set out to tweak and tune the configuration, make sure you
# understand what are you trying to accomplish and the consequences.
#
# The primary way of configuring a node is via this file. This template lists
# the most important settings you may want to configure for a production cluster.
#
# Please consult the documentation for further information on configuration options:
# https://www.elastic.co/guide/en/elasticsearch/reference/index.html
#
# ---------------------------------- Cluster -----------------------------------
#
# Use a descriptive name for your cluster:
#
cluster.name: my-application
#
# ------------------------------------ Node ------------------------------------
#
# Use a descriptive name for the node:
#
#node.name: node-1
#
# Add custom attributes to the node:
#
#node.attr.rack: r1
#
# ----------------------------------- Paths ------------------------------------
#
# Path to directory where to store the data (separate multiple locations by comma):
#
#path.data: /path/to/data
#
# Path to log files:
#
#path.logs: /path/to/logs
#
# ----------------------------------- Memory -----------------------------------
#
# Lock the memory on startup:
#
#bootstrap.memory_lock: true
#
# Make sure that the heap size is set to about half the memory available
# on the system and that the owner of the process is allowed to use this
# limit.
#
# Elasticsearch performs poorly when the system is swapping the memory.
#
# ---------------------------------- Network -----------------------------------
#
# Set the bind address to a specific IP (IPv4 or IPv6):
#
network.host: 0.0.0.0
#
# Set a custom port for HTTP:
#
#http.port: 9200
#
# For more information, consult the network module documentation.
#
# --------------------------------- Discovery ----------------------------------
#
# Pass an initial list of hosts to perform discovery when new node is started:
# The default list of hosts is ["127.0.0.1", "[::1]"]
#
#discovery.zen.ping.unicast.hosts: ["host1", "host2"]
#
# Prevent the "split brain" by configuring the majority of nodes (total number of master-eligible nodes / 2 + 1):
#
#discovery.zen.minimum_master_nodes:
#
# For more information, consult the zen discovery module documentation.
#
# ---------------------------------- Gateway -----------------------------------
#
# Block initial recovery after a full cluster restart until N nodes are started:
#
#gateway.recover_after_nodes: 3
#
# For more information, consult the gateway module documentation.
#
# ---------------------------------- Various -----------------------------------
#
# Require explicit names when deleting indices:
#
#action.destructive_requires_name: true
2.2 啓動 ElasticSearch-6.5.0
# 切換目錄
cd E:\Project\elasticsearch-6.5.0\bin
elasticsearch.bat
# 啓動結果
[2019-10-21T14:37:21,301][INFO ][o.e.e.NodeEnvironment ] [d71csjX] using [1] data paths, mounts [[杞歡 (D:)]], net usable_space [74.8gb], net total_space [102gb], types [NTFS]
[2019-10-21T14:37:21,306][INFO ][o.e.e.NodeEnvironment ] [d71csjX] heap size [990.7mb], compressed ordinary object pointers [true]
[2019-10-21T14:37:21,364][INFO ][o.e.n.Node ] [d71csjX] node name derived from node ID [d71csjXIQaqc9SqVXm1FeA]; set [node.name] to override
[2019-10-21T14:37:21,365][INFO ][o.e.n.Node ] [d71csjX] version[6.5.0], pid[11940], build[default/zip/816e6f6/2018-11-09T18:58:36.352602Z], OS[Windows 10/10.0/amd64], JVM[Oracle Corporation/Java HotSpot(TM) 64-Bit Server VM/1.8.0_191/25.191-b12]
[2019-10-21T14:37:21,367][INFO ][o.e.n.Node ] [d71csjX] JVM arguments [-Xms1g, -Xmx1g, -XX:+UseConcMarkSweepGC, -XX:CMSInitiatingOccupancyFraction=75, -XX:+UseCMSInitiatingOccupancyOnly, -XX:+AlwaysPreTouch, -Xss1m, -Djava.awt.headless=true, -Dfile.encoding=UTF-8, -Djna.nosys=true, -XX:-OmitStackTraceInFastThrow, -Dio.netty.noUnsafe=true, -Dio.netty.noKeySetOptimization=true, -Dio.netty.recycler.maxCapacityPerThread=0, -Dlog4j.shutdownHookEnabled=false, -Dlog4j2.disable.jmx=true, -Djava.io.tmpdir=C:\Users\ADMINI~1\AppData\Local\Temp\elasticsearch, -XX:+HeapDumpOnOutOfMemoryError, -XX:HeapDumpPath=data, -XX:ErrorFile=logs/hs_err_pid%p.log, -XX:+PrintGCDetails, -XX:+PrintGCDateStamps, -XX:+PrintTenuringDistribution, -XX:+PrintGCApplicationStoppedTime, -Xloggc:logs/gc.log, -XX:+UseGCLogFileRotation, -XX:NumberOfGCLogFiles=32, -XX:GCLogFileSize=64m, -Delasticsearch, -Des.path.home=D:\Project\elasticsearch-6.5.0, -Des.path.conf=D:\Project\elasticsearch-6.5.0\config, -Des.distribution.flavor=default, -Des.distribution.type=zip]
[2019-10-21T14:37:26,912][INFO ][o.e.p.PluginsService ] [d71csjX] loaded module [aggs-matrix-stats]
[2019-10-21T14:37:26,913][INFO ][o.e.p.PluginsService ] [d71csjX] loaded module [analysis-common]
[2019-10-21T14:37:26,914][INFO ][o.e.p.PluginsService ] [d71csjX] loaded module [ingest-common]
[2019-10-21T14:37:26,915][INFO ][o.e.p.PluginsService ] [d71csjX] loaded module [lang-expression]
[2019-10-21T14:37:26,917][INFO ][o.e.p.PluginsService ] [d71csjX] loaded module [lang-mustache]
[2019-10-21T14:37:26,918][INFO ][o.e.p.PluginsService ] [d71csjX] loaded module [lang-painless]
[2019-10-21T14:37:26,920][INFO ][o.e.p.PluginsService ] [d71csjX] loaded module [mapper-extras]
[2019-10-21T14:37:26,921][INFO ][o.e.p.PluginsService ] [d71csjX] loaded module [parent-join]
[2019-10-21T14:37:26,925][INFO ][o.e.p.PluginsService ] [d71csjX] loaded module [percolator]
[2019-10-21T14:37:26,928][INFO ][o.e.p.PluginsService ] [d71csjX] loaded module [rank-eval]
[2019-10-21T14:37:26,930][INFO ][o.e.p.PluginsService ] [d71csjX] loaded module [reindex]
[2019-10-21T14:37:26,931][INFO ][o.e.p.PluginsService ] [d71csjX] loaded module [repository-url]
[2019-10-21T14:37:26,933][INFO ][o.e.p.PluginsService ] [d71csjX] loaded module [transport-netty4]
[2019-10-21T14:37:26,935][INFO ][o.e.p.PluginsService ] [d71csjX] loaded module [tribe]
[2019-10-21T14:37:26,936][INFO ][o.e.p.PluginsService ] [d71csjX] loaded module [x-pack-ccr]
[2019-10-21T14:37:26,937][INFO ][o.e.p.PluginsService ] [d71csjX] loaded module [x-pack-core]
[2019-10-21T14:37:26,940][INFO ][o.e.p.PluginsService ] [d71csjX] loaded module [x-pack-deprecation]
[2019-10-21T14:37:26,942][INFO ][o.e.p.PluginsService ] [d71csjX] loaded module [x-pack-graph]
[2019-10-21T14:37:26,942][INFO ][o.e.p.PluginsService ] [d71csjX] loaded module [x-pack-logstash]
[2019-10-21T14:37:26,944][INFO ][o.e.p.PluginsService ] [d71csjX] loaded module [x-pack-ml]
[2019-10-21T14:37:26,947][INFO ][o.e.p.PluginsService ] [d71csjX] loaded module [x-pack-monitoring]
[2019-10-21T14:37:26,948][INFO ][o.e.p.PluginsService ] [d71csjX] loaded module [x-pack-rollup]
[2019-10-21T14:37:26,949][INFO ][o.e.p.PluginsService ] [d71csjX] loaded module [x-pack-security]
[2019-10-21T14:37:26,950][INFO ][o.e.p.PluginsService ] [d71csjX] loaded module [x-pack-sql]
[2019-10-21T14:37:26,951][INFO ][o.e.p.PluginsService ] [d71csjX] loaded module [x-pack-upgrade]
[2019-10-21T14:37:26,952][INFO ][o.e.p.PluginsService ] [d71csjX] loaded module [x-pack-watcher]
[2019-10-21T14:37:26,956][INFO ][o.e.p.PluginsService ] [d71csjX] no plugins loaded
[2019-10-21T14:37:38,616][INFO ][o.e.x.s.a.s.FileRolesStore] [d71csjX] parsed [0] roles from file [D:\Project\elasticsearch-6.5.0\config\roles.yml]
[2019-10-21T14:37:40,293][INFO ][o.e.x.m.j.p.l.CppLogMessageHandler] [d71csjX] [controller/14712] [Main.cc@109] controller (64 bit): Version 6.5.0 (Build 71882a589e5556) Copyright (c) 2018 Elasticsearch BV
[2019-10-21T14:37:41,392][DEBUG][o.e.a.ActionModule ] [d71csjX] Using REST wrapper from plugin org.elasticsearch.xpack.security.Security
[2019-10-21T14:37:42,074][INFO ][o.e.d.DiscoveryModule ] [d71csjX] using discovery type [zen] and host providers [settings]
[2019-10-21T14:37:43,816][INFO ][o.e.n.Node ] [d71csjX] initialized
[2019-10-21T14:37:43,817][INFO ][o.e.n.Node ] [d71csjX] starting ...
[2019-10-21T14:37:47,341][INFO ][o.e.t.TransportService ] [d71csjX] publish_address {172.17.115.17:9300}, bound_addresses {[::]:9300}
[2019-10-21T14:37:47,387][INFO ][o.e.b.BootstrapChecks ] [d71csjX] bound or publishing to a non-loopback address, enforcing bootstrap checks
[2019-10-21T14:37:50,642][INFO ][o.e.c.s.MasterService ] [d71csjX] zen-disco-elected-as-master ([0] nodes joined), reason: new_master {d71csjX}{d71csjXIQaqc9SqVXm1FeA}{XwYtG8qXQGO1ZYAOCjd4KQ}{172.17.115.17}{172.17.115.17:9300}{ml.machine_memory=17087959040, xpack.installed=true, ml.max_open_jobs=20, ml.enabled=true}
[2019-10-21T14:37:50,653][INFO ][o.e.c.s.ClusterApplierService] [d71csjX] new_master {d71csjX}{d71csjXIQaqc9SqVXm1FeA}{XwYtG8qXQGO1ZYAOCjd4KQ}{172.17.115.17}{172.17.115.17:9300}{ml.machine_memory=17087959040, xpack.installed=true, ml.max_open_jobs=20, ml.enabled=true}, reason: apply cluster state (from master [master {d71csjX}{d71csjXIQaqc9SqVXm1FeA}{XwYtG8qXQGO1ZYAOCjd4KQ}{172.17.115.17}{172.17.115.17:9300}{ml.machine_memory=17087959040, xpack.installed=true, ml.max_open_jobs=20, ml.enabled=true} committed version [1] source [zen-disco-elected-as-master ([0] nodes joined)]])
[2019-10-21T14:37:51,979][WARN ][o.e.x.s.a.s.m.NativeRoleMappingStore] [d71csjX] Failed to clear cache for realms [[]]
[2019-10-21T14:37:52,162][INFO ][o.e.l.LicenseService ] [d71csjX] license [37a50ea7-2222-4e93-bc1a-de74bb762a5a] mode [basic] - valid
[2019-10-21T14:37:52,218][INFO ][o.e.g.GatewayService ] [d71csjX] recovered [1] indices into cluster_state
[2019-10-21T14:37:53,050][INFO ][o.e.x.s.t.n.SecurityNetty4HttpServerTransport] [d71csjX] publish_address {172.17.115.17:9200}, bound_addresses {[::]:9200}
[2019-10-21T14:37:53,052][INFO ][o.e.n.Node ] [d71csjX] started
[2019-10-21T14:37:53,622][INFO ][o.e.c.r.a.AllocationService] [d71csjX] Cluster health status changed from [RED] to [GREEN] (reason: [shards started [[books][0]] ...]).
2.3 查看 ElasticSearch-6.5.0 啓動結果
http://localhost:9200/
2.4 查看 ElasticSearch-6.5.0 集羣狀態
localhost:9200/_cat/health?v
2.5 查看 ElasticSearch-6.5.0 索引列表
localhost:9200/_cat/indices?v
3 測試代碼
3.0 測試項目
3.1 測試 Entity 類
/**
*
* @Author: hyacinth
* @Title: Books.java
* @Package com.xu.springboot.elasticsearch
* @Description: TODO:
* @Date: 2019年10月20日 下午8:40:02
* @Version V-1.0
* @Copyright: 2019 hyacinth
*
*/
package com.xu.springboot.elasticsearch;
import java.io.Serializable;
import org.springframework.data.elasticsearch.annotations.Document;
/**
* @Author: hyacinth
* @ClassName: Books
* @Description: TODO
* @Date: 2019年10月20日 下午8:40:02
* @Copyright: hyacinth
*/
@Document(indexName = "books", type = "info", shards = 1, replicas = 0)
public class Books implements Serializable {
/**
* @Fields serialVersionUID:TODO
* @Date 2019年8月17日 下午9:56:28
*/
private static final long serialVersionUID = -4201309328223793614L;
private String id;
private String name;
private String tag;
private String description;
public String getId() {
return id;
}
public void setId(String id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getTag() {
return tag;
}
public void setTag(String tag) {
this.tag = tag;
}
public String getDescription() {
return description;
}
public void setDescription(String description) {
this.description = description;
}
}
3.2 測試 Repository 類
/**
*
* @Author: hyacinth
* @Title: BookSearchRepository.java
* @Package com.xu.springboot.elasticsearch
* @Description: TODO:
* @Date: 2019年10月20日 下午8:44:32
* @Version V-1.0
* @Copyright: 2019 hyacinth
*
*/
package com.xu.springboot.elasticsearch;
import org.springframework.data.elasticsearch.repository.ElasticsearchRepository;
import org.springframework.stereotype.Component;
/**
* @Author: hyacinth
* @ClassName: BookSearchRepository
* @Description: TODO
* @Date: 2019年10月20日 下午8:44:32
* @Copyright: hyacinth
*/
@Component
public interface BookSearchRepository extends ElasticsearchRepository<Books,String> {
}
3.3 測試 Service 類
/**
*
* @Author: hyacinth
* @Title: BookSearchService.java
* @Package com.xu.springboot.elasticsearch
* @Description: TODO:
* @Date: 2019年10月20日 下午8:43:01
* @Version V-1.0
* @Copyright: 2019 hyacinth
*
*/
package com.xu.springboot.elasticsearch;
/**
* @Author: hyacinth
* @ClassName: BookSearchService
* @Description: TODO
* @Date: 2019年10月20日 下午8:43:01
* @Copyright: hyacinth
*/
public interface BookSearchService {
Object save(Books books);
Object findAllBook();
Object findByBookId(String id);
Object findByBookName(String name);
Object updateByBookId(Books books);
Object updateByBookName(Books books);
Object deleteByBookId(String id);
Object deleteByBookName(String name);
}
3.4 測試 ServiceImpl 類
/**
*
* @Author: hyacinth
* @Title: BookSearchServiceImpl.java
* @Package com.xu.springboot.elasticsearch
* @Description: TODO:
* @Date: 2019年10月20日 下午8:43:34
* @Version V-1.0
* @Copyright: 2019 hyacinth
*
*/
package com.xu.springboot.elasticsearch;
import java.util.Optional;
import org.elasticsearch.index.query.QueryBuilders;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.elasticsearch.core.ElasticsearchTemplate;
import org.springframework.data.elasticsearch.core.query.NativeSearchQueryBuilder;
import org.springframework.data.elasticsearch.core.query.SearchQuery;
import org.springframework.stereotype.Service;
/**
* @Author: hyacinth
* @ClassName: BookSearchServiceImpl
* @Description: TODO
* @Date: 2019年10月20日 下午8:43:34
* @Copyright: hyacinth
*/
@Service
public class BookSearchServiceImpl implements BookSearchService{
@Autowired
private BookSearchRepository repository;
@Autowired
private ElasticsearchTemplate template;
@Override
public Object save(Books books) {
Books save = repository.save(books);
return save.toString();
}
@Override
public Object findAllBook() {
return repository.findAll();
}
@Override
public Object findByBookId(String id) {
return repository.findById(id);
}
@Override
public Object findByBookName(String name) {
SearchQuery searchQuery = new NativeSearchQueryBuilder()
.withQuery(QueryBuilders.matchPhraseQuery("name", name))
.build();
return template.queryForList(searchQuery, Books.class);
}
@Override
public Object updateByBookId(Books books) {
// TODO Auto-generated method stub
return null;
}
@Override
public Object updateByBookName(Books books) {
// TODO Auto-generated method stub
return null;
}
@Override
public Object deleteByBookId(String id) {
Optional<Books> books = repository.findById(id);
repository.deleteById(id);
return books;
}
@Override
public Object deleteByBookName(String name) {
// TODO Auto-generated method stub
return null;
}
}
3.5 測試 ElasticSearchController 類
/**
*
* @Author: hyacinth
* @Title: ElasticSearchController.java
* @Package com.xu.springboot.controler
* @Description: TODO:
* @Date: 2019年10月20日 下午10:22:59
* @Version V-1.0
* @Copyright: 2019 hyacinth
*
*/
package com.xu.springboot.controler;
import java.util.ArrayList;
import java.util.List;
import java.util.UUID;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.xu.springboot.elasticsearch.BookSearchService;
import com.xu.springboot.elasticsearch.Books;
/**
* @Author: hyacinth
* @ClassName: ElasticSearchController
* @Description: TODO
* @Date: 2019年10月20日 下午10:22:59
* @Copyright: hyacinth
*/
@RestController
@RequestMapping("/es")
public class ElasticSearchController {
@Autowired
private BookSearchService service;
@RequestMapping("/save")
public Object save(String id) {//http://127.0.0.1:8080/es/save?id=2
Books document=new Books();
document.setId(id);
document.setName(id+": 心如孤島囚我終老 "+UUID.randomUUID().toString());
document.setTag("愛情");
document.setDescription(UUID.randomUUID().toString());
service.save(document);
List<Object> list=new ArrayList<Object>();
list.add("Success\t"+id);
list.add(service.findByBookId(id));
return list;
}
@RequestMapping("/getByBookId")
public Object getByBookId(String id) {//http://127.0.0.1:8080/es/getByBookId?id=2
return service.findByBookId(id);
}
@RequestMapping("/getByBookName")
public Object getByBookName(String name) {//http://127.0.0.1:8080/es/getByBookName?name=心如孤島囚我終老
return service.findByBookName(name);
}
@RequestMapping("/deleteByBookId")
public Object deleteByBookId(String id) {//http://127.0.0.1:8080/es/deleteByBookId?id=1
return service.deleteByBookId(id);
}
@RequestMapping("/findAllBook")
public Object findAllBook() {//http://127.0.0.1:8080/es/findAllBook
return service.findAllBook();
}
}
3.6 測試 Application 類
package com.xu.springboot;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
@SpringBootApplication
public class Application {
public static void main(String[] args) {
SpringApplication.run(Application.class, args);
}
}
3.6 啓動測試項目
. ____ _ __ _ _
/\\ / ___'_ __ _ _(_)_ __ __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
\\/ ___)| |_)| | | | | || (_| | ) ) ) )
' |____| .__|_| |_|_| |_\__, | / / / /
=========|_|==============|___/=/_/_/_/
:: Spring Boot :: (v2.1.9.RELEASE)
2019-10-21 14:55:58.211 INFO 1824 --- [ restartedMain] com.xu.springboot.Application : Starting Application on ZWJ0R16WWO114LL with PID 1824 (E:\SourceCode\Eclipse-2019-06\ElasticSearch\target\classes started by Administrator in E:\SourceCode\Eclipse-2019-06\ElasticSearch)
2019-10-21 14:55:58.218 INFO 1824 --- [ restartedMain] com.xu.springboot.Application : No active profile set, falling back to default profiles: default
2019-10-21 14:55:58.521 INFO 1824 --- [ restartedMain] .e.DevToolsPropertyDefaultsPostProcessor : Devtools property defaults active! Set 'spring.devtools.add-properties' to 'false' to disable
2019-10-21 14:55:58.521 INFO 1824 --- [ restartedMain] .e.DevToolsPropertyDefaultsPostProcessor : For additional web related logging consider setting the 'logging.level.web' property to 'DEBUG'
2019-10-21 14:56:01.521 INFO 1824 --- [ restartedMain] .s.d.r.c.RepositoryConfigurationDelegate : Bootstrapping Spring Data repositories in DEFAULT mode.
2019-10-21 14:56:01.774 INFO 1824 --- [ restartedMain] .s.d.r.c.RepositoryConfigurationDelegate : Finished Spring Data repository scanning in 239ms. Found 1 repository interfaces.
2019-10-21 14:56:04.594 INFO 1824 --- [ restartedMain] o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat initialized with port(s): 8080 (http)
2019-10-21 14:56:04.782 INFO 1824 --- [ restartedMain] o.apache.catalina.core.StandardService : Starting service [Tomcat]
2019-10-21 14:56:04.783 INFO 1824 --- [ restartedMain] org.apache.catalina.core.StandardEngine : Starting Servlet engine: [Apache Tomcat/9.0.26]
2019-10-21 14:56:05.432 INFO 1824 --- [ restartedMain] o.a.c.c.C.[Tomcat].[localhost].[/] : Initializing Spring embedded WebApplicationContext
2019-10-21 14:56:05.432 INFO 1824 --- [ restartedMain] o.s.web.context.ContextLoader : Root WebApplicationContext: initialization completed in 6910 ms
2019-10-21 14:56:09.081 INFO 1824 --- [ restartedMain] o.elasticsearch.plugins.PluginsService : no modules loaded
2019-10-21 14:56:09.083 INFO 1824 --- [ restartedMain] o.elasticsearch.plugins.PluginsService : loaded plugin [org.elasticsearch.index.reindex.ReindexPlugin]
2019-10-21 14:56:09.084 INFO 1824 --- [ restartedMain] o.elasticsearch.plugins.PluginsService : loaded plugin [org.elasticsearch.join.ParentJoinPlugin]
2019-10-21 14:56:09.085 INFO 1824 --- [ restartedMain] o.elasticsearch.plugins.PluginsService : loaded plugin [org.elasticsearch.percolator.PercolatorPlugin]
2019-10-21 14:56:09.085 INFO 1824 --- [ restartedMain] o.elasticsearch.plugins.PluginsService : loaded plugin [org.elasticsearch.script.mustache.MustachePlugin]
2019-10-21 14:56:09.085 INFO 1824 --- [ restartedMain] o.elasticsearch.plugins.PluginsService : loaded plugin [org.elasticsearch.transport.Netty4Plugin]
2019-10-21 14:56:15.059 INFO 1824 --- [ restartedMain] o.s.d.e.c.TransportClientFactoryBean : Adding transport node : 127.0.0.1:9300
2019-10-21 14:56:17.718 INFO 1824 --- [ restartedMain] o.s.b.d.a.OptionalLiveReloadServer : LiveReload server is running on port 35729
2019-10-21 14:56:18.478 INFO 1824 --- [ restartedMain] o.s.s.concurrent.ThreadPoolTaskExecutor : Initializing ExecutorService 'applicationTaskExecutor'
2019-10-21 14:56:21.377 INFO 1824 --- [ restartedMain] o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat started on port(s): 8080 (http) with context path ''
2019-10-21 14:56:21.382 INFO 1824 --- [ restartedMain] com.xu.springboot.Application : Started Application in 24.713 seconds (JVM running for 26.128)
4 測試結果
4.1 增加
http://127.0.0.1:8080/es/save?id=2
4.2 刪除
http://127.0.0.1:8080/es/deleteByBookId?id=1
4.3 查詢
http://127.0.0.1:8080/es/findAllBook