4

Amazon Neptune's implementation of Gremlin allows for multiple labels on vertices (see https://docs.aws.amazon.com/neptune/latest/userguide/access-graph-gremlin-differences.html)

But how to query for vertices by multiple labels?

g.V().hasLabel('label1').hasLabel('label2')

was what I expected, but does not seem to do the trick.

Graphileon
  • 5,275
  • 3
  • 17
  • 31

2 Answers2

4

Given Gremlin semantics, this:

g.V().hasLabel('label1').hasLabel('label2')

means that you're doing an "and" operation so the vertices must have "label1" and "label2". If you want an "or" operation where the vertices can have either "label1" or "label2" then you'd probably need to change that to:

g.V().or(hasLabel('label1'),hasLabel('label2'))

Not sure if that solves your problem with Neptune in what you want to query but that's what Gremlin expects.

stephen mallette
  • 45,298
  • 5
  • 67
  • 135
3

As an interim measure you could try doing hasLabel('label1').fold().unfold().hasLabel('label2')

Kelvin Lawrence
  • 14,674
  • 2
  • 16
  • 38
  • 1
    Thanks Kelvin. It looks like a workaround, but at least it returns the expected result. I hope AWS Neptune will soon support the simpler g.V().hasLabel('label1').hasLabel('label2') – Graphileon Dec 21 '18 at 08:41
  • hmm - that's interesting, does `g.V().hasLabel('label1').barrier().hasLabel('label2')` also work? – stephen mallette Dec 31 '18 at 12:29
  • @stephenmallette - no, barrier doesn't fix the problem (thanks anyway) – Gedge Jun 05 '19 at 15:55