当前位置:网站首页>After going to the bathroom, I figured out the ES search server
After going to the bathroom, I figured out the ES search server
2022-06-12 09:09:00 【Eden Garden】
1、 Concept
- ElasticSearch It's based on Lucene Search server for

- It's a distribution 、 High expansion 、 High real time search and data analysis engine
- be based on RESTful web Interface
- Elasticsearch Yes, it is Java Language development , The bottom is Lucene
- It is often used to query massive amounts of information
Supplementary knowledge :
Elasticsearch yes ELK A component of , Is one of the products , And it's a perfect product ,ELK It stands for :E Namely ElasticSearch,L Namely Logstach( Data acquisition and synchronization , The operation log ),K Namely kibana( Data visualization analysis )
2、ElasticSearch The core concept
Indexes (index)
ElasticSearch Where to store data , It can be understood as the database concept in relational database .
mapping (mapping)
mapping Defines the type of each field 、 The word breaker used by the field, etc . It is equivalent to the table structure in relational database .
file (document)
Elasticsearch The smallest data unit in , Often in json Format display . One document Equivalent to a row of data in a relational database .
Inverted index
An inverted index consists of a list of all non repeating words in a document , For each of these words , Corresponding to a document containing it id list .
The inverted index is es At the heart of , We normally operate the database according to ID Search content , An inverted index is a search based on content ID, Then take it ID To find out what you really need .
type (type)
A kind of type It's like a kind of watch . Such as user table 、 Role sheets, etc . stay Elasticsearch7.* Default type by _doc.
Summarizing the above will Elasticsearch Compare with relational data terms :
relational database ⇒ database ⇒ surface ⇒ That's ok ⇒ Column (Columns)
Elasticsearch ⇒ Indexes (Index) ⇒ type (type) ⇒ file (Docments) ⇒ Field (Fields)
3、es Index and mysql The difference between indexes
Speaking of ES The index of , Then we can't help thinking MySQL The index of , So what is the difference between them , I believe everyone knows that this is a question that interviewers like to ask .
Database index It's a separate 、 Physical A storage structure that sorts the values of one or more columns in a database table , You can think of it as something like a book catalog , You can easily find what you want through the directory .
Need to know MySQL5.5 Later versions of the index use B+Tree, But why use B+Tree He tried his best to optimize for a long time. If you want to know more, please see once , I thought I understood MySQL Indexes I only put one picture here , Everyone knows , If you don't understand, just read the above link and learn more deeply !
ES Indexes , stay ES What is used in is Inverted index , So what is an inverted index ? For the convenience of understanding, we first introduce Forward index
Forward index is the document. (Document) And its fields Fields The relationship of positive correspondence : Also is to use id Search content
| id | book | content |
|---|---|---|
| 1 | In the Quiet Night | abed, I see a silver light , The frost on the ground |
| 2 | to | When is the moon ? Drink to the sky |
| 3 | The full moon bosom far | Marine moon , Horizon time |
Inverted index is to use the content to find the corresponding id
| content | id |
|---|---|
| bright moon | 【1,2,3】 |
| In front of the bed | 【1】 |
| The sea | 【3】 |
The inverted index is clear , But how to query efficiently ?
Here we refer to two new concepts :Term Dictionary,Term Index
We split a text into separate ones Term Actually, it is the participle we often say . And put all Term Together, it's one Term Dictionary, It can also be called a dictionary of words . But too many participles are not efficient , So there is the introduction of Term Index, We are Term Dictionary Create an index and put it in memory , This reduces io frequency , Improved query efficiency .
4、RESTful Style operation
Operating index
# add to
PUT http://ip: port / The index name
# Inquire about
GET http://ip: port / The index name # Query single index information
GET http://ip: port / The index name 1, The index name 2... # Query multiple index information
GET http://ip: port /_all # Query all index information
# Delete
DELETE http://ip: port / The index name
# close 、 Open the index
POST http://ip: port / The index name /_close
POST http://ip: port / The index name /_open
Operation mapping
# Create an index and add a map
PUT /person
{
"mappings": {
"properties": {
"name": {
"type": "text"
},
"age": {
"type": "integer"
}
}
}
}
# Query mapping
GET person/_mapping
# Add fields
PUT /person/_mapping
{
"properties": {
"name": {
"type": "text"
},
"age": {
"type": "integer"
}
}
}
Operation document
Add the document , Appoint id
POST /person/_doc/1
{
"name":" Zhang San ",
"age":18,
"address":" Beijing "
}
# Query all documents
GET /person/_doc/1
# Query all documents
GET /person/_search
# Add the document , Don't specify id
POST /person1/_doc/
{
"name":" Zhang San ",
"age":18,
"address":" Beijing "
}
# Delete the specified id file
DELETE /person/_doc/1
5、 Word segmentation is
IKAnalyzer It's an open source , be based on java Language development of lightweight Chinese word segmentation toolkit .
IK Two word segmentation modes are provided : Intelligent patterns and fine-grained patterns
{ intelligence ( Group granularity ): Corresponding es Of IK The plug-in ik_smart, fine-grained : Corresponding es Of IK The plug-in ik_max_word }
6、SpringBoot Integrate ES
① build SpringBoot engineering
② introduce ElasticSearch Related coordinates
<!-- introduce es Coordinates of -->
<dependency>
<groupId>org.elasticsearch.client</groupId>
<artifactId>elasticsearch-rest-high-level-client</artifactId>
<version>7.4.0</version>
</dependency>
<dependency>
<groupId>org.elasticsearch.client</groupId>
<artifactId>elasticsearch-rest-client</artifactId>
<version>7.4.0</version>
</dependency>
<dependency>
<groupId>org.elasticsearch</groupId>
<artifactId>elasticsearch</artifactId>
<version>7.4.0</version>
</dependency>
application.yml
elasticsearch:
host: 192.168.200.128
port: 9200
③ test
ElasticSearchConfig
@Configuration
@ConfigurationProperties(prefix="elasticsearch")
public class ElasticSearchConfig {
private String host;
private int port;
public String getHost() {
return host;
}
public void setHost(String host) {
this.host = host;
}
public int getPort() {
return port;
}
public void setPort(int port) {
this.port = port;
}
@Bean
public RestHighLevelClient client(){
return new RestHighLevelClient(RestClient.builder(
new HttpHost(host,port,"http")
));
}
}
@SpringBootTest
class ElasticsearchDay01ApplicationTests {
@Autowired
RestHighLevelClient client;
/** * test */
@Test
void contextLoads() {
System.out.println(client);
}
}
1. Add index
/** * Add index * @throws IOException */
@Test
public void addIndex() throws IOException {
//1. Use client Get operation index object
IndicesClient indices = client.indices();
//2. The specific operation is to obtain the return value
//2.1 Set index name
CreateIndexRequest createIndexRequest=new CreateIndexRequest("itheima");
CreateIndexResponse createIndexResponse = indices.create(createIndexRequest, RequestOptions.DEFAULT);
//3. Judge the result according to the return value
System.out.println(createIndexResponse.isAcknowledged());
}
2. Add index , And add the mapping
/** * Add index , And add the mapping */
@Test
public void addIndexAndMapping() throws IOException {
//1. Use client Get operation index object
IndicesClient indices = client.indices();
//2. The specific operation is to obtain the return value
//2. Specific operation , Get the return value
CreateIndexRequest createIndexRequest = new CreateIndexRequest("itcast");
//2.1 Set up mappings
String mapping = "{\n" +
" \"properties\" : {\n" +
" \"address\" : {\n" +
" \"type\" : \"text\",\n" +
" \"analyzer\" : \"ik_max_word\"\n" +
" },\n" +
" \"age\" : {\n" +
" \"type\" : \"long\"\n" +
" },\n" +
" \"name\" : {\n" +
" \"type\" : \"keyword\"\n" +
" }\n" +
" }\n" +
" }";
createIndexRequest.mapping(mapping,XContentType.JSON);
CreateIndexResponse createIndexResponse = indices.create(createIndexRequest, RequestOptions.DEFAULT);
//3. Judge the result according to the return value
System.out.println(createIndexResponse.isAcknowledged());
}
3. Query index
/** * Query index */
@Test
public void queryIndex() throws IOException {
IndicesClient indices = client.indices();
GetIndexRequest getRequest=new GetIndexRequest("itcast");
GetIndexResponse response = indices.get(getRequest, RequestOptions.DEFAULT);
Map<String, MappingMetaData> mappings = response.getMappings();
//iter Tips foreach
for (String key : mappings.keySet()) {
System.out.println(key+"==="+mappings.get(key).getSourceAsMap());
}
}
4. Delete index
/** * Delete index */
@Test
public void deleteIndex() throws IOException {
IndicesClient indices = client.indices();
DeleteIndexRequest deleteRequest=new DeleteIndexRequest("itheima");
AcknowledgedResponse delete = indices.delete(deleteRequest, RequestOptions.DEFAULT);
System.out.println(delete.isAcknowledged());
}
边栏推荐
- Codecraft-22 and codeforces round 795 (Div. 2)
- 第三章 寄存器 (内存访问)
- Implementing architecture caching in MySQL under redis server environment
- torch.logical_and()方法
- mySql学习记录——二、mySql建表命令
- MFS详解(四)——MFS管理服务器安装与配置
- 90%以上软件公司都会问的软件测试面试题赶紧来背吧
- Sword finger offer:[day 8 dynamic planning (simple)] --- > frog jumping on steps
- Leetcode689 wrong greedy thinking
- (JS) three digits are separated by commas, and two decimal places are reserved (or rounded)
猜你喜欢
![[computer use] how to change a computer disk into a mobile disk?](/img/ff/843f4220fcaefc00980a6edc29aebf.jpg)
[computer use] how to change a computer disk into a mobile disk?

Description of string

Multi table operation instance
测试用例和bug描述规范参考

ISCSI详解(五)——ISCSI客户端配置实战

Detailed explanation of iSCSI (V) -- actual operation of iSCSI client configuration

Application method of new version UI of idea + use method of non test qualification and related introduction

Es6-- common basic knowledge

Minimum transfer times

Flink传入自定义的参数或配置文件
随机推荐
Technology cloud report: how will the industrial Internet rebuild the security boundary in 2022?
Filters and listeners
(js)三位用逗号隔开,保留两位小数(or 四舍五入取整)
Notes used by mqtt (combined with source code)
Source code and scheme for target recognition, detection and 6D attitude estimation (the most advanced method and data set)
Meeting time (topology sorting +dp)
重启Kubernetes Pod的几种方式
ip、DNS、域名、URL、hosts
Basic knowledge of Linear Algebra -- concepts and relationships of common matrices
解压缩zip文件的工具类
2022 safety officer-c certificate special operation certificate examination question bank and simulation examination
Unittest测试框架
Subtractive integer (number theory)
[character set 6] wide string and multi byte character conversion
Offer:[day 8 dynamic planning (simple)] --- > maximum profit of stock
Xshell startup encountered "unable to continue code execution because mfc110.dll cannot be found"
目标识别、检测和 6D 姿态估算源码与方案(最先进的方法和数据集)
[character set 7] what are the wide character codes and multi byte codes of Chinese characters
2024. 考试的最大困扰度-滑动窗口
Detailed explanation of iSCSI (V) -- actual operation of iSCSI client configuration