1

I have a Janusgraph database which contains nodes with the label 'Paper', the node properties 'paperTitle' and 'year' and the edge type 'References'.

I'm trying to write a query that will allow me to select two papers by title and all their references and assign that result to a subgraph.

I can select one paper using two conditions like this:

sg = g.V().
     and(has('Paper', 'paperTitle', 'ladle pouring guide'), has('Paper', 'year', '1950')).
     inE('References').
     subgraph('sg1').
     cap('sg1').
     next()

Using this query as my starting point I had hoped I could do this:

sg = g.V().
     or(has('Paper', 'paperTitle', 'ladle pouring guide'), has('Paper', 'paperTitle', 'the development of the human mandibular joint')).
     inE('References').
     subgraph('sg1').
     cap('sg1').
     next()

But this returns a subgraph with 0 nodes and 0 edges.

I saw this page in the Janusgraph documentation http://tinkerpop.apache.org/docs/current/reference/#or-step but it seems to only describe selections of multiple edges not multiple node properties.

Is it possible to create this kind of subgraph or do I need to runs these as two separate queries?

Matt
  • 437
  • 2
  • 14

1 Answers1

1

I don't see why you can't do this in one query and I'm not sure why your traversal doesn't work, however I would write it as:

sg = g.V().
     has('Paper', 'paperTitle', within('ladle pouring guide', 
                                       'the development of the human mandibular joint')).
     inE('References').
     subgraph('sg1').
     cap('sg1').
     next()
stephen mallette
  • 45,298
  • 5
  • 67
  • 135
  • If that does not fix your problem you might need to include some sample data to demonstrate the problem like this: https://stackoverflow.com/questions/51388315/gremlin-choose-one-item-at-random – stephen mallette Apr 13 '20 at 11:04