Access nested keys in Groovy

Is there a way to easily check for the existence of a key and subsequently
access keys in complex object (nested, maybe at times 3 levels deep
simplified example doc:
"level1" : {
"level2" : {
"links" : ["", "", "",
"title" : "test123"

This doesn't seem to work (form what I can tell it never finds the key
level1.level2.links even when it does exist)

  "script" : "if (ctx._source.containsKey('level1.level2.links') ) 

{ctx._source.links_url_count = ctx._source['level1.level2.links''].size() }
else { ctx._source.links_url_count = 0 }"

Simple keys work though like ctx._source.containsKey('title')

Does it require intermediate checks for every level (which could be a messy

You received this message because you are subscribed to the Google Groups "elasticsearch" group.
To unsubscribe from this group and stop receiving emails from it, send an email to
To view this discussion on the web visit
For more options, visit