首页 / 知识
SpringBoot集成Elasticseach
2023-04-11 16:31:00

一、Elasticseach介绍
1.简单介绍
官网:
开源搜索:Elasticsearch、ELK Stack 和 Kibana 的开发者 | Elastic
https://www.elastic.co/cn/
ElasticSeach详细安装教程--图文介绍超详细:
ElasticSeach详细安装教程--图文介绍超详细_小小张自由—>张有博-CSDN博客
ElasticSeach详细安装教程--图文介绍超详细。Elasticsearch 是一个分布式、RESTful 风格的搜索和数据分析引擎,能够解决不断涌现出的各种用例。 作为 Elastic Stack 的核心,它集中存储您的数据,帮助您发现意料之中以及意料之外的情况。Elasticsearch 是一个基于JSON的分布式搜索和分析引擎。
https://blog.csdn.net/promsing/article/details/122722302
令人记忆深刻的口号:能够发现意料之中以及意料之外的情况
Elasticsearch也是基于Lucene的全文检索库,本质也是存储数据,很多概念与MySQL类似的。是一种全文检索技术。
Elasticsearch 是位于 Elastic Stack 核心的分布式搜索和分析引擎。Logstash 和 Beats 有助于收集、聚合和丰富您的数据并将其存储在 Elasticsearch 中。Kibana 使您能够以交互方式探索、可视化和分享对数据的见解,并管理和监控堆栈。Elasticsearch 是索引、搜索和分析魔法发生的地方。
Elasticsearch 是一个基于JSON的分布式搜索和分析引擎。
Elasticsearch是用Java语言开发的,并作为Apache许可条款下的开放源码发布,是一种流行的企业级搜索引擎。Elasticsearch用于云计算中,能够达到实时搜索,稳定,可靠,快速,安装使用方便。
2.对比关系:
索引(indices)--------------------------------Databases 数据库
类型(type)-----------------------------Table 数据表
文档(Document)----------------Row 行
字段(Field)-------------------Columns 列
3.详细说明:
概念
说明
索引库(indices)
indices是index的复数,代表许多的索引,
类型(type)
类型是模拟mysql中的table概念,一个索引库下可以有不同类型的索引,比如商品索引,订单索引,其数据格式不同。不过这会导致索引库混乱,因此未来版本中会移除这个概念
文档(document)
存入索引库原始的数据。比如每一条商品信息,就是一个文档
字段(field)
文档中的属性
映射配置(mappings)
字段的数据类型、属性、是否索引、是否存储等特性
4.查出数据的解释
took:查询花费时间,单位是毫秒
time_out:是否超时
_shards:分片信息
hits:搜索结果总览对象
total:搜索到的总条数
max_score:所有结果中文档得分的最高分
hits:搜索结果的文档对象数组,每个元素是一条搜索到的文档信息
_index:索引库
_type:文档类型
_id:文档id
_score:文档得分
_source:文档的源数据
二、SpringBoot集成Elasticseach
1.引入依赖
<dependencies>
<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>
</dependencies>
2.添加配置
spring:
data:
elasticsearch:
cluster-name: elasticsearch
cluster-nodes: 192.168.7.132:9300
3.创建pojo类与索引对应
package com.leyou.elasticsearch.pojo;
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;
/**
* 创建pojo类与索引对应
*
* @author Promsing(张有博)
* @version 1.0.0
* @since 2022/1/26 - 20:35
*/
@Document(indexName = "item", type = "docs", shards = 1, replicas = 0)
public class Item {
@Id
private Long id;
/**
* 标题
*/
@Field(type = FieldType.Text,analyzer = "ik_max_word")
private String title;
/**
* 分类
*/
@Field(type = FieldType.Keyword)
private String category;
/**
* 品牌
*/
@Field(type = FieldType.Keyword)
private String brand;
/**
* 价格
*/
@Field(type = FieldType.Double)
private Double price;
/**
* 图片地址
*/
@Field(type = FieldType.Keyword)
private String images;
public Long getId() {
return id;
}
public void setId(Long id) {
this.id = id;
}
public String getTitle() {
return title;
}
public void setTitle(String title) {
this.title = title;
}
public String getCategory() {
return category;
}
public void setCategory(String category) {
this.category = category;
}
public String getBrand() {
return brand;
}
public void setBrand(String brand) {
this.brand = brand;
}
public Double getPrice() {
return price;
}
public void setPrice(Double price) {
this.price = price;
}
public String getImages() {
return images;
}
public void setImages(String images) {
this.images = images;
}
public Item() {
}
public Item(Long id, String title, String category, String brand, Double price, String images) {
this.id = id;
this.title = title;
this.category = category;
this.brand = brand;
this.price = price;
this.images = images;
}
@Override
public String toString() {
return "Item{" +
"id=" + id +
", title='" + title + '\'' +
", category='" + category + '\'' +
", brand='" + brand + '\'' +
", price=" + price +
", images='" + images + '\'' +
'}';
}
}
|
最新内容
相关内容
用Python开发一个简单的猜数字游戏
用Python开发一个简单的猜数字游戏,数字,代码,培训,官网,设备,程序,玩家,注释,内容,游戏,本文介绍如何使用Python制作一个简单的猜数字游戏。Python进程、线程、协程的区别
Python进程、线程、协程的区别,地址,单位,线程,入口,状态,培训,进程,区别,资源,空间,简述进程、线程、协程的区别以及应用场景?线程是指进程python内置函数:map、reduce、filte
python内置函数:map、reduce、filter的用法和区别,数据,培训,数字,函数,序列,内容,元素,参数,列表,个数,map:根据函数对指定序列做映射map参数python如何调用另一个文件夹中的内
python如何调用另一个文件夹中的内容?,系统,培训,文件,模块,内容,路径,函数,所在,前缀,语句,python中调用另外一个文件夹中的内容:1、同一文件python中怎么对一个数进行因式分解
python中怎么对一个数进行因式分解?,代码,培训,因式分解,因数,个数,最小,整数,数组,假定,分解,1、Python因式分解代码:importtime#对一个数进python怎么在数组添加一行?
python怎么在数组添加一行?,培训,下标,维度,数组,列表,函数,形状,元素,代表,原型,python中在数组添加一行的方法:python中可以使用stack()函数python函数里面形参和实参一样吗?
python函数里面形参和实参一样吗?,培训,函数,参数,里面,变量,实际,形式,全称,示例,后面,python函数里面形参和实参不一样。形参全称是形式参python判断xml是否存在某一节点?
python判断xml是否存在某一节点?,数据,培训,节点,方法,结果,表达式,长度,以上,更多,内容,python中判断xml是否存在某一节点的方法:使用selectNpython是一种编程语言吗?
python是一种编程语言吗?,放宽,适当,平台,培训,语言,指令,计算机,机器,程序,解释性,python是一种编程语言,Python是一种跨平台的计算机程序设计python如何获取字符串最后一个字符
python如何获取字符串最后一个字符?,培训,字符串,方括号,字符,方法,引号,变量,数据类型,结尾,分配,python获取字符串最后一个字符的方法:字符python怎么import另一个python文件
python怎么import另一个python文件?,系统,培训,文件,模块,函数,路径,所在,前缀,示例,语句,python使用import导入python文件的方法:示例:有a.pypython中怎么将元组、字典转化为列
python中怎么将元组、字典转化为列表,培训,列表,字典,方法,元素,示例,中将,语法,以上,参数,python中将元组、字典转化为列表的方法:python中可