# Runtime Fields with subnested fields

**URL:** <https://discuss.elastic.co/t/runtime-fields-with-subnested-fields/287218>\
**Category:** Elasticsearch\
**Tags:** runtime-fields\
**Created:** [October 20, 2021, 3:44pm UTC](https://discuss.elastic.co/t/runtime-fields-with-subnested-fields/287218 "2021-10-20T15:44:20Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![rreverol](https://avatars.discourse-cdn.com/v4/letter/r/8e8cbc/32.png) [@rreverol](https://discuss.elastic.co/u/rreverol)\
**Post date:** [October 20, 2021, 3:44pm UTC](https://discuss.elastic.co/t/runtime-fields-with-subnested-fields/287218/1 "2021-10-20T15:44:21Z")

</div>

I have the following doc mapping

```auto
{
  "mappings": {
    "security": {
      "properties": {
        "id": {
          "type": "keyword"
        },
        "trades": {
          "type": "nested",
          "properties": {
            "yield": {
              "type": "double"
            },
            "prices": {
              "type": nested,
              "properties": {
                "transacionType": {
                  "type": "keyword"
                },
                "priceValue": {
                  "type": "double"
                }
              }
            }
          }
        }
      }
    }
  }
}

```

And the search body:

```auto
{
  "runtime_mappings": {
    "trades.sellPrice": {
      "type": "double",
      "script": {
        "source": "for (def price : doc('trades.prices')) { if(price.transacionType == 'sell') {emit(price.priceValue)} }"
      }
    }
  },
  "query": {
    "match": {
      "id": "securityId"
    }
  },
  "aggs": {
    "trades": {
      "nested": {
        "path": "trades"
      },
      "aggs": {
        "minSellPrice": {
          "min": {
            "field": "trades.sellPrice"
          }
        }
      }
    }
  }
}

```

That runtime mapping is not working because I am not able to get the value of subnested field  
trades.prices. It seems to be because I don't have "subnested" context, only nested which is at the level of trades. Am I right ? Is there a workaround for using "subnested" properties in my runtime field script ?

---

<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:** [November 17, 2021, 3:44pm UTC](https://discuss.elastic.co/t/runtime-fields-with-subnested-fields/287218/2 "2021-11-17T15:44:24Z")

</div>

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