Term Aggregation

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 .

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

1 Like

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

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