0

I am trying to do a query in Gremlin similar to the following.

SELECT * FROM profiles WHERE firstName like 'John' OR lastName like 'John'

both firstName and lastName are properties of one vertex

Stanislav Kralin
  • 11,070
  • 4
  • 35
  • 58
sinthu225
  • 301
  • 3
  • 16

1 Answers1

0

Assuming that profiles is a node label (akin to a table name in SQL), and that the column names are properties on a node, the simple Gremlin form (without like) would be something like:

g.V().hasLabel('profile').
  or(has('firstName','John'),has('lastName','John'))

However, the Gremlin language (before release 3.6) did not have a way to express anything along the lines of like. Some implementations offer language extensions or integration with an external index such as Elastic Search or Open Search. In those cases that is a way to achieve the like functionality.

Starting with TinkerPop 3.6 a new regex text predicate has been added. So the query above can be re-written using any supported regular expression. For example, a simple case where you are not sure if the name is capitalized might be queried using:

g.V().hasLabel('profile').
  or(has('firstName',regex('[J|j]ohn')),has('lastName',regex('[J|j]ohn'))) 

It may take a while before implementations move up to this new level, but once they do, this is one way to address queries that need vaguer searches.

Kelvin Lawrence
  • 14,674
  • 2
  • 16
  • 38