# Calculate sum of run\_time without runtime fields?

**URL:** <https://discuss.elastic.co/t/calculate-sum-of-run-time-without-runtime-fields/292267>\
**Category:** Elasticsearch\
**Created:** [December 17, 2021, 6:56am UTC](https://discuss.elastic.co/t/calculate-sum-of-run-time-without-runtime-fields/292267 "2021-12-17T06:56:28Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![afkbrb](https://avatars.discourse-cdn.com/v4/letter/a/43a26b/32.png) [@afkbrb](https://discuss.elastic.co/u/afkbrb)\
**Post date:** [December 17, 2021, 6:56am UTC](https://discuss.elastic.co/t/calculate-sum-of-run-time-without-runtime-fields/292267/1 "2021-12-17T06:56:28Z")

</div>

I want to get the sum of run\_time variant, by using runtime\_mapping I got mistakes.  
I know that it'a new feature in ES 7.12, but I can't upgrade it because it's not depend on me.  
So how could I get the answer without runtime\_mapping?

```auto
GET log/_search
{
  "query": {
    "bool": {
                "must": [
                {
                    "match": {
                    "username": "xxx"
                    }
                },{
                  "range": {
                    "time_end": {
                        "gte": "2021-12-01 11:40:06",
                        "lte": "2021-12-12 11:40:06"
                    }
                    }
                }
                ]
          }
  }
  , "_source": ["username", "time_start","time_submit", "time_end", "gpus_alloc"]
  ,
  "runtime_mappings": {
    "exec_time.weighted": {
      "type": "long",
      "script": """
        long exec_time;
        long timediff = doc['time_end'].date.getMillis() - doc['time_start'].date.getMillis();
        String gpus = doc['gpus_alloc.keyword'].value;
        int idx = gpus.lastIndexOf(':');
        if(idx != -1)
           exectime = timediff * Integer.parseInt(gpus.substring(idx+1));
        else
           exectime = 0;
        emit(exectime);
      """
    }
  },
  "aggs": {
    "U1": {
      "sum": {
        "field": "exec_time.weighted"
      }
    }
  }
}

```

**the Error information is as follow:**

```auto
{
  "error": {
    "root_cause": [
      {
        "type": "parsing_exception",
        "reason": "Unknown key for a START_OBJECT in [runtime_mappings].",
        "line": 22,
        "col": 23
      }
    ],
    "type": "parsing_exception",
    "reason": "Unknown key for a START_OBJECT in [runtime_mappings].",
    "line": 22,
    "col": 23
  },
  "status": 400
}

```

---

<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:** [January 14, 2022, 6:57am UTC](https://discuss.elastic.co/t/calculate-sum-of-run-time-without-runtime-fields/292267/2 "2022-01-14T06:57:11Z")

</div>

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