ES installation and deployment

ES installation and deployment

1.elasticsearch installation and deployment

1.1 Installation

Download address : https://www.elastic.co/cn/downloads/ (I downloaded 7.6.1)
and then unzip it

1.2 Directory

insert image description here
1. bin startup file directory
2. config configuration file directory
        1og4j2 log configuration file
         jvm.options java virtual machine related configuration
         elasticsearch.ym1 elasticsearch configuration file!
3. lib related jar package
4. modules functional module directory
5. plugins plug-in directory

1.3 start

Check whether your Java environment is configured and
insert image description here
double-click , and you can see the following content in normal operation

insert image description hereEnter in the URL: localhost:9200 to test it, and see the following instructions to start successfully!
insert image description here

1.4 Install the visual interface

elasticsearch-head

(Only as a data display tool, use kibana for query statements)

1. Download address : https://github.com/mobz/elasticsearch-head
2. Installation : Just unzip
3. Start :

cd elasticsearch-head 
#安装相关依赖
npm install
#启动
npm run start
#访问
http://localhost:9100/

As follows:
insert image description here

At this time, there is a cross-domain problem (only when the two pages have the same origin, can they interact) Same
origin (port, host, and protocol are all the same)
Enable cross-domain: Add to elasticsearch.yml under the elasticsearch decompression directory config:

# 开启跨域
http.cors.enabled: true
# 所有人访问
http.cors.allow-origin: "*"

Restart elasticsearch
access URL: http://localhost:9100, connect
insert image description here

1.5 ElasticSearch installed as a Windows service

1. There is an elasticsearch-service.bat in the bin directory of elasticsearch
2. cmd enters the bin directory and executes: elasticsearch-service.bat install
insert image description here
3. Check that the computer service es already exists

install kibana

1. Installation

1. Download address: https://www.elastic.co/cn/downloads/
2. Installation: Unzip it
3. Start: Double-click
insert image description here
insert image description here
to access the URL: http://localhost:5601
kibana Sinicization: editor opens /config/ kibana.yml, add: i18n.locale: "zh-CN"
restart kibana: finished
insert image description here

2. Basic use:

Basic Rest command description:
insert image description here

2.1 Index and document creation, query, update, deletion

1. Create:
(1) Index creation

PUT /索引名

insert image description here
(2) Creation of documents

PUT /索引名/文档类型/文档id

insert image description here
View in elasticsearch-head, add successfully
insert image description here(3) Create index rules
insert image description here
insert image description here
2. Query:

(1) Get index information

GET 索引名
#获取该索引信息 

GET 索引名/_mapping
#获取索引的映射规则

insert image description here
insert image description here
(2) Get document information

GET 索引名/类型名/文档id

insert image description here
(3) Supplement the commonly used command GET _cat/... to obtain the information of the es cluster

GET _cat/health
#查看集群的健康值

GET _cat/indices?v
#查看es包含的所有索引的信息

insert image description here
insert image description here

Some Complex Queries: Query Matching

match:匹配(会使用分词器解析(先分析文档,然后进行查询))

_source:过滤字段

sort:排序

form、size 分页

insert image description here
Multi-condition query:

must 相当于 and
should 相当于 or
must_not 相当于 not (... and ...)
filter 过滤

insert image description here

3. Index update:
first create an index and add three pieces of data to it:
insert image description here

POST /索引名/类型名/文档id/_update
#修改索引内容,一定要注意加上"doc"标签

insert image description here
4. Delete:
(1) Delete the index

DELETE 索引名

insert image description here
(2) Delete a document in the index

DELETE 索引名/类型名/文档id

insert image description here

3. Index and document query

1. Simple query

<Here I installed the ik tokenizer myself, so partial matching can be achieved>

GET /test2/_search?q=name:"张"
#获取test2索引中名字中含有"张"的文档信息

insert image description here

2. Complex query

1. Fuzzy query

#match是模糊查询,term是精确查询。

#term和match只管传入的查询条件是否分词,比如“晚会”使用match可以被分词成“晚”“会”两个词进行查询,term不分词就直接用“晚会”进行查询。
#(总结,模糊查询既拆分输入的关键字,也拆分被查询的字段;精确查询只拆分被查询的字段)

insert image description here
insert image description here

2. Filter the fields you don't want to see

_source: []
#过滤字段

insert image description here

3. Sort

sort:
#排序

At this time, I added some test data to test2, sorted
insert image description here
by age as follows
insert image description here

4. Paging query

from:从查询结果的第几个开始显示
size:一个页面显示几个

insert image description here

5. Boolean value bool query

must:相当于逻辑与 AND
should: 相当于逻辑或 OR
must_not: 实现的是“逻辑非”NOT
filter:过滤器

insert image description here
must:
insert image description here
should:
insert image description here
must_not:
insert image description here
filter:
insert image description here

6. Multi-condition query of fuzzy query

#多个条件直接用“空格”隔开,这一点比MySQL数据库查询方便得多。

insert image description here

7. Highlight query and custom highlight style

insert image description here
insert image description here

3. Aggregation query

Two core concepts bucket, metric:

对每个组内的数据进行聚合分析,分组,就是bucket
对一个bucket执行的某种聚合分析的操作,比如说求平均值,求最大值,求最小值,就是metric

Now create a new index in es and add three pieces of data:
insert image description here
1. Calculate the quantity of each product according to the product name

#size:只获取聚合结果,而不执行聚合原始数据
#aggs:固定语法,要对一份数据执行分组聚合操作
#group_by_name:就是对每个aggs,都要起一个名字,这个名字是随机的,你随便取什么都ok
#terms:根据字段的值进行分组
#field:根据指定的字段的值进行分组
对于返回的数据:
#hits.hits:指定了size是0,所以hits.hits为空,否则会把执行聚合的那些原始数据给你返回回来
#aggregations:聚合结果                         
#group_by_name:我们指定的某个聚合的名称
#buckets:根据我们指定的field划分出的buckets           
#key:每个bucket对应的那个值
#doc_count:这个bucket分组内,有多少个数据          
 默认的排序规则:按照doc_count降序排序

insert image description here

2. Count the number of Zhengzhou area

insert image description here
3. Calculate the average price/minimum price/maximum price/total price of each commodity

#count:buckets,terms,自动就会有一个doc_count,就相当于是count
#avg:avg aggs 求平均值
#max:求一个bucket内,指定field值最大的那个数据
#min:求一个bucket内,指定field值最小的那个数据
#sum:求一个bucket内,指定field值的总和先分组,再算每组的平均值

insert image description here
4. Calculate the average price first, and then sort the average price from large to small

"collect_mode"
#对于子聚合的计算,有两种方式:
#depth_first 直接进行子聚合的计算
#breadth_first 先计算出当前聚合的结果,针对这个结果在对子聚合进行计算。
"order": {
    
     "avg_price": "desc" }

insert image description here
5. Group according to the specified price range, then group by name within each group, and finally calculate the average price of each group

"ranges": [{
    
    },{
    
    }]

insert image description here

Guess you like

Origin blog.csdn.net/qq_46533159/article/details/126717885
Recommended