How to match parameters in the cayley console


#1

Hi All

I have a small doubt regarding the match for the source,target and the relation in the cayley console.

I have written a below query to match all the 3 parameters from the cayley database.but I am not able to understand how to match the 3rd parameter target in the below query.

In the below output I am getting 2 comma separated results but I want only one output as to match all the 3 parameters.

1st parameter : app-1501220821766
2nd parameter : RunsOn (relation name)
3rd parameter : srv-1501166269730 (Not able to understand how to pass it to get only the one result)

Query : graph.V(‘app-1501220821766’).As(‘source’).Out(‘RunsOn’,‘relation’).As(‘target’).All();

Output : {“result”:[{“id”:“srv-1501166269730”,“relation”:“RunsOn”,“source”:“app-1501220821766”,“target”:“srv-1501166269730”},{“id”:“srv-1501222746307”,“relation”:“RunsOn”,“source”:“app-1501220821766”,“target”:“srv-1501222746307”}]}

Thanks in advance.


#2

It is possible to apply number of filters as long as they are connected. For example you can chain your existing query with an additional predicate on the incoming edges of “srv-1501166269730”.


#3

@DroidPoe Thanks for the quick response.
can you please help me out with the small example.


#4

To match all 3 parameters you can use Has instead of Out:

g.V('app').Has('RunsOn', 'srv')

But in this case the Result node (id) will point to an App instead of Server. This query can be used to quickly check if you have a relation or not.

If you want to check the relation and traverse to node, you can either “reverse” your query (use HasReverse):

g.V('srv').HasR('RunsOn', 'app')

or traverse to node and check it’s value:

g.V('app').Out('RunsOn').Is('srv')

And you can still tag nodes with As along the way.

Hope this answers your question.


#5

Thanks @dennwc

But when I am trying below queries in the cayley UI console, I am getting null response.

Query : g.V(‘app-1501220821766’).Has(‘RunsOn’, ‘srv-1501166269730’)
Output : {“result”:null}

Query : g.V(‘app-1501220821766’).Out(‘RunsOn’).Is(‘srv-1501166269730’)
Output : {“result”:null}


#6

I got it @dennwc

Thank you so much.