# 3.3. Analysis(分析)

> 下文反向索引,其实就是倒排索引

分析是将文本，如任何电子邮件的正文转换成附加到反向索引的tokens(标记)或terms(条件)的过程。分析由分析器执行，它可以是内置的分析器，也可以是每个索引定义的自定义分析器。

## **Index time analysis（索引时分析）**

例如在索引时，内置的english analyzer(英文分析器)将会转换这个句子：

```
"The QUICK brown foxes jumped over the lazy dog!"
```

这些条件将被添加到反向索引中。

```
[ quick, brown, fox, jump, over, lazi, dog ]
```

**Specifying an index time analyzer（指定索引时分析器）**

映射中的每个文本字段都能指定其自己的分析器。

```
PUT my_index
{
  "mappings": {
    "my_type": {
      "properties": {
        "title": {
          "type":     "text",
          "analyzer": "standard"
        }
      }
    }
  }
}
```

在索引时，如果没有指定分析器，则会在索引设置中查找名为default的分析器。未找到则默认使用standard analyzer(标准分析器)。

## **Search time analysis（搜索时分析）**

同样的分析过程应用于使用类似match query(匹配查询)的全文检索搜索时，将查询字符串的文本转换为相同形式的条件存储到反向索引中。

例如，用户可能搜索：

```
"a quick fox"
```

这将由类似英语分析器分析为以下的条件：

```
[ quick, fox ]
```

尽管在查询的字符串中使用明确的单词不会出现在原始的文本中(quick VS QUICK,fox VS foxes),因为我们已将相同的分析器应用于文本和查询字符串，查询字符串中的条件与反向索引中的文本完全匹配，这意味着这个查询匹配到我们的示例文档。

> 上句话的意思其实是当我们搜索"a quick fox", 经过搜索分析器进行分析后,出去停止词,后变成了两个关键词`quick, fox`,原始文档中其实存储的是QUICK,foxes (大写和负数这种形式),由于我们搜索和索引时使用的相同分析器,也就是说可以分析器可以识别出来搜索的词 和原始文档中的词 划等号 quick = QUICK,fox = foxes

**Specifying a search time analyzer（指定搜索时分析器）**

通常在索引时和搜索时应该使用相同的分析器，而像match query(匹配查询)那样的全文检索将使用映射来查找用于每个字段的分析器。

通过查找用于搜索特定字段的分析器来决定：

* 在查询中指定分析器。
* search\_analyzer映射参数。
* analyzer映射参数。
* 索引设置中的分析器称为default\_search。
* 索引设置中的分析器称为default。
* standard分析器。


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://xiaoxiami.gitbook.io/elasticsearch/ji-chu/33-analysisfen-679029.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
