---
type: api
title: Get terms in an index
description: **All methods and paths for this operation:**
url: https://www.elastic.co/elastic/docs-builder/docs/4371/api/doc/elasticsearch/operation/operation-terms-enum
resource: https://www.elastic.co/elastic/docs-builder/docs/4371/api/doc/elasticsearch/operation/operation-terms-enum
products:
  - Elasticsearch
---

# Get terms in an index


Availability: 7.14+

## Paths

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

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

#### Path Parameters

- `index` (union IndexName | [] IndexName)
  A comma-separated list of data streams, indices, and index aliases to search.
Wildcard (`*`) expressions are supported.
To search all data streams or indices, omit this parameter or use `*`  or `_all`.

## Description

Discover terms that match a partial string in an index.
This API is designed for low-latency look-ups used in auto-complete scenarios.

> info
> The terms enum API may return terms from deleted documents. Deleted documents are initially only marked as deleted. It is not until their segments are merged that documents are actually deleted. Until that happens, the terms enum API will return terms from these documents.

## Request Body

`application/json`

- `field` (string Field) — required
  The string to match at the start of indexed terms. If not provided, all terms in the field are considered.
- `size` (number · default: 10) — optional
  The number of matching terms to return.
- `timeout` (string Duration · default: 1s) — optional
  The maximum length of time to spend collecting results.
If the timeout is exceeded the `complete` flag set to `false` in the response and the results may be partial or empty.
- `case_insensitive` (boolean · default: false) — optional
  When `true`, the provided search string is matched against index terms without case sensitivity.
- `index_filter` ({} QueryContainer) — optional
  Filter an index shard if the provided query rewrites to `match_none`.
  See [QueryContainer](https://www.elastic.co/elastic/docs-builder/docs/4371/api/doc/elasticsearch/types/_types-query_dsl-querycontainer)
- `string` (string) — optional
  The string to match at the start of indexed terms.
If it is not provided, all terms in the field are considered.

> info
> The prefix string cannot be larger than the largest possible keyword value, which is Lucene's term byte-length limit of 32766.
- `search_after` (string) — optional
  The string after which terms in the index should be returned.
It allows for a form of pagination if the last result from one request is passed as the `search_after` parameter for a subsequent request.

## Response

`application/json`

- `_shards` ({} ShardStatistics)
  - `failed` (number uint)
    The number of shards the operation or search attempted to run on but failed.
  - `successful` (number uint)
    The number of shards the operation or search succeeded on.
  - `total` (number uint)
    The number of shards the operation or search will run on overall.
  - `failures` ([] ShardFailure)
    - `index` (string IndexName)
    - `node` (string)
    - `reason` ({} ErrorCause)
      - `type` (string)
        The type of error
      - `reason` (union string) — nullable
        A human-readable explanation of the error, in English.
        One of: `string`
      - `stack_trace` (string)
        The server stack trace. Present only if the `error_trace=true` parameter was sent with the request.
      - `caused_by` ({} ErrorCause) — recursive
        Same fields as `reason` in `failures`
      - `root_cause` ([] ErrorCause) — recursive
        Same fields as `reason` in `failures`
      - `suppressed` ([] ErrorCause) — recursive
        Same fields as `reason` in `failures`
    - `shard` (number)
    - `status` (string)
    - `primary` (boolean)
  - `skipped` (number uint)
- `terms` ([] string)
- `complete` (boolean)
  If `false`, the returned terms set may be incomplete and should be treated as approximate.
This can occur due to a few reasons, such as a request timeout or a node error.
## Code Examples

#### Console

```console
POST stackoverflow/_terms_enum
{
    "field" : "tags",
    "string" : "kiba"
}
```

#### JavaScript

```javascript
const response = await client.termsEnum({
  index: "stackoverflow",
  field: "tags",
  string: "kiba",
});
```

#### Python

```python
resp = client.terms_enum(
    index="stackoverflow",
    field="tags",
    string="kiba",
)
```

#### curl

```curl
curl -X POST "$ELASTICSEARCH_URL/stackoverflow/_terms_enum" \
  -H "Authorization: ApiKey $ELASTIC_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "field": "tags",
    "string": "kiba"
  }'
```

#### Java

```java
client.termsEnum(t -> t
    .field("tags")
    .index("stackoverflow")
    .string("kiba")
);
```

#### C#

```c#
var response = await client
    .TermsEnumAsync(indices: new[] { "stackoverflow" }, d1 => d1
        .Field(x => x.Tags)
        .String("kiba")
    );
```

#### PHP

```php
$resp = $client->termsEnum([
    "index" => "stackoverflow",
    "body" => [
        "field" => "tags",
        "string" => "kiba",
    ],
]);
```

#### Ruby

```ruby
response = client.terms_enum(
  index: "stackoverflow",
  body: {
    "field": "tags",
    "string": "kiba"
  }
)
```

## Response Examples

#### Terms enum response example1

A successful response from `POST stackoverflow/_terms_enum`.

```json
{
  "_shards": {
    "total": 1,
    "successful": 1,
    "failed": 0
  },
  "terms": [
    "kibana"
  ],
  "complete" : true
}
```

