Es环境搭建 ▎kibana组件 ▎ik分词器 ▎idea继承Es ▎idea中Es操作

目录

安装Es

安装Es可视化界面(elasticsearch-head)

elasticsearch-head安装:

安装可视化Kibana组件

汉化kibana

[​编辑 启动服务器:](#编辑 启动服务器:)

安装ik分词器插件

Idea继承Es

索引库操作

文档操作


安装Es

Es下载地址:

ES下载地址https://www.elastic.co/cn/downloads/elasticsearch

解压并在打开bin目录

在bin目录中双击启动elasticsearch.bat

使用访问127.0.0.1:9200地址

网页显示如:

安装Es可视化界面(elasticsearch-head)

安装前提:需要安装nodejs

安装教程https://blog.csdn.net/Dreamkidya/article/details/140017222?spm=1001.2014.3001.5501

elasticsearch-head安装:

elasticsearch-head安装地址https://github.com/mobz/elasticsearch-head/

解压并配置elasticsearch.yml文件

添加跨域访问

启动可视化界面服务

访问127.0.0:9100进入可视界面

网页效果:

安装可视化Kibana组件

Kibana 是一个针对Elasticsearch的开源分析及可视化平台,用来搜索、查看交互 存储在Elasticsearch 索引中的数据。

使用Kibana,可以通过各种图表进行高级数据分析及展示。Kibana让海量数据更 容易理解。

下载版本需要和Es版本一致

下载地址:

kibana下载地址(默认为最新版本)https://www.elastic.co/cn/downloads/kibana

汉化kibana

修改config 目录下的kibana.yml 文件 i18n.locale: "zh-CN"

启动服务器:

双击bin目录下的kibana.bat启动

网页访问127.0.0:5601

安装ik分词器插件

下载地址:

注:与es版本一致

**下载地址https://github.com/medcl/elasticsearch-analysis-ik/releases/download/v7.6.1/elasticsearchanalysis-ik-7.6.1.zip**解压,在elasticsearch-7.6.1\plugins目录下创建名称为ik的文件夹,将解压后的文件复 制到ik目录

注:一定要解压在elasticsearch-7.6.1\plugins目录下

Idea继承Es

第一步:指定jdk与es版本

复制代码
    <!--指定 jdk 版本-->
    <properties>
        <java.version>1.8</java.version>
      <!-- Es版本-->
        <elasticsearch.version>7.6.1</elasticsearch.version>
    </properties>

第二步:添加依赖

复制代码
<!-- Es-->
<dependency>
    <groupId>org.elasticsearch.client</groupId>
    <artifactId>elasticsearch-rest-high-level-client</artifactId>
</dependency>

第三步:添加初始化RestHighLevelClient的配置类

java 复制代码
package com.kid.news.config;

import org.apache.http.HttpHost;
import org.elasticsearch.client.RestClient;
import org.elasticsearch.client.RestHighLevelClient;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class ElasticSearchConfig {

    @Bean
    public RestHighLevelClient restHighLevelClient(){
        RestHighLevelClient client = new RestHighLevelClient(
                RestClient.builder(new HttpHost("localhost", 9200, "http")));
        return client;
    }

}

索引库操作

创建索引库

CreateIndexRequestrequest=newCreateIndexRequest("users"); CreateIndexResponsecreateIndexResponse=restHighLevelClient.indices().create(request, RequestOptions.DEFAULT);

判断索引库是否存在

GetIndexRequestrequest=newGetIndexRequest("users"); booleanexists=restHighLevelClient.indices().exists(request,RequestOptions.DEFAULT);

删除索引库

DeleteIndexRequestindexRequest=newDeleteIndexRequest("users"); AcknowledgedResponsedelete=restHighLevelClient.indices().delete(indexRequest, RequestOptions.DEFAULT); delete.isAcknowledged();//返回true删除成功,返回false删除失败

文档操作

添加文档

Newsnews =newNews(); news.setId(3); news.setTitle("中国航母开往美国,准备开战,拜登着急了"); news.setImg("dddddddddddd.jpg"); UpdateRequestupdateRequest=newUpdateRequest("news",news.getId().toString()); updateRequest.doc(newObjectMapper().writeValueAsString(news),XContentType.JSON); restHighLevelClient.update(updateRequest,RequestOptions.DEFAULT);

修改文档

Newsnews =newNews(); news.setId(3); news.setTitle("中国航母开往美国,准备开战,拜登着急了"); news.setImg("dddddddddddd.jpg"); UpdateRequestupdateRequest=newUpdateRequest("news",news.getId().toString()); updateRequest.doc(newObjectMapper().writeValueAsString(news),XContentType.JSON); restHighLevelClient.update(updateRequest,RequestOptions.DEFAULT);

查询文档

GetRequestgetRequest=newGetRequest("news","1"); GetResponsegetResponse=restHighLevelClient.get(getRequest,RequestOptions.DEFAULT); //获取查询的内容,返回json格式 Stringjson=getResponse.getSourceAsString(); //使用jackson组件将json字符串解析为对象 Newsnews=newObjectMapper().readValue(json,News.class);

删除文档

DeleteRequestdeleteRequest=newDeleteRequest("news","1"); DeleteResponsedelete=restHighLevelClient.delete(deleteRequest,RequestOptions.DEFAULT);

搜索文档

SearchRequestsearchRequest=newSearchRequest("news"); SearchRequestsearchRequest=newSearchRequest("news"); //精确条件查询 searchRequest.source().query(QueryBuilders.termQuery("title","美国")); //发送查询请求 SearchResponsesearch=restHighLevelClient.search(searchRequest,RequestOptions.DEFAULT); //接收查询结果 SearchHitshits=search.getHits(); //组装查询结果 ArrayListlist=newArrayList<>(); //取出结果集 for(SearchHitsearchHit:hits.getHits()){ Stringjson=searchHit.getSourceAsString(); Newsnews=newObjectMapper().readValue(json,News.class); list.add(news);

}



感谢大家的观看,本次分享就到这里。希望我的内容能够对您有所帮助。创作不易,欢迎大家多多支持,您的每一个点赞都是我持续更新的最大动力!如有不同意见,欢迎在评论区积极讨论,让我们一起学习、共同进步!如果有相关问题,也可以私信我,我会认真查看每一条留言。期待下次再见!

希望路飞的笑容可以治愈努力路途中的你我!

博主vx:Dreamkid05 --->欢迎大家和博主讨论问题

相关推荐
物联网软硬件开发-轨物科技37 分钟前
【轨物洞见】什么是产品碳足迹(PCF)?ISO 14067 计算方法与应用场景深度解读
大数据·网络·人工智能
GlobalInfo1 小时前
2026年全球无人机清洗系统市场深度分析:规模、竞争格局与AI自主作业演进趋势
大数据·人工智能·ai·无人机
AI职业加油站1 小时前
AI 校招现状:大模型应用工程师证书,助力简历能力证明
大数据·运维·人工智能·学习·职场发展
cc5725026531 小时前
2027 秋招求职分析:大数据相关专业,企业服务售前与实施岗位对比
大数据
专注API从业者2 小时前
告别复杂页面解析,OpenClaw 快速搭建电商商品监控与数据分析脚本
大数据·数据库·python·数据挖掘·数据分析
楚楚2512 小时前
2026企业AI办公工具选型指南:从需求匹配到平台评估
大数据·人工智能
SelectDB2 小时前
Apache Doris x Fluss:面向湖流一体的统一查询与分析
大数据·数据库·数据分析
论文复现现场2 小时前
金融大模型微调需要几张 RTX 4090?QLoRA 配置、工期估算与断点续训
大数据·金融·大模型·分布式训练·模型微调·qlora·rtx4090
阿乔外贸日记3 小时前
全球电子产业高度集中:中、韩、日和中国台湾地区占全球数字硬件产能八成
大数据·服务器·人工智能·物联网·云计算
飞飞传输3 小时前
业务系统文件安全检测怎么做?生物医药企业选型与建设指南
大数据·运维·安全