# How can I run analytics on elasticsearch using aggregations without getting the fielddata error?

**URL:** https://discuss.elastic.co/t/how-can-i-run-analytics-on-elasticsearch-using-aggregations-without-getting-the-fielddata-error/87589
**Category:** Elasticsearch
**Created:** [May 30, 2017, 3:11pm UTC](https://discuss.elastic.co/t/how-can-i-run-analytics-on-elasticsearch-using-aggregations-without-getting-the-fielddata-error/87589 "2017-05-30T15:11:15Z")
**Posts on this page:** 2
**Page:** 1

<div class="post-metadata">

### Author: ![Imad\_Youbi\_Idrissi](https://avatars.discourse-cdn.com/v4/letter/i/bb73d2/32.png) [@Imad\_Youbi\_Idrissi](https://discuss.elastic.co/u/Imad_Youbi_Idrissi)
#### Post date: [May 30, 2017, 3:11pm UTC](https://discuss.elastic.co/t/how-can-i-run-analytics-on-elasticsearch-using-aggregations-without-getting-the-fielddata-error/87589/1 "2017-05-30T15:11:15Z")

</div>

Dear community,

I am a complete newbie in elasticsearch, I am up to the [Getting started - analytics](https://www.elastic.co/guide/en/elasticsearch/guide/current/_analytics.html) part of the book.  
I use Kibana in order to view the examples provided with the tutorial, but I bump into an issue by trying to apply this aggregation (as indicated by the book):

```
GET /megacorp/employee/_search
{
  "query": {
    "match": {
      "last_name": "smith"
    }
  },
  "aggs": {
    "all_interests": {
      "terms": {
        "field": "interests"
      }
    }
  }
}

```

The issue in question is documented many times. E.g: [Stack overflow: how to set fielddata=true in kibana](https://stackoverflow.com/questions/38145991/how-to-set-fielddata-true-in-kibana) and also on [Github](https://github.com/elastic/elasticsearch/issues/22633), but seeing as I am only up to the **Getting started** part of the book, it should be understandable that I don't comprehend how to apply the solutions found in those forums.  
So what I request is a **simple, stupid** explanation of why this happens (so I can get smarter), and also a solution to be able to fix this:

Suggestions:

- Either to make fielddata=true happen,
- Or as the stacktrace bellow suggests:

> Alternatively use a keyword field instead

Here is the stacktrace related to this issue:

```
{
  "error": {
    "root_cause": [
      {
        "type": "illegal_argument_exception",
        "reason": "Fielddata is disabled on text fields by default. Set fielddata=true on [interests] in order to load fielddata in memory by uninverting the inverted index. Note that this can however use significant memory. Alternatively use a keyword field instead."
      }
    ],
    "type": "search_phase_execution_exception",
    "reason": "all shards failed",
    "phase": "query",
    "grouped": true,
    "failed_shards": [
      {
        "shard": 0,
        "index": "megacorp",
        "node": "TgrGa5mFTn-SFQssnJC1Nw",
        "reason": {
          "type": "illegal_argument_exception",
          "reason": "Fielddata is disabled on text fields by default. Set fielddata=true on [interests] in order to load fielddata in memory by uninverting the inverted index. Note that this can however use significant memory. Alternatively use a keyword field instead."
        }
      }
    ]
  },
  "status": 400
}

```

FYI: I have followed the book's [Let's build an employee directory - use case](https://www.elastic.co/guide/en/elasticsearch/guide/current/_indexing_employee_documents.html).

Best regards,  
Imad.

---

<div class="post-metadata">

### Author: ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)
#### Post date: [June 27, 2017, 3:11pm UTC](https://discuss.elastic.co/t/how-can-i-run-analytics-on-elasticsearch-using-aggregations-without-getting-the-fielddata-error/87589/2 "2017-06-27T15:11:19Z")

</div>

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.
