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
unfortunately)
simplified example doc:
{
"level1" : {
"level2" : {
"links" : ["http://bit.ly/abc", "http://bit.ly/abc", "http://bit.ly/def",
"http://bit.ly/ghi"]
}
},
"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
script)?

--
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 elasticsearch+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/elasticsearch/c3d0e9aa-ac68-4775-85d2-06a0bf3f3bd4%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.