docker部署elasticsearch-+-Kibana(6-8)-+-SpringBoot-2-1-6
elasticsearch快速开始
docker run -d --name elasticsearch --net somenetwork -p 9200:9200 -p 9300:9300 -e "discovery.type=single-node" elasticsearch:6.8.11
环境Linux
该vm.max_map_count
内核设置需要至少设置为262144
用于生产。取决于您的平台:
的Linux
该
vm.max_map_count
设置应该在/etc/sysctl.conf中永久设置:
vim /etc/sysctl.conf
# 这里设置多一点
vm.max_map_count=655360
# 刷新
sysctl -p
官网es6.8安装教程
https://www.elastic.co/guide/en/elasticsearch/reference/6.8/docker.html
注意SpringBoot和ES的版本
Elasticsearch :docker-compose.yml
version: '3'
services:
elasticsearch:
image: elasticsearch:6.8.11
container_name: myES
environment:
- TZ="Asia/Shanghai"
- cluster.name=cluster1
- bootstrap.memory_lock=true
- "ES_JAVA_OPTS=-Xms512m -Xmx512m"
ulimits:
memlock:
soft: -1
hard: -1
volumes:
- /var/docker/elasticsearch/data:/usr/share/elasticsearch/data:rw
ports:
- 9200:9200
- 9300:9300
Kibana:docker-compose.yml
官网参考
https://www.elastic.co/guide/en/kibana/6.8/docker.html#docker
version: '3'
services:
kibana:
image: kibana:6.8.11
container_name: myKibana
ports:
- 5601:5601
environment:
TZ: "Asia/Shanghai"
SERVER_NAME: kibana
ELASTICSEARCH_HOSTS: http://elasticsearch.example.org
volumes:
- /var/docker/kibana/config:/usr/share/kibana/config
整合成一个docker-compose.yml
version: '3'
services:
elasticsearch:
image: elasticsearch:6.8.11
container_name: myES
restart: always
environment:
- TZ="Asia/Shanghai"
- cluster.name=cluster1
- bootstrap.memory_lock=true
- "ES_JAVA_OPTS=-Xms512m -Xmx512m"
ulimits:
memlock:
soft: -1
hard: -1
volumes:
- /var/docker/elasticsearch/data:/usr/share/elasticsearch/data:rw
ports:
- 9200:9200
- 9300:9300
kibana:
image: kibana:6.8.11
container_name: myKibana
restart: always
ports:
- 5601:5601
environment:
TZ: "Asia/Shanghai"
SERVER_NAME: kibana
ELASTICSEARCH_HOSTS: http://192.168.0.14:9200
#volumes:
# - /var/docker/kibana/config:/usr/share/kibana/config
springboot配置
spring:
data:
elasticsearch:
cluster-name: cluster1
cluster-nodes: 192.168.0.14:9300
repositories:
enabled: true
pom.xml
<!--elasticsearch-->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-elasticsearch</artifactId>
</dependency>
PageUtil.java
/**
* 获取Pageable
* @param pageIndex 前端从1开始
* @param pageSize
* @return
*/
static Pageable getPageable(Integer pageIndex, Integer pageSize, Sort sort){
Pageable pageable = null;
if (pageIndex != null && pageSize != null){
if (pageIndex < 1) {
pageIndex = 0;
} else {
pageIndex --;
}
if (pageSize < 1) {
pageSize = 10;
}
} else {
pageIndex = 0;
pageSize = Integer.MAX_VALUE;
}
if (sort != null) {
pageable = new PageRequest(pageIndex, pageSize, sort);
} else {
pageable = new PageRequest(pageIndex, pageSize);
}
return pageable;
}
ProjectSearchRepository.java
package com.meeno.chemical.extend.search.repository;
import com.meeno.chemical.extend.search.entity.ProjectSearch;
import org.springframework.data.elasticsearch.repository.ElasticsearchRepository;
/**
* @description: 项目搜索Repository
* @author: Wzq
* @create: 2020-08-06 15:23
*/
public interface ProjectSearchRepository extends ElasticsearchRepository<ProjectSearch,Long> {
}
SearchServiceImpl.java
package com.meeno.chemical.extend.search.service.impl;
import com.google.common.collect.Lists;
import com.meeno.chemical.extend.project.material.entity.Material;
import com.meeno.chemical.extend.search.entity.ProjectMaterialSearch;
import com.meeno.chemical.extend.search.entity.ProjectSearch;
import com.meeno.chemical.extend.search.repository.ProjectSearchRepository;
import com.meeno.chemical.extend.search.result.HighlightResultMapper;
import com.meeno.chemical.extend.search.service.ProjectSearchService;
import com.meeno.chemical.extend.search.view.ProjectSearchListView;
import com.meenoframework.util.PageData;
import com.meenoframework.util.PageUtil;
import org.elasticsearch.action.search.SearchResponse;
import org.elasticsearch.index.query.QueryBuilders;
import org.elasticsearch.search.SearchHit;
import org.elasticsearch.search.fetch.subphase.highlight.HighlightBuilder;
import org.elasticsearch.search.fetch.subphase.highlight.HighlightField;
import org.elasticsearch.search.sort.SortBuilders;
import org.elasticsearch.search.sort.SortOrder;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable;
import org.springframework.data.domain.Sort;
import org.springframework.data.elasticsearch.core.ElasticsearchTemplate;
import org.springframework.data.elasticsearch.core.SearchResultMapper;
import org.springframework.data.elasticsearch.core.aggregation.AggregatedPage;
import org.springframework.data.elasticsearch.core.query.NativeSearchQuery;
import org.springframework.data.elasticsearch.core.query.NativeSearchQueryBuilder;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.CollectionUtils;
import org.springframework.util.StringUtils;
import java.security.Key;
import java.util.ArrayList;
import java.util.List;
/**
* @description: 项目搜索ServiceImpl
* @author: Wzq
* @create: 2020-08-06 15:25
*/
@Service
@Transactional(rollbackFor = Exception.class)
public class ProjectSearchServiceImpl implements ProjectSearchService {
@Autowired
private ProjectSearchRepository projectSearchRepository;
@Autowired
private ElasticsearchTemplate elasticsearchTemplate;
@Override
public void save(ProjectSearch projectSearch) {
this.projectSearchRepository.save(projectSearch);
}
@Override
public void update(Long projectId, String name) {
ProjectSearch projectSearch = this.projectSearchRepository.findById(projectId).orElse(null);
if(projectSearch != null){
projectSearch.setProjectName(name);
this.projectSearchRepository.save(projectSearch);
}
}
@Override
public void update(Long projectId, List<Material> materialSearchList) {
ProjectSearch projectSearch = this.projectSearchRepository.findById(projectId).orElse(null);
if(projectSearch != null){
String materialsStr = "";
if(!CollectionUtils.isEmpty(materialSearchList)){
for (int i = 0; i < materialSearchList.size(); i++) {
if(i == materialSearchList.size()-1){
materialsStr += materialSearchList.get(i).getName();
}else{
materialsStr += materialSearchList.get(i).getName() + ",";
}
}
}
projectSearch.setMaterialsStr(materialsStr);
this.projectSearchRepository.save(projectSearch);
}
}
@Override
public void delete(Long id) {
this.projectSearchRepository.deleteById(id);
}
@Override
public ProjectSearch get(Long id) {
ProjectSearch projectSearch = this.projectSearchRepository.findById(id).orElse(null);
return projectSearch;
}
@Override
public List<ProjectSearch> findAll() {
Iterable<ProjectSearch> searchIterable = this.projectSearchRepository.findAll();
List<ProjectSearch> list = Lists.newArrayList();
searchIterable.forEach(search ->{
list.add(search);
});
return list;
}
@Override
public PageData<ProjectSearch> findPage(Integer pageIndex, Integer pageSize) {
Sort.Order createTimeDesc = Sort.Order.desc("createTime");
Sort sort = Sort.by(createTimeDesc);
Pageable pageable = PageUtil.getPageable(pageIndex, pageSize, sort);
Page<ProjectSearch> page = this.projectSearchRepository.findAll(pageable);
PageData<ProjectSearch> pageData = new PageData<>(page.getTotalElements(),page.getContent());
return pageData;
}
@Override
public PageData<ProjectSearch> findPageKeyword(Integer pageIndex, Integer pageSize, String keywords) {
Pageable pageable = PageUtil.getPageable(pageIndex, pageSize);
//高亮
String preTag = "<span style=‘color:red’>";
String postTag = "</font>";
// 构造查询条件
NativeSearchQueryBuilder queryBuilder = new NativeSearchQueryBuilder();
//keyworks为空查询全部
if(StringUtils.isEmpty(keywords)){
Sort.Order createTimeDesc = Sort.Order.desc("createTime");
Sort sort = Sort.by(createTimeDesc);
pageable = PageUtil.getPageable(pageIndex, pageSize,sort);
queryBuilder.withPageable(pageable);
}else{
queryBuilder.withQuery(QueryBuilders.multiMatchQuery(keywords,"projectName","materialsStr"))
.withHighlightFields(
new HighlightBuilder.Field("projectName").preTags(preTag).postTags(postTag),
new HighlightBuilder.Field("materialsStr").preTags(preTag).postTags(postTag)
)
.withPageable(pageable);
//对象嵌套查询
//queryBuilder.withQuery(QueryBuilders.matchQuery("materialSearchList.materialName",keywords))
// .withPageable(pageable);
}
NativeSearchQuery searchQuery = queryBuilder.build();
Page<ProjectSearch> searchPage = this.elasticsearchTemplate.queryForPage(searchQuery, ProjectSearch.class, new HighlightResultMapper());
//Page<ProjectSearch> searchPage = this.projectSearchRepository.search(searchQuery);
PageData<ProjectSearch> pageData = new PageData<>(searchPage.getTotalElements(),searchPage.getContent());
return pageData;
}
}
高亮处理类 HighlightResultMapper.java
package com.meeno.chemical.extend.search.result;
import com.alibaba.fastjson.JSON;
import org.elasticsearch.action.search.SearchResponse;
import org.elasticsearch.search.SearchHit;
import org.elasticsearch.search.SearchHits;
import org.elasticsearch.search.fetch.subphase.highlight.HighlightField;
import org.springframework.data.domain.Pageable;
import org.springframework.data.elasticsearch.core.SearchResultMapper;
import org.springframework.data.elasticsearch.core.aggregation.AggregatedPage;
import org.springframework.data.elasticsearch.core.aggregation.impl.AggregatedPageImpl;
import java.lang.reflect.Field;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
/**
* @description:
* @author: Wzq
* @create: 2020-08-07 12:40
*/
public class HighlightResultMapper implements SearchResultMapper {
@Override
public <T> AggregatedPage<T> mapResults(SearchResponse searchResponse, Class<T> clazz, Pageable pageable) {
long totalHits = searchResponse.getHits().getTotalHits();
List<T> list = new ArrayList<>();
SearchHits hits = searchResponse.getHits();
if (hits.getHits().length> 0) {
for (SearchHit searchHit : hits) {
Map<String, HighlightField> highlightFields = searchHit.getHighlightFields();
T item = JSON.parseObject(searchHit.getSourceAsString(), clazz);
Field[] fields = clazz.getDeclaredFields();
for (Field field : fields) {
field.setAccessible(true);
if (highlightFields.containsKey(field.getName())) {
try {
field.set(item, highlightFields.get(field.getName()).fragments()[0].toString());
} catch (IllegalAccessException e) {
e.printStackTrace();
}
}
}
list.add(item);
}
}
return new AggregatedPageImpl<>(list, pageable, totalHits);
}
/*@Override
public <T> T mapSearchHit(SearchHit searchHit, Class<T> aClass) {
return null;
}*/
}
参考文档
https://blog.csdn.net/tianyaleixiaowu/article/details/77965257
https://blog.csdn.net/weter_drop/article/details/104581758
可视化工具 dejavu
elasticsearch可视化 dejavu
https://github.com/appbaseio/dejavu
docker run -p 1358:1358 -d appbaseio/dejavu
http.port: 9200
http.cors.allow-origin: "*"
http.cors.enabled: true
http.cors.allow-headers : X-Requested-With,X-Auth-Token,Content-Type,Content-Length,Authorization
http.cors.allow-credentials: true
docker部署elasticsearch-+-Kibana(6-8)-+-SpringBoot-2-1-6的更多相关文章
- Docker部署Elasticsearch集群
http://blog.sina.com.cn/s/blog_8ea8e9d50102wwik.html Docker部署Elasticsearch集群 参考文档: https://hub.docke ...
- 【ELK】【docker】【elasticsearch】1. 使用Docker和Elasticsearch+ kibana 5.6.9 搭建全文本搜索引擎应用 集群,安装ik分词器
系列文章:[建议从第二章开始] [ELK][docker][elasticsearch]1. 使用Docker和Elasticsearch+ kibana 5.6.9 搭建全文本搜索引擎应用 集群,安 ...
- 【最新】docker 安装elasticsearch + kibana步骤【第一篇_elasticsearch】
最近在用docker 安装elasticsearch + kibana 遇到了很多坑,最后成功安装elasticsearch + kibana (6.8.1)版本 安装了一下午,现总结过程中遇到 ...
- Docker部署ElasticSearch以及使用
ElasticSearch笔记 1. ElasticSearch前期 1.1 聊聊ElasticSearch的简介 Elaticsearch,简称为es, es是一个开源的高扩展的分布式全文检索引 ...
- Centos8 Docker部署ElasticSearch集群
ELK部署 部署ElasticSearch集群 1.拉取镜像及批量生成配置文件 # 拉取镜像 [root@VM-24-9-centos ~]# docker pull elasticsearch:7. ...
- docker 运行 elasticsearch + kibana
一.elasticsearch的安装 1.从官网上拉取 elasticsearch 的镜像 docker pull elasticsearch:5.6.11docker images 2.运行容器 m ...
- docker安装Elasticsearch Kibana和Cerebro
环境:win10家庭版,基于Docker Toolbox 首先先做好以下两步准备工作: ①.打开Oracle VM VirtualBox,设置虚拟机内存大小,默认不够安装,建议如下设置: ②.启动虚拟 ...
- 【最新】docker 安装elasticsearch + kibana步骤【第二篇_kibana】
本文主要讲解Docker 安装 kibana并设置中文语言 [如果有需要安装elasticsearch 的朋友请移步博主第一篇文章] 话不多说! 第一步:docker 下载kibana docker ...
- Docker 安装 Elasticsearch+kibana
1 下载镜像 docker pull elasticsearch:7.4.1 docker pull kibana:7.4.1 拉取的镜像如下: 2 创建network 创建一个网络,名字任意取,使得 ...
- 使用 docker 进行 ElasticSearch + Kibana 集群搭建
在Docker容器中运行Elasticsearch Kibana和Cerebro 机器信息 10.160.13.139 10.160.9.162 10.160.11.171 1. 安装docker和d ...
随机推荐
- docker安装应用整理
nginx安装: docker run \ --name nginx \ --volume /var/data/nginx/nginx.conf:/etc/nginx/nginx.conf \ --v ...
- Nacos入门学习&实践
文中涉及到了一些模块代码没有给出,我一并上传到github了,可以整个项目clone下来进行调试. 地址:https://github.com/stronglxp/springcloud-test 1 ...
- JavaScript学习笔记:你必须要懂的原生JS(一)
1.原始类型有哪几种?null是对象吗?原始数据类型和复杂数据类型存储有什么区别? 原始类型有6种,分别是undefined,null,bool,string,number,symbol(ES6新增) ...
- python之数据驱动ddt操作(方法一)
下载ddt并安装 Pip install ddt 或者官网下载安装 http://ddt.readthedocs.io/en/latest/ https://github.com/txels/ddt ...
- P6295 有标号 DAG 计数
P6295 有标号 DAG 计数 题意 求 \(n\) 个点有标号弱联通 DAG 数量. 推导 设 \(f_i\) 表示 \(i\) 个点有标号 DAG 数量(不保证弱联通),有: \[f(i)=\s ...
- Cesium产品体系
Cesium是国外Analytical Graphics, Inc.公司开发的一款基于JavaScript 的使用WebGL的地图引擎.Cesium支持3D,2D,2.5D形式的地图展示,可以自行绘制 ...
- FreeRTOS-03-其它任务相关函数
说明: 本文仅作为学习FreeRTOS的记录文档,作为初学者肯定很多理解不对甚至错误的地方,望网友指正. FreeRTOS是一个RTOS(实时操作系统)系统,支持抢占式.合作式和时间片调度.适用于微处 ...
- Aria2 任意文件写入
访问aria2,发现服务已启动并且返回404页面 打开http://binux.github.io/yaaw/demo/#打开yaaw,点击配置按钮,填入运行aria2的目标域名:http://you ...
- WinUI 3学习笔记(2)—— 用ListView来展示集合
在WPF的时代,我们多是使用ListBox和ListView来展示,纵向滚动条显示的集合数据.这两个控件的默认样式,以及对触控的支持,已完全落后于时代.他们两个分别长这样,和Win10及Win11的风 ...
- mybatis动态sql总结
前言 平时在开发中,针对动态sql这块目前是薄弱点,自己根据官网在对应项目边测试边写博客,此篇只是为了加深动态sql的熟练度,有不到之处敬请批评指正! 1.if 使用动态 SQL 最常见情景是根据条件 ...