Accessing nested objects in a filter script

Is there a way to access nested objects in a filter script? I found several relevant questions on this forum, but all are without answers. I got a mapping:

    "properties": {
      "locations": {
        "type": "nested",
        "properties": {  "kind": { "type": "keyword" }  }
      }
    }

I tried using doc['locations.kind'], but it shows up as empty.

I need this to implement custom filtering based on analyzing the entire set of nested objects for each parent object in a way that cannot be accomplished using builtin elasticsearch filters. If it's not possible to access nested objects in a script, would it be possible from an elasticsearch plugin?