-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
277 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{ | ||
"graph": false | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
查询所有:查询出所有数据,一般测试使用,match_all,不会返回全部数据,有限制条数啦。 | ||
全文检索:利用分词器对查询文本进行分词,然后匹配倒排索引库,然后拿到文档的 ID,计算得分,根据 ID 查询文档。 | ||
- match_query | ||
- match | ||
- multi_match_query | ||
精确查询:根据精确的词条查找数据,一般查询 keyword、数值、日期、boolean 等类型字段。 | ||
- ids | ||
- range | ||
- term | ||
地理查询:根据经纬度查询。 | ||
- geo_distance | ||
- geo_bounding_box | ||
复合查询:将上述的查询条件组合起来,合并查询条件。 | ||
- bool | ||
- function_score | ||
|
||
基本语法 | ||
``` | ||
GET /indexName/_search | ||
{ | ||
"query": { | ||
"查询类型": { | ||
"查询条件": "条件值" | ||
} | ||
} | ||
} | ||
``` | ||
|
||
查询示例 | ||
``` | ||
# 查询全部 | ||
GET /book/_search | ||
{ | ||
"query": { | ||
"match_all": {} | ||
} | ||
} | ||
# 全文检索,单字段 | ||
GET /book/_search | ||
{ | ||
"query": { | ||
"match": { | ||
"all": "Java" | ||
} | ||
} | ||
} | ||
# 全文检索,多字段,可以使用 * 表示全部字段 | ||
GET /book/_search | ||
{ | ||
"query": { | ||
"multi_match": { | ||
"query": "Java", | ||
"fields": ["name", "author"] | ||
} | ||
} | ||
} | ||
# 精确查询词条查询 | ||
GET /book/_search | ||
{ | ||
"query": { | ||
"term": { | ||
"name": { | ||
"value": "Java 揭秘" | ||
} | ||
} | ||
} | ||
} | ||
# 精确查询范围查询 | ||
GET /boot/_search | ||
{ | ||
"query": { | ||
"range": { | ||
"public_year": { | ||
"gte": 2013, | ||
"lte": 2034 | ||
} | ||
} | ||
} | ||
} | ||
``` |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,98 @@ | ||
创建网络 | ||
```shell | ||
docker network create elastic-net | ||
``` | ||
|
||
配置密码 | ||
``` | ||
export ELASTIC_PASSWORD="<ES_PASSWORD>" # password for "elastic" username | ||
export KIBANA_PASSWORD="<KIB_PASSWORD>" # Used _internally_ by Kibana, must be at least 6 characters long | ||
``` | ||
|
||
Docker 安装 ES | ||
```shell | ||
docker run -p 9200:9200 -itd --name elasticsearch --network elastic-net \ | ||
-e ELASTIC_PASSWORD=$ELASTIC_PASSWORD \ | ||
-e "discovery.type=single-node" \ | ||
-e "xpack.security.http.ssl.enabled=false" \ | ||
-e "xpack.license.self_generated.type=basic" \ | ||
docker.elastic.co/elasticsearch/elasticsearch:8.12.2 | ||
``` | ||
|
||
|
||
|
||
Docker 安装 Kibana | ||
|
||
初始化 `kibana_system` 用户密码 | ||
```shell | ||
curl -u elastic:$ELASTIC_PASSWORD \ | ||
-X POST \ | ||
http://localhost:9200/_security/user/kibana_system/_password \ | ||
-d '{"password":"'"$KIBANA_PASSWORD"'"}' \ | ||
-H 'Content-Type: application/json' | ||
``` | ||
|
||
安装 Kibana | ||
```shell | ||
docker run -p 5601:5601 -itd --name kibana --network elastic-net \ | ||
-e ELASTICSEARCH_URL=http://elasticsearch:9200 \ | ||
-e ELASTICSEARCH_HOSTS=http://elasticsearch:9200 \ | ||
-e ELASTICSEARCH_USERNAME=kibana_system \ | ||
-e ELASTICSEARCH_PASSWORD=$KIBANA_PASSWORD \ | ||
-e "xpack.security.enabled=false" \ | ||
-e "xpack.license.self_generated.type=basic" \ | ||
docker.elastic.co/kibana/kibana:8.12.2 | ||
``` | ||
|
||
完成安装了 ES 和 Kibana, | ||
ES 地址:http://192.168.31.11:9200, | ||
ES 有两个用户 | ||
- 管理员用户 elastic/$ELASTIC_PASSWORD。 | ||
- Kibana 容器连接用户 kibana_system/$KIBANA_PASSWORD | ||
Kibana 地址:http://192.168.31.11:5601,使用 ES 管理员用户登录即可。 | ||
|
||
ES 配置中文分词器 | ||
下载分词器安装包,https://github.com/infinilabs/analysis-ik/releases,注意版本匹配。 | ||
```shell | ||
unzip elasticsearch-analysis-ik-8.12.2.zip -d ik | ||
docker cp ik/ elasticsearch:/usr/share/elasticsearch/plugins/ | ||
docker restart elasticsearch | ||
``` | ||
|
||
测试 ik 分词器 | ||
```text | ||
POST /_analyze | ||
{ | ||
"analyzer": "standard", | ||
"text": "nice to meet you 我是程序员!" | ||
} | ||
POST /_analyze | ||
{ | ||
"analyzer": "ik_smart", | ||
"text": "nice to meet you 我是程序员!" | ||
} | ||
POST /_analyze | ||
{ | ||
"analyzer": "ik_max_word", | ||
"text": "nice to meet you 我是程序员!" | ||
} | ||
``` | ||
|
||
ik 分词器支持配置扩展词和停止词。如果 ik 自带的字典里面没有相关词汇,默认分成一个一个字,扩展词典可以配置相关的词避免分成一个一个字。停止词可以配置一些语气词或者冠词或者一些敏感词,那么分词的时候这些词就会忽略掉。 | ||
```xml | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<!DOCTYPE properties SYSTEM "http://java.sun.com/dtd/properties.dtd"> | ||
<properties> | ||
<comment>IK Analyzer 扩展配置</comment> | ||
<!--用户可以在这里配置自己的扩展字典 --> | ||
<entry key="ext_dict"></entry> | ||
<!--用户可以在这里配置自己的扩展停止词字典--> | ||
<entry key="ext_stopwords"></entry> | ||
<!--用户可以在这里配置远程扩展字典 --> | ||
<!-- <entry key="remote_ext_dict">words_location</entry> --> | ||
<!--用户可以在这里配置远程扩展停止词字典--> | ||
<!-- <entry key="remote_ext_stopwords">words_location</entry> --> | ||
</properties> | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
本地测试服务器,4核心 8 线程,16GB 内存,50GB 磁盘存储。Debian GNU/Linux 12 (bookworm) 系统。 | ||
|
||
配置了 APT 清华源。 | ||
安装了 VIM。 | ||
配置了 root 允许密码登录。 | ||
安装了 Docker,参考 [[安装 Docker]]。 | ||
配置静态IP。 | ||
|
||
一、ElasticSearch 安装。 | ||
|
||
二、Kbina 安装。 | ||
|
||
|
||
|
||
| 端口 | 服务 | 描述 | | ||
| ---- | ----------------- | ---------- | | ||
| 9200 | ElasticSearch | Docker 安装。 | | ||
| 2000 | Java web-tools 服务 | 提供开发工具接口 | |