Runtime Fields with subnested fields

I have the following doc mapping

{
  "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:

{
  "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 ?

2 Likes

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