---
type: api
title: Get tokens from text analysis
description: **All methods and paths for this operation:**
url: https://www.elastic.co/elastic/docs-builder/docs/4371/api/doc/elasticsearch/v9/operation/operation-indices-analyze
resource: https://www.elastic.co/elastic/docs-builder/docs/4371/api/doc/elasticsearch/v9/operation/operation-indices-analyze
products:
  - Elasticsearch
---

# Get tokens from text analysis


Availability:

## Paths

- `POST` (also `GET`) `/{index}/_analyze`
- `POST` (also `GET`) `/_analyze`

- [Api key auth](/elastic/docs-builder/docs/4371/api/doc/elasticsearch/v9/authentication#apikeyauth)
- [Basic auth](/elastic/docs-builder/docs/4371/api/doc/elasticsearch/v9/authentication#basicauth)
- [Bearer auth](/elastic/docs-builder/docs/4371/api/doc/elasticsearch/v9/authentication#bearerauth)

#### Path Parameters

- `index` (string IndexName) — optional, leave it out to use `/_analyze`
  Index used to derive the analyzer.
If specified, the `analyzer` or field parameter overrides this value.
If no index is specified or the index does not have a default analyzer, the analyze API uses the standard analyzer.

## Description

The analyze API performs analysis on a text string and returns the resulting tokens.

Generating excessive amount of tokens may cause a node to run out of memory.
The `index.analyze.max_token_count` setting enables you to limit the number of tokens that can be produced.
If more than this limit of tokens gets generated, an error occurs.
The `_analyze` endpoint without a specified index will always use `10000` as its limit.

## Required authorization

* Index privileges: `index`

[Learn more about text analysis](https://www.elastic.co/docs/manage-data/data-store/text-analysis)

## Query String Parameters

- `index` (string IndexName)
  Index used to derive the analyzer.
If specified, the `analyzer` or field parameter overrides this value.
If no index is specified or the index does not have a default analyzer, the analyze API uses the standard analyzer.

## Request Body

`application/json`

- `analyzer` (string) — optional
  The name of the analyzer that should be applied to the provided `text`.
This could be a built-in analyzer, or an analyzer that’s been configured in the index.
- `attributes` ([] string) — optional
  Array of token attributes used to filter the output of the `explain` parameter.
- `char_filter` ([] CharFilter) — optional
  Array of character filters used to preprocess characters before the tokenizer.
- `explain` (boolean · default: false) — optional
  If `true`, the response includes token attributes and additional details.
- `field` (string Field) — optional
  Field used to derive the analyzer.
To use this parameter, you must specify an index.
If specified, the `analyzer` parameter overrides this value.
- `filter` ([] TokenFilter) — optional
  Array of token filters used to apply after the tokenizer.
- `normalizer` (string) — optional
  Normalizer to use to convert text into a single token.
- `text` (TextToAnalyze) — optional
  Text to analyze.
If an array of strings is provided, it is analyzed as a multi-value field.
- `tokenizer` (Tokenizer) — optional
  Tokenizer to use to convert text into tokens.

## Response

`application/json`

- `detail` ({} AnalyzeDetail)
  - `analyzer` ({} AnalyzerDetail)
    - `name` (string)
    - `tokens` ([] ExplainAnalyzeToken)
      - `bytes` (string)
      - `end_offset` (number)
      - `keyword` (boolean)
      - `position` (number)
      - `positionLength` (number)
      - `start_offset` (number)
      - `termFrequency` (number)
      - `token` (string)
      - `type` (string)
  - `charfilters` ([] CharFilterDetail)
    - `filtered_text` ([] string)
    - `name` (string)
  - `custom_analyzer` (boolean)
  - `tokenfilters` ([] TokenDetail)
    - `name` (string)
    - `tokens` ([] ExplainAnalyzeToken)
      - `bytes` (string)
      - `end_offset` (number)
      - `keyword` (boolean)
      - `position` (number)
      - `positionLength` (number)
      - `start_offset` (number)
      - `termFrequency` (number)
      - `token` (string)
      - `type` (string)
  - `tokenizer` ({} TokenDetail)
    Same fields as `tokenfilters` in `detail`
- `tokens` ([] AnalyzeToken)
  - `end_offset` (number)
  - `position` (number)
  - `positionLength` (number)
  - `start_offset` (number)
  - `token` (string)
  - `type` (string)
## Code Examples

#### Console

```console
POST /_analyze
{
  "analyzer": "standard",
  "text": "this is a test"
}
```

#### JavaScript

```javascript
const response = await client.indices.analyze({
  analyzer: "standard",
  text: "this is a test",
});
```

#### Python

```python
resp = client.indices.analyze(
    analyzer="standard",
    text="this is a test",
)
```

#### curl

```curl
curl -X POST "$ELASTICSEARCH_URL/_analyze" \
  -H "Authorization: ApiKey $ELASTIC_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "analyzer": "standard",
    "text": "this is a test"
  }'
```

#### Java

```java
client.indices().analyze(a -> a
    .analyzer("standard")
    .text("this is a test")
);
```

#### C#

```c#
var response = await client.Indices
    .AnalyzeAsync(d1 => d1
        .Analyzer("standard")
        .Text("this is a test")
    );
```

#### PHP

```php
$resp = $client->indices()->analyze([
    "body" => [
        "analyzer" => "standard",
        "text" => "this is a test",
    ],
]);
```

#### Ruby

```ruby
response = client.indices.analyze(
  body: {
    "analyzer": "standard",
    "text": "this is a test"
  }
)
```

## Response Examples

#### Indices analyze response example7

A successful response for an analysis with `explain` set to `true`.

```json
{
  "detail": {
    "custom_analyzer": true,
    "charfilters": [],
    "tokenizer": {
      "name": "standard",
      "tokens": [
        {
          "token": "detailed",
          "start_offset": 0,
          "end_offset": 8,
          "type": "<ALPHANUM>",
          "position": 0
        },
        {
          "token": "output",
          "start_offset": 9,
          "end_offset": 15,
          "type": "<ALPHANUM>",
          "position": 1
        }
      ]
    },
    "tokenfilters": [
      {
        "name": "snowball",
        "tokens": [
          {
            "token": "detail",
            "start_offset": 0,
            "end_offset": 8,
            "type": "<ALPHANUM>",
            "position": 0,
            "keyword": false
          },
          {
            "token": "output",
            "start_offset": 9,
            "end_offset": 15,
            "type": "<ALPHANUM>",
            "position": 1,
            "keyword": false
          }
        ]
      }
    ]
  }
}
```

