Docs/ELK/es学习记录08-索引设置.md
2022-10-18 16:59:37 +08:00

64 lines
2.2 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

### 主分片与副本分片
number_of_shards
每个索引的主分片数,默认值是 5 。这个配置在索引创建后不能修改。
number_of_replicas
每个主分片的副本数,默认值是 1 。对于活动的索引库,这个配置可以随时修改。
#### 创建一个有1个主分片无副本分片的索引
```
PUT /my_temp_index
{
"settings": {
"number_of_shards" : 1,
"number_of_replicas" : 0
}
}
```
#### 修改索引副本分片数量
```
PUT /my_temp_index/_settings
{
"number_of_replicas": 2
}
```
### 分析器
standard 分析器是用于全文字段的默认分析器,对于大部分西方语系来说是一个不错的选择。 它包括了以下几点:
standard 分词器,通过单词边界分割输入的文本。
standard 语汇单元过滤器,目的是整理分词器触发的语汇单元(但是目前什么都没做)。
lowercase 语汇单元过滤器,转换所有的语汇单元为小写。
stop 语汇单元过滤器,删除停用词—​对搜索相关性影响不大的常用词,如 a the and is 。
默认情况下,停用词过滤器是被禁用的。如需启用它,你可以通过创建一个基于 standard 分析器的自定义分析器并设置 stopwords 参数。 可以给分析器提供一个停用词列表,或者告知使用一个基于特定语言的预定义停用词列表。
在下面的例子中,我们创建了一个新的分析器,叫做 es_std 并使用预定义的西班牙语停用词列表:
```
PUT /spanish_docs
{
"settings": {
"analysis": {
"analyzer": {
"es_std": {
"type": "standard",
"stopwords": "_spanish_"
}
}
}
}
}
```
es_std 分析器不是全局的—​它仅仅存在于我们定义的 spanish_docs 索引中。 为了使用 analyze API来对它进行测试我们必须使用特定的索引名
```
GET /spanish_docs/_analyze?analyzer=es_std
El veloz zorro marrón
```
简化的结果显示西班牙语停用词 El 已被正确的移除:
```
{
"tokens" : [
{ "token" : "veloz", "position" : 2 },
{ "token" : "zorro", "position" : 3 },
{ "token" : "marrón", "position" : 4 }
]
}
```