# Elasticsearch: illegal_argument_exception: Fielddata is disabled on text fields by default

**Code:** `fielddata is disabled on text fields` · **Category:** API · **Seen on:** Elasticsearch, OpenSearch

A sort or aggregation targeted a `text` field, which is analysed and not sortable.

## Meaning

Aggregations and sorting need `doc_values`, available on `keyword` fields. Dynamic mappings create a `text` field with a `.keyword` sub-field.

## Common causes

- Aggregating on the `text` field instead of `field.keyword`
- Mapping has no keyword sub-field
- Enabling fielddata to silence the error (memory heavy)

## Quick fix

1. Use the `.keyword` sub-field in sort and aggs
2. Map the field as `keyword`
3. Avoid `fielddata: true` on large indices

## Detailed fix by platform

### Elasticsearch

1. `"aggs": {"by_city": {"terms": {"field": "city.keyword"}}}`

## How to diagnose

1. **Type** — text or keyword?
2. **Subfield** — .keyword exists?
3. **Memory** — Heap pressure?

---
Source: [WhatIsMyError](https://whatismyerror.com/errors/api/elasticsearch-fielddata-disabled-text)
