# Suggesters

**suggest**特征通过使用**suggester**基于所提供的文本来建议相似的术语。部分**suggest**功能还在开发中。

**suggest**请求部分&#x5728;**\_search**请求中或者通过**REST\_suggest**断点和查询部分一起定义。

```
POST twitter/_search
{
  "query" : {
    "match": {
      "message": "tring out Elasticsearch"
    }
  },
  "suggest" : {
    "my-suggestion" : {
      "text" : "trying out Elasticsearch",
      "term" : {
        "field" : "message"
      }
    }
  }
}
```

针&#x5BF9;**\_suggest**端点执行的建议请求应忽略周围的**suggest**元素，该元素仅在**suggest**请求是搜索的一部分时使用。

```
POST _suggest
{
  "my-suggestion" : {
    "text" : "tring out Elasticsearch",
    "term" : {
      "field" : "message"
    }
  }
}
```

每个请求可以指定几个**suggestions**。 每个**suggestion**用任意名称标识。 在下面的示例中，请求了两个**suggestions**。**my-suggest-1**和**my-suggest-2**两个**suggestions**使用术语**suggester**，但有不同的**test**。

```
POST _suggest
{
  "my-suggest-1" : {
    "text" : "tring out Elasticsearch",
    "term" : {
      "field" : "message"
    }
  },
  "my-suggest-2" : {
    "text" : "kmichy",
    "term" : {
      "field" : "user"
    }
  }
}
```

下面的 suggest 响应示例包括对于 my-suggest-1 和 my-suggestion-2 的 suggest 响应。 每个suggest 部分包含条目（entries）。 每个条目实际上是来自 suggest 文本的 token ，并且包含 suggest 文本中的 suggest 条目文本，原始的条目开始于 suggest 偏移（offset）和长度，并且如果找到任意数目的选项。

```
{
  "_shards": ...
  "my-suggest-1": [ {
    "text": "tring",
    "offset": 0,
    "length": 5,
    "options": [ {"text": "trying", "score": 0.8, "freq": 1 } ]
  }, {
    "text": "out",
    "offset": 6,
    "length": 3,
    "options": []
  }, {
    "text": "elasticsearch",
    "offset": 10,
    "length": 13,
    "options": []
  } ],
  "my-suggest-2": ...
}
```

每个选项数组（**option array**）包含一个选项对象，其中包括**suggest**文本，其文档频率和分数与**suggest**输入文本相比较。 分数的意义取决于使用的**suggester**。 术语**suggester**的分数是基于编辑（edit）距离。

全局 **suggest** 文本

为了避免重复**suggest**文本，可以定义全局文本。 在下面的示例中，**suggest**文本是全局定义的，并适用于**my-suggest-1**和**my-suggest-2**建议。

```
POST _suggest
{
  "text" : "tring out Elasticsearch",
  "my-suggest-1" : {
    "term" : {
      "field" : "message"
    }
  },
  "my-suggest-2" : {
    "term" : {
      "field" : "user"
    }
  }
}
```

在上述示例中，**suggest**文本也可以被指定为**suggest**特定选项。 在**suggestion**级别上指定的**suggest**文本覆盖全局级别上的**suggest**文本。


---

# 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-apis/343sou-suo-apis-search-apis/suggesters.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.
