local

Limit the operation of the traversal to a single element within the traversal.

Synopsis

local(traversal)
Table 1. Legend
Syntax conventions Description
Lowercase and uppercase Literal keyword. Includes ().
Italics Variable value. Replace with a user-defined value.
[] Optional. Square brackets ( [] ) surround optional command arguments. Do not type the square brackets.
{} Group. Braces ( {} ) identify a group to choose from. Do not type the braces.
| Or. A vertical bar ( | ) separates alternative elements. Type any one of the elements. Do not type the vertical bar.
... Repeatable. An ellipsis ( ... ) indicates that you can repeat the syntax element as often as required.

Description

The local() step is a branch step that allows the action within the step to be applied to the element within the local() step.

Examples

Get a list of all people and the countries they have lived in, ordered by the year that the person started living in the country:
g.V().hasLabel('person').as('person').
   local(properties('country').order().by('startYear', incr).limit(2)).value().as('country').
   select('person','country').
      by('name').by()
Here, local() is used to restrict the sorting by the meta-property startYear for each person.
g.V().has('person','personId','1').local(outE('created').has('createDate', gte('1962-03-03')).order().by('createDate'))
// explain
//g.V().hasLabel('person').outE('reviewed').has('stars', gte(1)).order().by('stars').profile()
// Sorts the reviews by stars for each user - uses the edge index
//g.V().hasLabel('person').local(outE('reviewed').has('stars', gte(1)).order().by('stars')).profile()
// Sorts the users by name, and then their reviews by stars
//g.V().hasLabel('person').order().by('name').local(outE('reviewed').has('stars', gte(1)).order().by('stars')).profile()