Are you trying to produce the same as your current queries, except to only include the entityCode
instead of the complete vertices?
If so, I believe the solution you're looking for is tree().by('entityCode')
. There are some relevant examples in the reference docs for the tree step: https://tinkerpop.apache.org/docs/3.7.3/reference/#tree-step