Skip to content

Commit 023e01e

Browse files
committed
update docs
1 parent 626d763 commit 023e01e

9 files changed

+398
-60
lines changed

.travis.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ language: node_js
55

66
sudo: required
77

8-
node_js: stable
8+
node_js: '16.13.0'
99

1010
branches:
1111
only:

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@
7575
7676
- [Elasticsearch 面试总结](docs/nosql/elasticsearch/elasticsearch-interview.md) 💯
7777
- [ElasticSearch 应用指南](docs/nosql/elasticsearch/elasticsearch-quickstart.md)
78-
- [ElasticSearch API](docs/nosql/elasticsearch/elasticsearch-api.md)
78+
- [ElasticSearch API](docs/nosql/elasticsearch/ElasticSearchRestApi.md)
7979
- [ElasticSearch 运维](docs/nosql/elasticsearch/elasticsearch-ops.md)
8080

8181
#### HBase

docs/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ footer: CC-BY-SA-4.0 Licensed | Copyright © 2018-Now Dunwu
7474
7575
- [Elasticsearch 面试总结](nosql/elasticsearch/elasticsearch-interview.md) 💯
7676
- [ElasticSearch 应用指南](nosql/elasticsearch/elasticsearch-quickstart.md)
77-
- [ElasticSearch API](nosql/elasticsearch/elasticsearch-api.md)
77+
- [ElasticSearch API](nosql/elasticsearch/ElasticSearchRestApi.md)
7878
- [ElasticSearch 运维](nosql/elasticsearch/elasticsearch-ops.md)
7979

8080
#### HBase

docs/nosql/elasticsearch/elasticsearch-api.md renamed to docs/nosql/elasticsearch/ElasticsearchRestApi.md

Lines changed: 140 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,22 @@
1-
# Elasticsearch API
1+
# ElasticSearch Rest API
22

33
> **[Elasticsearch](https://github.com/elastic/elasticsearch) 是一个分布式、RESTful 风格的搜索和数据分析引擎**,能够解决不断涌现出的各种用例。 作为 Elastic Stack 的核心,它集中存储您的数据,帮助您发现意料之中以及意料之外的情况。
44
>
55
> [Elasticsearch](https://github.com/elastic/elasticsearch) 基于搜索库 [Lucene](https://github.com/apache/lucene-solr) 开发。ElasticSearch 隐藏了 Lucene 的复杂性,提供了简单易用的 REST API / Java API 接口(另外还有其他语言的 API 接口)。
66
>
77
> _以下简称 ES_
88
9-
## 一、REST API
10-
119
> REST API 最详尽的文档应该参考:[ES 官方 REST API](https://www.elastic.co/guide/en/elasticsearch/reference/current/rest-apis.html)
1210
13-
### 索引
11+
## 索引 API
1412

15-
新建 Index,可以直接向 ES 服务器发出 `PUT` 请求。
13+
> 参考资料:[Elasticsearch 官方之 cat 索引 API](https://www.elastic.co/guide/en/elasticsearch/reference/current/cat-indices.html)
1614
17-
#### 创建索引
15+
### 创建索引
16+
17+
新建 Index,可以直接向 ES 服务器发出 `PUT` 请求。
1818

19-
示例:直接创建索引
19+
(1)直接创建索引
2020

2121
```bash
2222
curl -X POST 'localhost:9200/user'
@@ -28,21 +28,23 @@ curl -X POST 'localhost:9200/user'
2828
{"acknowledged":true,"shards_acknowledged":true,"index":"user"}
2929
```
3030

31-
示例:创建索引时指定配置
31+
(2)创建索引时指定配置
32+
33+
语法格式:
3234

3335
```bash
34-
$ curl -X PUT -H 'Content-Type: application/json' 'localhost:9200/user' -d '
36+
$ curl -X PUT /my_index
3537
{
36-
"settings" : {
37-
"index" : {
38-
"number_of_shards" : 3,
39-
"number_of_replicas" : 2
40-
}
38+
"settings": { ... any settings ... },
39+
"mappings": {
40+
"type_one": { ... any mappings ... },
41+
"type_two": { ... any mappings ... },
42+
...
4143
}
42-
}'
44+
}
4345
```
4446
45-
示例:创建索引时指定 `mappings`
47+
示例:
4648
4749
```bash
4850
$ curl -X PUT -H 'Content-Type: application/json' 'localhost:9200/user' -d '
@@ -56,63 +58,72 @@ $ curl -X PUT -H 'Content-Type: application/json' 'localhost:9200/user' -d '
5658
}'
5759
```
5860
59-
#### 删除索引
61+
如果你想禁止自动创建索引,可以通过在 `config/elasticsearch.yml` 的每个节点下添加下面的配置:
62+
63+
```js
64+
action.auto_create_index: false
65+
```
66+
67+
### 删除索引
6068
6169
然后,我们可以通过发送 `DELETE` 请求,删除这个 Index。
6270
6371
```bash
6472
curl -X DELETE 'localhost:9200/user'
6573
```
6674
67-
#### 查看索引
75+
删除多个索引
76+
77+
```js
78+
DELETE /index_one,index_two
79+
DELETE /index_*
80+
```
81+
82+
### 查看索引
6883
6984
可以通过 GET 请求查看索引信息
7085
7186
```bash
7287
# 查看索引相关信息
73-
curl -X GET 'localhost:9200/user'
88+
GET kibana_sample_data_ecommerce
7489

75-
#查看索引的文档总数
76-
CURL -X 'localhost:9200/user/_count'
90+
# 查看索引的文档总数
91+
GET kibana_sample_data_ecommerce/_count
7792

78-
#查看前10条文档,了解文档格式
79-
POST user/_search
80-
{
81-
}
93+
# 查看前10条文档,了解文档格式
94+
GET kibana_sample_data_ecommerce/_search
8295

83-
#_cat indices API
84-
#查看indices
85-
CURL -X /_cat/indices/kibana*?v&s=index
96+
# _cat indices API
97+
# 查看indices
98+
GET /_cat/indices/kibana*?v&s=index
8699

87-
#查看状态为绿的索引
88-
CURL -X /_cat/indices?v&health=green
100+
# 查看状态为绿的索引
101+
GET /_cat/indices?v&health=green
89102

90-
#按照文档个数排序
91-
CURL -X /_cat/indices?v&s=docs.count:desc
103+
# 按照文档个数排序
104+
GET /_cat/indices?v&s=docs.count:desc
92105

93-
#查看具体的字段
94-
CURL -X /_cat/indices/kibana*?pri&v&h=health,index,pri,rep,docs.count,mt
106+
# 查看具体的字段
107+
GET /_cat/indices/kibana*?pri&v&h=health,index,pri,rep,docs.count,mt
95108

96-
#How much memory is used per index?
97-
CURL -X /_cat/indices?v&h=i,tm&s=tm:desc
109+
# 查看索引占用的内存
110+
GET /_cat/indices?v&h=i,tm&s=tm:desc
98111
```
99112
100-
#### 打开/关闭索引
113+
### 打开/关闭索引
101114
102115
通过在 `POST` 中添加 `_close``_open` 可以打开、关闭索引。
103-
关闭索引
104-
105-
```bash
106-
curl -X POST 'localhost:9200/user/_close'
107-
```
108116
109117
打开索引
110118
111119
```bash
112-
curl -X POST 'localhost:9200/user/_open'
120+
# 打开索引
121+
POST kibana_sample_data_ecommerce/_open
122+
# 关闭索引
123+
POST kibana_sample_data_ecommerce/_close
113124
```
114125
115-
### 文档
126+
## 文档
116127
117128
#### 新增记录
118129
@@ -372,9 +383,92 @@ $ curl -H 'Content-Type: application/json' 'localhost:9200/user/admin/_search?pr
372383
}'
373384
```
374385
375-
## 二、Java API
386+
## 集群 API
387+
388+
> [Elasticsearch 官方之 Cluster API](https://www.elastic.co/guide/en/elasticsearch/reference/current/cluster.html)
389+
390+
一些集群级别的 API 可能会在节点的子集上运行,这些节点可以用节点过滤器指定。例如,任务管理、节点统计和节点信息 API 都可以报告来自一组过滤节点而不是所有节点的结果。
376391
377-
TODO:待补充...
392+
节点过滤器以逗号分隔的单个过滤器列表的形式编写,每个过滤器从所选子集中添加或删除节点。每个过滤器可以是以下之一:
393+
394+
- `_all`:将所有节点添加到子集
395+
- `_local`:将本地节点添加到子集
396+
- `_master`:将当前主节点添加到子集
397+
- 根据节点ID或节点名将匹配节点添加到子集
398+
- 根据IP地址或主机名将匹配节点添加到子集
399+
- 使用通配符,将节点名、地址名或主机名匹配的节点添加到子集
400+
- `master:true`, `data:true`, `ingest:true`, `voting_only:true`, `ml:true``coordinating_only:true`, 分别意味着将所有主节点、所有数据节点、所有摄取节点、所有仅投票节点、所有机器学习节点和所有协调节点添加到子集中。
401+
- `master:false`, `data:false`, `ingest:false`, `voting_only:true`, `ml:false``coordinating_only:false`, 分别意味着将所有主节点、所有数据节点、所有摄取节点、所有仅投票节点、所有机器学习节点和所有协调节点排除在子集外。
402+
- 配对模式,使用 `*` 通配符,格式为 `attrname:attrvalue`,将所有具有自定义节点属性的节点添加到子集中,其名称和值与相应的模式匹配。自定义节点属性是通过 `node.attr.attrname: attrvalue` 形式在配置文件中设置的。
403+
404+
```bash
405+
# 如果没有给出过滤器,默认是查询所有节点
406+
GET /_nodes
407+
# 查询所有节点
408+
GET /_nodes/_all
409+
# 查询本地节点
410+
GET /_nodes/_local
411+
# 查询主节点
412+
GET /_nodes/_master
413+
# 根据名称查询节点(支持通配符)
414+
GET /_nodes/node_name_goes_here
415+
GET /_nodes/node_name_goes_*
416+
# 根据地址查询节点(支持通配符)
417+
GET /_nodes/10.0.0.3,10.0.0.4
418+
GET /_nodes/10.0.0.*
419+
# 根据规则查询节点
420+
GET /_nodes/_all,master:false
421+
GET /_nodes/data:true,ingest:true
422+
GET /_nodes/coordinating_only:true
423+
GET /_nodes/master:true,voting_only:false
424+
# 根据自定义属性查询节点(如:查询配置文件中含 node.attr.rack:2 属性的节点)
425+
GET /_nodes/rack:2
426+
GET /_nodes/ra*:2
427+
GET /_nodes/ra*:2*
428+
```
429+
430+
### 集群健康 API
431+
432+
```bash
433+
GET /_cluster/health
434+
GET /_cluster/health?level=shards
435+
GET /_cluster/health/kibana_sample_data_ecommerce,kibana_sample_data_flights
436+
GET /_cluster/health/kibana_sample_data_flights?level=shards
437+
```
438+
439+
### 集群状态 API
440+
441+
集群状态 API 返回表示整个集群状态的元数据。
442+
443+
```bash
444+
GET /_cluster/state
445+
```
446+
447+
448+
449+
## 节点 API
450+
451+
> [Elasticsearch 官方之 cat Nodes API](https://www.elastic.co/guide/en/elasticsearch/reference/current/cat-nodes.html)——返回有关集群节点的信息。
452+
453+
```bash
454+
# 查看默认的字段
455+
GET /_cat/nodes?v=true
456+
# 查看指定的字段
457+
GET /_cat/nodes?v=true&h=id,ip,port,v,m
458+
```
459+
460+
## 分片 API
461+
462+
> [Elasticsearch 官方之 cat Shards API](https://www.elastic.co/guide/en/elasticsearch/reference/current/cat-shards.html)——shards 命令是哪些节点包含哪些分片的详细视图。它会告诉你它是主还是副本、文档数量、它在磁盘上占用的字节数以及它所在的节点。
463+
464+
```bash
465+
# 查看默认的字段
466+
GET /_cat/shards
467+
# 根据名称查询分片(支持通配符)
468+
GET /_cat/shards/my-index-*
469+
# 查看指定的字段
470+
GET /_cat/shards?h=index,shard,prirep,state,unassigned.reason
471+
```
378472
379473
## 参考资料
380474

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy