Search code examples
propertiesfindgremlinvertextinkerpop3

Graphdb Gremlin query to find vertices by property value match


Assuming a simple a graphdb content in an AWS Neptune property graph that in shown at

http://tinkerpop.apache.org/docs/current/reference/#graph-computing

i am looking for a pure gremlin solution to find vertices that have at least one property value from property value set of reference vertex. The solution needs to work with more than one values for the given property. ie a vertex should be found if it has at least one value in common. In this example, we are looking for all the vertices that have the same (in case of multiple values, at least one) 'lang' property value(s) that V(3) has.

Tried:

g.V().has('lang', within(V(3).properties('lang')))
g.V().has('lang', within(V(3).properties('lang').value()))
g.V().has('lang', within(V(3).valueMap('lang')))

These seem to scan through the database but returns no results. Probably within() is not the right step here.

Preferably it needs to be a single query, without having to read out the reference property values first and assemble a string list for within. Any pure Gremlin tricks or techniques are welcome.


Solution

  • I suppose the direct answer to your question would be to do something like:

    gremlin> g.V(3).as('x').V().hasLabel('software').where(neq('x')).where(eq('x')).by('lang')
    ==>v[5]
    

    I say "suppose" because while this traversal mechanically gets the answer you want, you'd want to be careful that you don't end up with a full graph scan on your mid-traversal V(). So you would want to be sure that you had a graph database that would optimize this traversal with an index somehow or a small enough dataset on which to do the search.