# Glossary of terms (词汇表)

* analysis（分析）
* cluster （集群）
* document （文档）
* id&#x20;
* field（属性）&#x20;
* index （索引）
* mapping （映射）
* node （节点）
* primary shard （主分片）
* replica shard （副本分片）
* routing （路由）
* shard （分片）
* source field （源属性）
* term （词条）
* text （文本）
* type （类型）

## analysis（分析） <a href="#glossaryofterms-ci-hui-biao-analysis-fen-xi" id="glossaryofterms-ci-hui-biao-analysis-fen-xi"></a>

**Analysis**（分析）是将[full text](https://www.elastic.co/guide/en/elasticsearch/reference/5.4/glossary.html#glossary-text)（全文）转化为[terms](https://www.elastic.co/guide/en/elasticsearch/reference/5.4/glossary.html#glossary-term)（词条）的过程。使用不同的 **analyzer**（分词器），`FOO BAR，Foo-Bar，foo，bar这些短语可能都会生成foo和bar两个词条，实际的index（索引）里面存储的就是这些terms（词条）。针对FoO:bAR的full text query（全文检索），会先将其分析成为foo,bar这样的词条，然后匹配存储在index（索引）中的term（词条）。正是这个analysis（分析）的过程（发生在索引和搜索时）使得elasticsearch能够执行full text queries（全文检索）。也可以参阅`[`text`](https://www.elastic.co/guide/en/elasticsearch/reference/5.4/glossary.html#glossary-text)`（文本）和`[`term`](https://www.elastic.co/guide/en/elasticsearch/reference/5.4/glossary.html#glossary-term)`（词条）了解更多细节信息。`

## cluster （集群） <a href="#glossaryofterms-ci-hui-biao-cluster-ji-qun" id="glossaryofterms-ci-hui-biao-cluster-ji-qun"></a>

**cluster**（集群）是由拥有同一个集群名的一个或者多个节点组成。每个集群拥有一个主节点，它由集群自行选举出来，在当前主节点挂了，能被其他节点取代。

## document （文档） <a href="#glossaryofterms-ci-hui-biao-document-wen-dang" id="glossaryofterms-ci-hui-biao-document-wen-dang"></a>

**document（文档）**&#x662F;存储在**elasticsearch**中的**json**文档。类似于关系型数据库中的一行记录。每个文档存储在一个**index**（索引）中，它具有一个**type**（类型）和一个**id**。文档是包含零到多个**fields**（属性）或者键值对的**json**对象（类似于其他语言中的hash/hashmap/associative array）。当一个文档被**indexed**（索引）的时候，它的原始**json**文档会被存储&#x6210;**\_source**属性，对该文档进行**get**或者**search**操作时，默认返回的就是改属性。

## id <a href="#glossaryofterms-ci-hui-biao-id" id="glossaryofterms-ci-hui-biao-id"></a>

文档的**ID**标识一个文档。文档的index/type/id必须唯一。如果没有提供**ID**，**elasticsearch**会自动生成一个**ID**。（查询**routing**（路由）获取更多信息）

## field（属性） <a href="#glossaryofterms-ci-hui-biao-field-shu-xing" id="glossaryofterms-ci-hui-biao-field-shu-xing"></a>

一个文档包涵一系列的属性或者键值对。它的值可以是简单标量值（如字符串，整型数，日期），或者是像数组和对象一样的嵌套结构。属性类似于关系型数据库中的列。每个属性的**mapping**（映射）都有其类型（不同于**document**（文档）的**type**（类型）），表明该属性能存储成改类型的数据，例如 `integer`, `string`, `object。mapping（映射）也允许你定义属性的值是否需要analyzed（分词）。`

## index （索引） <a href="#glossaryofterms-ci-hui-biao-index-suo-yin" id="glossaryofterms-ci-hui-biao-index-suo-yin"></a>

**index**（索引）类似于关系型数据库中的表。它有一个**mapping**（映射）来定义索引中的**fields**（属性），这些属性被分组成多种**type**（类型）。索引是一个逻辑命名空间，它对应一到多个**primaryshards**（主分片）和零到多个**replica shards**（副本分片）。

## mapping （映射） <a href="#glossaryofterms-ci-hui-biao-mapping-ying-she" id="glossaryofterms-ci-hui-biao-mapping-ying-she"></a>

**mapping**（映射）类似于关系型数据库中的元数据定义。每一个**index**（索引）对应一个**mapping**（映射），它定义了**index**（索引）中的每一个**type**（类型），另外还有一些索引级别的设置。**mapping**（映射）可以显式定义，或者当一个文档进行索引时自动生成。

## node （节点） <a href="#glossaryofterms-ci-hui-biao-node-jie-dian" id="glossaryofterms-ci-hui-biao-node-jie-dian"></a>

**node**（节点）是从属于一个**elasticsearch**集群的正在运行的节点。当以测试为目的时，可以在一台主机上启动多个节点，但是通常一台主机最好运行一个节点。在启动时，节点会使用广播的方式，自动感知（网络中）具有相同集群名的集群，并尝试加入它。

## primary shard （主分片） <a href="#glossaryofterms-ci-hui-biao-primaryshard-zhu-fen-pian" id="glossaryofterms-ci-hui-biao-primaryshard-zhu-fen-pian"></a>

每个文档存储在单**primary shard**（主分片）中。当索引一个文档时，它会首先被索引到主分片上，然后索引到主分片的所有副本上。默认情况下，一个**index**（索引）有5个**primary shard**（主分片）。根据**index**（索引）的处理能力，你可以指定更少或者更多的**primary shard**（主分片）来扩展文档数量。当**index**（索引）创建之后，**primary shard**（主分片）的数量不可更改。查询**routing**（路由）获取更多信息。

## replica shard （副本分片） <a href="#glossaryofterms-ci-hui-biao-replicashard-fu-ben-fen-pian" id="glossaryofterms-ci-hui-biao-replicashard-fu-ben-fen-pian"></a>

每一个**primary shard**（主分片）拥有零到多个副本。副本是**primary shard**（主分片）的拷贝，它的存在有两个目的：

1. 增加容错：当主分片失败时，一个

   **replica shard**

   （副本分片）可以提升为

   **primary shard**

   （主分片）
2. 提升性能：

   **primary shard**

   （主分片）和

   **replica shard**

   （副本分片）都能处理

   **get**

   和

   **shearch**

   请求。默认情况下，每个

   **primary shard**

   （主分片）有一个副本，副本的个数可以动态的修改。

   **replica shard**

   （副本分片）不会和

   **primary shard**

   （主分片）分配在同一个节点上。

## routing （路由） <a href="#glossaryofterms-ci-hui-biao-routing-lu-you" id="glossaryofterms-ci-hui-biao-routing-lu-you"></a>

**index**（索引）一个**document**（文档）时，它会存储在一个**primary shard**（主分片）上。通过对**routing**（路由）值作哈希来决定具体是哪一个主分片。默认情况下，**routing**（路由）值是由**document**（文档）**ID**派生的，如果**document**（文档）指定了父**document**（文档），则通过其父**document**（文档）的**ID**派生（保证父子文档存储在同一个分片上）。**routing**（路由）值可以在索引时直接指定，或者在**mapping**（映射）中指定一个**routing field**（路由属性）。

## shard （分片） <a href="#glossaryofterms-ci-hui-biao-shard-fen-pian" id="glossaryofterms-ci-hui-biao-shard-fen-pian"></a>

**shard**（分片）是一个**Lucene**实例。它是由**elasticsearch**管理的低层次的工作单元。**index**（索引）是针对 主分片和副本分片的逻辑命名空间。除了定义**index**（索引）应该具有的**primaryshard**（主分片）和**replica shard**（副本分片）的数量之外，你不需要对**shard**（分片）作其它的工作。相反，你的代码应该只处理**index**（索引）。**elasticsearch**将**shards**（分片）分配到整个集群的所有节点上，当节点失败时可以自动将分片迁移到其他节点或者新增的节点上。

## source field （源属性） <a href="#glossaryofterms-ci-hui-biao-sourcefield-yuan-shu-xing" id="glossaryofterms-ci-hui-biao-sourcefield-yuan-shu-xing"></a>

在默认情况下，你索引的**jsondocument**（文档）会存储在\_source**field**（属性）中，**get**和**search**请求会返回该**field**（属性）。这样可以直接在搜索结果中获取原始文档对象，不需要通过**ID**再检索一次文档对象。

## term （词条） <a href="#glossaryofterms-ci-hui-biao-term-ci-tiao" id="glossaryofterms-ci-hui-biao-term-ci-tiao"></a>

**term**（词条）是**elasticsearch**中被索引的确切值。`foo`, `Foo`, `FOO 这些term（词条）不相等。term（词条）可以通过词条搜索来检索。查询text（文本）和anaylsis（分词）获取更多信息。`

## text （文本） <a href="#glossaryofterms-ci-hui-biao-text-wen-ben" id="glossaryofterms-ci-hui-biao-text-wen-ben"></a>

**text**（文本）（或者说全文）是普通的非结构化文本，如一个段落。默认情况下，**text**（文本）会被**analyzed**（分词）成**term**（词条），**term**（词条）是在索引中存储的确切值。文本的**field**（属性）必须在索引时完成**analyzed**（分词）来支持全文检索的功能，全文检索使用的关键词也必须在搜索时**analyzed**（分词）成索引时产生的相同**term**（词条）。查询**term**（词条）和**analysis**（分词）获取更多信息。

## type （类型） <a href="#glossaryofterms-ci-hui-biao-type-lei-xing" id="glossaryofterms-ci-hui-biao-type-lei-xing"></a>

**type**（类型）代表文档的类型，如一封邮件，一个用户，一条推文。搜索API可以通过文档类型来过滤。**index**（索引）可以包涵多个类型，每一个**type**（类型）有一系列的**fields**（属性）。同一个**index**（索引）中不同**type**（类型）的同名**fields**（属性）必须使用相同的**mapping**（映射）（定义文档的属性如何索引以及是文档能被搜索）。
