0

I am new to graphdb's and gremlin and struggling with a query I need to come up with I have users(vertex) who can be members of(edge: memberOf) a group a group(vertex), uses in that group can also like (edge: 'likes') certain foods(vertex) that belong to(edge: belongTo) various categories(vertex).

I essentially need a query to return all like edges that fit into a selected category.

For example, a user wants to see who all in his group likes Italian food. I am interested in the like as it has additional properties that will be displayed.

Stanislav Kralin
  • 11,070
  • 4
  • 35
  • 58
xeroshogun
  • 1,062
  • 1
  • 18
  • 31

1 Answers1

3

It's easier to give you a tested answer if you can provide a few addV and addE steps that create a sample graph. However based on what you stated in the question I believe something like this is what you are looking for. I used id to represent the ID of the user doing the search.

g.V(id).
  out('memberOf').
  where(out('likes').has('food','type','Italian'))

You can add to the query if you need to factor in the categories. I was not 100% clear from your question how to factor those in. If you can update the question I will try to update the answer as well.

Kelvin Lawrence
  • 14,674
  • 2
  • 16
  • 38
  • I was thinking that I would have categories be its own vertex label and type would be a property of that vertex but think I will just make it a property of food. You pretty much nailed what I was looking for! – xeroshogun Sep 01 '21 at 23:27