has

Filter based on a particular vertex or edge label, property key, or property value.

The has() step is a filter step. It is the most common step used for graph traversals, since this step narrows the query to find particular vertices or edges with certain property keys or property values. Although the most performant method of using the has() step is to fully define with a label, property key and property value, several other options are available:
  • property key
  • property key and property value
  • vertex or edge label, property key and property value (recommended)
  • property key and predicate

Synopsis

has( 
[ 'vertexLabel' | 'edgeLabel' , ]  
{
[ predicate ('propertyKey_value', ... ) ] 
|
'propertyKey_name', [ 'propertyKey_value' ]
} 
)
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.

Examples

Find all items that use a property key name:
g.V().has('name'))
Find the item that has a property key name with a property value taco:
g.V().has('name', 'taco')
Find the item with a vertex label meal_item with a property key name and property value taco:
g.V().has('meal_item', 'name', 'taco')
Find the items have a property key name with property values taco or burrito:
g.V().has('name',within('taco','burrito'))