# How to use runtime mapping on field that is nested

**URL:** <https://discuss.elastic.co/t/how-to-use-runtime-mapping-on-field-that-is-nested/339853>\
**Category:** Elasticsearch\
**Tags:** runtime-fields\
**Created:** [August 1, 2023, 7:57pm UTC](https://discuss.elastic.co/t/how-to-use-runtime-mapping-on-field-that-is-nested/339853 "2023-08-01T19:57:18Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![jlucas](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/jlucas/32/90984_2.png) [@jlucas](https://discuss.elastic.co/u/jlucas)\
**Post date:** [August 1, 2023, 7:57pm UTC](https://discuss.elastic.co/t/how-to-use-runtime-mapping-on-field-that-is-nested/339853/1 "2023-08-01T19:57:18Z")

</div>

Lets say I have the following document on some index.

```auto
{
  "_source" : {
    "process1": {
      "part1": {
        "start": "2022-10-04T18:35:01.540Z",
        "end": "2022-10-04T18:35:01.540Z"
      },
      "part2": {
        "start": "2022-10-04T18:35:38.433Z",
        "end": "2022-10-04T18:35:38.433Z"
      }
    },
    "fileName": "1033977731.PDF",
    "startDate": "2022-10-04T18:35:01.540Z"
    }
  }

```

What I want to do is create a runtime field so that my documents in the search results have an elaspedTime calculated from a script in a runtime field. I know there is documentation on how to define a runtime field in the mappings, but it not apparent how to do this for nested fields or fields on objects. **How would I define the runtime mapping to do this?**

```auto
{
  "_source" : {
    "process1": {
      "part1": {
        "start": "2022-10-04T18:35:01.540Z",
        "end": "2022-10-04T18:35:01.540Z",
        "elaspedTime": 0 <-- Runtime field
      },
      "part2": {
        "start": "2022-10-04T18:35:38.433Z",
        "end": "2022-10-04T18:35:38.433Z",
        "elaspedTime": 0 <--Runtime field
      }
    },
    "fileName": "1033977731.PDF",
    "startDate": "2022-10-04T18:35:01.540Z"
    }
  }

```

---

<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:** [August 29, 2023, 7:57pm UTC](https://discuss.elastic.co/t/how-to-use-runtime-mapping-on-field-that-is-nested/339853/2 "2023-08-29T19:57:46Z")

</div>

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