# 3.3.2.Testing analyzers（测试分析器）

analyze API是查看分析器生成词语的一个非常有用的工具。内置的分析器（或结合内置的分词器，词语过滤器和字符过滤器）可以在请求中指定内联：

```
POST _analyze
{
  "analyzer": "whitespace",
  "text":     "The quick brown fox."}

POST _analyze
{
  "tokenizer": "standard",
  "filter":  [ "lowercase", "asciifolding" ],
  "text":      "Is this déja vu?"}
```

## Positions and character offsets（位置和字符偏移）

从analyze API的输出可以看出，分析器不仅将单词转换为词语，还记录了每个词语（用于短语查询或近义词查询）的顺序或相对位置，以及原始文本中每个词语的起始和结束字符的偏移量（用于突出搜索片段）。

或者，在特定的索引上运行analyze API时，可以参考自定义分析器：

```
PUT my_index
{
  "settings": {
    "analysis": {
      "analyzer": {
        "std_folded": {                       #1
          "type": "custom",
          "tokenizer": "standard",
          "filter": [
            "lowercase",
            "asciifolding"
          ]
        }
      }
    }
  },
  "mappings": {
    "my_type": {
      "properties": {
        "my_text": {
          "type": "text",
          "analyzer": "std_folded"            #2
        }
      }
    }
  }}

GET my_index/_analyze {                       #3
  "analyzer": "std_folded",                   #4
  "text":     "Is this déjà vu?"}

GET my_index/_analyze {                       #5
  "field": "my_text",                         #6
   "text":  "Is this déjà vu?"}
```

| 1   | 定义名为std\_folded的自定义分析器。      |
| --- | ---------------------------- |
| 2   | 字段my\_text使用std\_folded分析器。  |
| 3，5 | 要参考此分析器，analyze API必须指定索引名称。 |
| 4   | 按名称查看分析器。                    |
| 6   | 请参阅字段my\_text使用的分析器。         |


---

# 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/332testing-analyzersff08-ce-shi-fen-xi-qi.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.
