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

Dear community,

I am a complete newbie in elasticsearch, I am up to the Getting started - analytics 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 and also on Github, 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.

Best regards,
Imad.

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