All Collections
Data Analysis
Gremlin training
Gremlin Training 4: Basic filtering steps - has()
Gremlin Training 4: Basic filtering steps - has()

Learn to use the has()-step and hasLabel()-step to filter components and references based on their field values.

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

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

gremlin query

If we wish to limit the search to components with a specific field value, we can use the has()-step. The following query limits the search to include all components whose name is "Ardoq".

g.V().has('name', 'Ardoq')
component name Ardoq

When inspecting the details of a component from a Gremlin result in Ardoq, you might have seen what appears to be an "_id" property and a "type" property. Those are not actual properties, and one cannot filter on those using the has()-step. Instead, one will have to use the hasId()-step and the hasLabel()-step, respectively.


Recall that when we used the hasLabel()-step to filter components and references based on their type, we wrote the component and reference types exactly as they appear in the app. Field names are a bit different. Field names in Gremlin use neither uppercase characters nor spaces. When creating a field in Ardoq, the corresponding field that is available in Gremlin has its uppercase characters replaced with lowercase characters, and spaces replaced with underscores. In the example above, we filter on the Name value, which is referred to as "name" in Gremlin. The value, however, is not altered. In the following example, we find all components where the Contact Email field is "". Notice how The field called Contact Email is referred to as "contact_email" in Gremlin:

g.V().has('contact_email', '')

Values created using checkbox fields in Ardoq are represented as the boolean values true and false, corresponding to checked and unchecked, respectively.

The following query will find all components which have a field called "Some Checkbox Field" which is checked.

g.V().has('some_checkbox_field', true) 

Until now, we have looked at using the has()-step with two arguments, the first argument being the field name and the second argument being the field value. It is also possible to pass only a field name to the has()-step. This will filter away all the components or references which do not have this field, or do not have a value set for this field. The following query finds all components which have a value set for the field Contact Email.


In the simple workspace we have visualized here, we see that all the components of type "Person", except the one named Tom Zaloga, have a "Contact Email" field which is filled out.

contact email field

Lastly, as a compact way to filter on component type and field value at the same time, it is possible to call the has()-step with three values. The first value is the type, the second value is the field name and the last value is the field value.

The following query finds all components of type Person whose Contact Email is "":


The above query is equivalent to the following:

has('contact_email', '')

Did this answer your question?