# How to aggregate data with type of long and add a string after each data record?

**URL:** <https://discuss.elastic.co/t/how-to-aggregate-data-with-type-of-long-and-add-a-string-after-each-data-record/184439>\
**Category:** Elasticsearch\
**Created:** [June 5, 2019, 6:22pm UTC](https://discuss.elastic.co/t/how-to-aggregate-data-with-type-of-long-and-add-a-string-after-each-data-record/184439 "2019-06-05T18:22:01Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![vschaefer](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/vschaefer/32/40641_2.png) [@vschaefer](https://discuss.elastic.co/u/vschaefer)\
**Post date:** [June 5, 2019, 6:22pm UTC](https://discuss.elastic.co/t/how-to-aggregate-data-with-type-of-long-and-add-a-string-after-each-data-record/184439/1 "2019-06-05T18:22:02Z")

</div>

I want to aggregate the data with the following query and add a string after each data record

```auto
GET /artikeldaten_de/_search
{
  "size": 0, 
  "aggs": {
    "leuchtenstrom": {
      "terms": {
        "field": "u_leuchtenlichtstrom",
        "size": 50,
        "script": "_value + ' lm'"
      }
    }
  }
}

```

I get the following error:

```auto
{
  "error": {
    "root_cause": [
      {
        "type": "class_cast_exception",
        "reason": "java.lang.String cannot be cast to java.lang.Number"
      }
    ],
    "type": "search_phase_execution_exception",
    "reason": "all shards failed",
    "phase": "query",
    "grouped": true,
    "failed_shards": [
      {
        "shard": 0,
        "index": "artikeldaten_de",
        "node": "WMEp8O05QyubRrC6N6EL-A",
        "reason": {
          "type": "class_cast_exception",
          "reason": "java.lang.String cannot be cast to java.lang.Number"
        }
      }
    ],
    "caused_by": {
      "type": "class_cast_exception",
      "reason": "java.lang.String cannot be cast to java.lang.Number",
      "caused_by": {
        "type": "class_cast_exception",
        "reason": "java.lang.String cannot be cast to java.lang.Number"
      }
    }
  },
  "status": 500
}

```

Is it possible to cast the values into a string? Or do I have to change the mapping for the field?

---

<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 3, 2019, 6:22pm UTC](https://discuss.elastic.co/t/how-to-aggregate-data-with-type-of-long-and-add-a-string-after-each-data-record/184439/2 "2019-07-03T18:22:07Z")

</div>

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