Skip to main content
All CollectionsData AnalysisGremlin training
Gremlin Training 3: Basic filtering steps - hasLabel()
Gremlin Training 3: Basic filtering steps - hasLabel()

Learn to use the hasLabel()-step to filter and search for components and references based on their type.

Kristine Marhilevica avatar
Written by Kristine Marhilevica
Updated over a year ago

Assume that we already have a Gremlin query which finds all components in the organization:

g.V()
gremlin

If we wish to limit the search to components of a specific type, we can use the hasLabel()-step. The following query limits the search to include all components of type Instrument:

g.V().hasLabel('Instrument')
component

It is also possible to pass multiple component types to the hasLabel()-step. The following query finds all components whose type is either "Person" or "Instrument":

g.V().hasLabel('Person', 'Instrument')
2 component types

The hasLabel()-step can also be used to filter references based on their type. The following query finds all references whose type is "Likes".

g.E().hasLabel('Likes')

reference

Did this answer your question?