# Term Aggregation

**URL:** <https://discuss.elastic.co/t/term-aggregation/48002>\
**Category:** Elasticsearch\
**Created:** [April 21, 2016, 8:31am UTC](https://discuss.elastic.co/t/term-aggregation/48002 "2016-04-21T08:31:34Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![maher](https://avatars.discourse-cdn.com/v4/letter/m/a6a055/32.png) [@maher](https://discuss.elastic.co/u/maher)\
**Post date:** [April 21, 2016, 8:31am UTC](https://discuss.elastic.co/t/term-aggregation/48002/1 "2016-04-21T08:31:34Z")

</div>

Hi, I am trying to group distinc products:

```
    Post localhost:9200/logstash-2016.04.18/_search
            {
                "aggs": {
                "DistincProduct": {
                 "terms": {
                 "field": "productcode"
                        }
                     }
                  }
              }

```

and this is the result:

```
             {
               "error": {
               "root_cause": [
             {
                 "type": "illegal_state_exception",
                 "reason": "Field data loading is forbidden on [productcode]"
              }
               ],
                 "type": "search_phase_execution_exception",
                 "reason": "all shards failed",
                 "phase": "query",
                 "grouped": true,
                 "failed_shards": [
             {
                 "shard": 0,
                 "index": "logstash-2016.04.18",
                 "node": "VPzQxOtkRk6oF3r6rOA3yg",
                 "reason": {
                 "type": "illegal_state_exception",
                "reason": "Field data loading is forbidden on [productcode]"
               }
              }
             ] 
           },
           "status": 500
            }

```

And this is the corresponding mapping for the ProductCode field:

```
      "productcode": {
        "type": "string",
        "norms": {
          "enabled": false
        },
        "fielddata": {
          "format": "disabled"
        },
        "fields": {
          "raw": {
            "type": "string",
            "index": "not_analyzed",
            "ignore_above": 256
          }
        }
      }

```

Thank you in advence, i really need an answer .

---

<div class="post-metadata">

**Author:** ![Mark\_Harwood](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/mark_harwood/32/10538_2.png) [@Mark\_Harwood](https://discuss.elastic.co/u/Mark_Harwood)\
**Post date:** [April 21, 2016, 8:37am UTC](https://discuss.elastic.co/t/term-aggregation/48002/2 "2016-04-21T08:37:29Z")

</div>

Did you define the mapping? Someone has disabled the loading of data from disk into RAM - possibly for good reason.

See [https://www.elastic.co/guide/en/elasticsearch/reference/2.3/fielddata.html#fielddata-format](https://www.elastic.co/guide/en/elasticsearch/reference/2.3/fielddata.html#fielddata-format)

---

<div class="post-metadata">

**Author:** ![maher](https://avatars.discourse-cdn.com/v4/letter/m/a6a055/32.png) [@maher](https://discuss.elastic.co/u/maher)\
**Post date:** [April 21, 2016, 8:54am UTC](https://discuss.elastic.co/t/term-aggregation/48002/3 "2016-04-21T08:54:12Z")

</div>

Thank you, changing the mapping of the field worked fine with me

```
          {
              "logs": {
              "properties": {
               "productcode": {
                "type": "string",
                "omit_norms": {
               "enabled": true
             },
               "fielddata": {
               "format": "enabled" 
                     }
                  }
                }
             }
          }
```

---

<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:** [July 5, 2017, 10:57pm UTC](https://discuss.elastic.co/t/term-aggregation/48002/4 "2017-07-05T22:57:24Z")

</div>


