138 lines
7.5 KiB
Markdown
138 lines
7.5 KiB
Markdown
- [index modules](#index-modules)
|
||
- [index module introduce](#index-module-introduce)
|
||
- [索引设置](#索引设置)
|
||
- [static index settings](#static-index-settings)
|
||
- [`index.number_of_shards`](#indexnumber_of_shards)
|
||
- [Analysis](#analysis)
|
||
- [index shard allocation](#index-shard-allocation)
|
||
- [index blocks](#index-blocks)
|
||
- [index block settings](#index-block-settings)
|
||
- [`index.blocks.read_only`](#indexblocksread_only)
|
||
- [`index.blocks.read_only_allow_delete`](#indexblocksread_only_allow_delete)
|
||
- [`index.blocks.read`](#indexblocksread)
|
||
- [`index.blocks.write`](#indexblockswrite)
|
||
- [`index.blocks.metadata`](#indexblocksmetadata)
|
||
- [增加index block示例](#增加index-block示例)
|
||
- [path param](#path-param)
|
||
- [query param](#query-param)
|
||
- [示例](#示例)
|
||
|
||
|
||
# index modules
|
||
## index module introduce
|
||
index module用于对索引进行创建,并且控制和索引相关的各个方面。
|
||
|
||
### 索引设置
|
||
索引级别的设置可以针对每个索引来进行设置,设置分类如下:
|
||
- static:static设置只能在如下时机应用于索引
|
||
- 索引创建时
|
||
- 索引处于closed状态
|
||
- 使用`update-index-settings` api,并且带有`reopen=true`的查询参数,带有该参数时,会关闭受影响索引,更新后将受影响索引重新开启
|
||
- dynamic:dynamic索引可以在索引处于活跃状态时,通过`udpate-index-settings` api进行修改
|
||
|
||
> #### closed index
|
||
> 当一个索引处于`closed`状态时,所有针对该索引的read/write操作都会被阻塞,所有可以用于`opened`状态索引的操作,其执行对于`closed`状态的索引来说都不允许。
|
||
>
|
||
> 对于`closed`状态的索引,既无法向其中新增文档,也无法在索引中检索文档。
|
||
>
|
||
> 处于closed状态的索引能够通过`open index api`来重新开启。
|
||
|
||
### static index settings
|
||
#### `index.number_of_shards`
|
||
索引拥有的primary shards数量,默认为1,该配置项只能在索引创建时被设置。`即使索引处于closed状态,该配置项也无法修改。`
|
||
|
||
> `index.number_of_shards`最大为1024
|
||
|
||
## Analysis
|
||
index analysis module充当了可配置的analyzer注册中心,analyzer可用于将`string`类型字段转换为独立的terms,这将用于:
|
||
- 将文档string field的字段转化为terms,并且将terms添加到倒排索引中,令文档可以被搜索
|
||
- analyzer被用于高级查询,例如`match`查询,将用户输入的查询字符串分割为search terms用于查询
|
||
|
||
## index shard allocation
|
||
index shard allocation提供了可针对单个索引的设置,用于控制node中shard的分配:
|
||
- shard allocating filtering:控制shard被分配给哪个node
|
||
- delayed allocation:`节点离开导致未分配shard`的延迟分配
|
||
- total shards per node:相同索引在同一node中,shards数量的上限
|
||
- data tier allocation:控制对data tier分配的索引
|
||
|
||
## index blocks
|
||
index blocks限制了针对特定索引的操作类型。操作阻塞的类型可以分为:
|
||
- 读操作阻塞
|
||
- 写操作阻塞
|
||
- 元数据操作阻塞
|
||
|
||
针对索引操作的阻塞可以通过`dynamic index setting`来进行新增和移除。并且,阻塞也可以通过特定的api来进行添加和移除。
|
||
|
||
针对wrtie blocks设置的修改,一旦修改成功,那么所有的在途写操作都已经完成。
|
||
|
||
### index block settings
|
||
#### `index.blocks.read_only`
|
||
如果该配置项设置为true,该索引和索引的元数据都是只读的,当设置为`false`时,允许写操作和元数据变更。
|
||
|
||
#### `index.blocks.read_only_allow_delete`
|
||
类似于`index.blocks.write`,但是可以对index进行删除。不要针对`index.blocks.read_only_allow_delete`进行手动设置或移除。`disk-based shard allocator`会根据磁盘剩余空间自动添加或移除该配置项。
|
||
|
||
从索引中删除文档释放资源(而不是删除索引本身)会暂时增加索引的大小,故而在node的磁盘空间不足时可能无法实现。当`index.blocks.read_only_allow_delete`被设置为true时,`并不允许删除索引中的文档`。但是,删除索引本身的操作只需要极少量的额外磁盘空间,并且几乎可以立即删除索引所占用的空间,故而删除索引本身的操作仍然被允许。
|
||
|
||
> elastic search在磁盘占用高于`flood stage watermark`时,会自动为索引增加` read-only-allow-delete`阻塞;当磁盘占用率跌倒`high watermark`之下时,则是会自动释放该阻塞
|
||
|
||
#### `index.blocks.read`
|
||
如果设置为true,会阻塞针对index的读操作
|
||
|
||
#### `index.blocks.write`
|
||
如果设置为true,会阻塞针对索引的写操作,和`index.blocks.read_only`不同,本设置项并不影响metadata。
|
||
|
||
例如,为索引设置write block后,仍然可以对metadata进行变更,但是设置了`index.blocks.read_only`后,无法对元数据进行变更
|
||
|
||
#### `index.blocks.metadata`
|
||
如果设置为true,会禁止对元数据的读取和变更
|
||
|
||
### 增加index block示例
|
||
```bash
|
||
# PUT /<index>/_block/<block>
|
||
PUT /my-index-000001/_block/write
|
||
```
|
||
#### path param
|
||
- `<index>`: 由`,`分隔的列表或通配符表达式,代表该请求的索引名称
|
||
- 默认情况下,`<index>`部分需要指定索引的精确名称。如果想要使用`_all, *`等通配表达式,需要将`action.destructive_requires_name`属性设置为`false`。
|
||
- `<block>`: 向索引应用的阻塞类型
|
||
- <block>部分可选的值为`metadata, read, read_only, write`
|
||
|
||
#### query param
|
||
- `allow_no_indices`:
|
||
- 如果该参数设置为false,那么当索引项中任一`wildcard expression, idnex alias或_all`值没有匹配的索引或只能匹配到closed状态的索引,那么该请求会返回异常。
|
||
- 例如`foo*,bar*`,`foo*`表达式匹配到索引,但是`bar*`没有相匹配的索引,那么会抛出异常。
|
||
- 该参数认值为`true`
|
||
- `expand_wildcards`:
|
||
- wildcard pattern能够匹配到的索引类型。如果请求能够匹配到data stream,那么该参数能够决定wildcard pattern能够匹配到hidden data stream
|
||
- 该参数的值支持`,`分隔,有效的值如下:
|
||
- `all`:匹配任何data stream或index,包括hidden的
|
||
- `open`:匹配`open, non-hidden`状态的索引和`non-hidden`状态的data stream
|
||
- `closed`:匹配`closed, non-hidden`状态的索引和`non-hidden`状态的data stream
|
||
- `hidden`:匹配`hidden`状态的索引和`hidden`状态的data stream。`hidden`必须和`open, closed`中任一组合使用,也能和两者一起使用`open, closed, hidden`
|
||
- `none`:不接受wildcard pattern
|
||
- 该参数默认值为`open`
|
||
- `ignore_unavailable`: 如果参数设置为false,若未匹配到索引或匹配到closed状态的索引,返回异常
|
||
- 该参数默认值为`false`
|
||
- `master_timeout`:等待master node的最大时间,默认为`30s`,如果超过该限制master node仍然不可访问,那么该请求会返回异常
|
||
- `timeout`:在更新完metadata后,等待cluster中所有节点返回的时间限制,默认为`30s`。如果超时后仍未能接受到返回,那么针对cluster metadata的修改仍然会被应用,但是在返回中会指定并非接受到了所有的ack
|
||
|
||
#### 示例
|
||
添加write block的示例如下所示:
|
||
```
|
||
PUT /my-index-000001/_block/write
|
||
```
|
||
返回结果如下:
|
||
```
|
||
{
|
||
"acknowledged" : true,
|
||
"shards_acknowledged" : true,
|
||
"indices" : [ {
|
||
"name" : "my-index-000001",
|
||
"blocked" : true
|
||
} ]
|
||
}
|
||
```
|
||
|
||
|