I want to find every edges connect by Vertices with the name "bob".
What can't be the correct SQL request?
You can use this query:
select expand(bothE()) from User where name = "bob"
Hope it helps.
UPDATE:
Try this query:
select * from E where in.name = "bob" and out.name = "bob"
Related
I want to do a query in OrientDB but i don't know how it works.
I'm using the Graph API and my DB looks like this:
class(V): #route (Name, Start, Length, Goal)
class(V): #direction (Goal, length)
class(E): #has_A
class(E): #start_Direction
class(E): #has_Follower
The Edges are connected to the Vertices like this:
route -> has_A -> direction
route -> start_Direction -> direction
direction -> has_Follower -> direction
now i need to find all followers by the name of the route,
what works so far is when i enter a rid (of the class startDirection) directly to the query for example:
select * from (traverse outE('has_Follower'),has_Follower.in from #??:?) where #class='direction'
But now i need to get to the rid over the Name of the route (which is the problem), what i tried so far is:
select * from (traverse outE('has_Follower'),has_Follower.in from (select #rid from start_Direction where start_Direction.out = (select #rid from route where Name = 'nameOfroute'))) where #class='direction'
But this gives me an empty query, although when i type in the rid from start_Direction of which i know has a has_Follower it works.
Hope this is understandable, thanks for any help in advance.
One problem in your query is probably start_Direction.out = (select..., you have to use an IN instead of an =, eg start_Direction.out IN (select....
In general, I think the easiest way to do what you need is as follows:
MATCH
{class:route, as:route} -start_Direction-> {} -has_Follower-> {as:direction, while:(true)}
RETURN route.#rid, route.Name, route.Start, route.Length, route.Goal, direction.Goal, direction.length
Or just RETURN $elements if you want single records per row
I ran a query like this:
select urlName from User where urlName like 'Nkj-Fm20%';
Which returns one record.
But when I run a query like this:
select * from User where urlName = 'Nkj-Fm20'
No record is found.
Can you help me?
the like operator allow usage of % jolly character, while the = doesn't. So with your second query it returns only the users with the exact urlName Nkj-Fm20.
Ivan
I'm trying to write a OSQL query for computing the length of the shortest path between all pairs of nodes but, since having more than one class in the FROM clause is not allowed, I am wondering how I can loop over all the pairs of different nodes.
I tried with this query:
SELECT shortestPath($current, $e0, 'BOTH', 'Meets')
FROM Employee
LET $e0 = (SELECT FROM Employee where $current.nt_account > $parent.nt_account)
(nt_account is the Employee ID).
When I try to execute the query I get the following error:
java.lang.IllegalArgumentException: Vertex id can not be null
Can anybody help me?
Cheers!
Try this query
select from (select $b.shortestPath from Employee let $b= ( SELECT shortestPath($parent.current,#this, 'BOTH', 'Meets') from Employee)) unwind $b
I am trying to write a search query where in the input is some search key and the requirement is to search among the vertices where the given input key matches the value of two or more property keys of the vertex. For example assuming that I have user vertices in my graph db with the following property keys:
1) User first name
2) User last name
3) User email
Now given a search key 'xyz' I have to search across the user vertices where any of the above three property keys matches the value 'xyz'. This is how I have approached the problem.
g.V.has('ENTITY_TYPE', 'USER').or(_().has('USER_EMAIL' , TEXT.REGEX , '.*xyz.*') , _().has('USER_FNAME' , TEXT.REGEX , '.*xyz.*''USER_EMAIL' , TEXT.REGEX , '.*xyz.*') , _().has('USER_LNAME' , TEXT.REGEX , '.*xyz.*')).dedup();
I have created the required mixed indices (three separate mixed indices) for USER_EMAIL, USER_FNAME and USER_LNAME as follows:
key = m.makePropertyKey("USER_EMAIL").dataType(String.class).make();
m.buildIndex("serachbyemail",Vertex.class).addKey(key).buildMixedIndex("search");
key = m.makePropertyKey("USER_FNAME").dataType(String.class).make();
m.buildIndex("searchbyfname",Vertex.class).addKey(key).buildMixedIndex("search");
key = m.makePropertyKey("USER_LNAME").dataType(String.class).make();
m.buildIndex("typemixed",Vertex.class).addKey(key).buildMixedIndex("search");
This works fine. But I want to know if this is the best approach to this kind of problem? Or is there a better way to do this? Also I am using gremlin java api to write the above query. I am using dedup() to remove the duplicate vertices.
The 3 indices won't help to answer your query efficiently. Better create a single index that covers all of the 3 fields (that doesn't mean, that your query has to have a condition for all fields) and issue a direct index query:
Sample graph:
g = TitanFactory.open("conf/titan-cassandra-es.properties")
m = g.getManagementSystem()
user = m.makeVertexLabel("USER").make()
email = m.makePropertyKey("USER_EMAIL").dataType(String.class).make()
fname = m.makePropertyKey("USER_FNAME").dataType(String.class).make()
lname = m.makePropertyKey("USER_LNAME").dataType(String.class).make()
m.buildIndex("users", Vertex.class).addKey(email).addKey(fname).addKey(lname).indexOnly(user).buildMixedIndex("search")
m.commit()
ElementHelper.setProperties(g.addVertexWithLabel("USER"), "USER_EMAIL", "foo#bar.com", "USER_FNAME", "foo", "USER_LNAME", "bar")
ElementHelper.setProperties(g.addVertexWithLabel("USER"), "USER_EMAIL", "foo#xyz.com", "USER_FNAME", "foo", "USER_LNAME", "bar")
ElementHelper.setProperties(g.addVertexWithLabel("USER"), "USER_EMAIL", "abc#bar.com", "USER_FNAME", "foo", "USER_LNAME", "xyz")
ElementHelper.setProperties(g.addVertexWithLabel("USER"), "USER_EMAIL", "foo#baz.com", "USER_FNAME", "xyz", "USER_LNAME", "bar")
ElementHelper.setProperties(g.addVertexWithLabel("USER"), "USER_EMAIL", "xyz#bar.com", "USER_FNAME", "xyz", "USER_LNAME", "xyz")
g.commit()
Direct index query:
gremlin> g.indexQuery("users", 'v."USER_EMAIL":/.*xyz.*/ v."USER_FNAME":/.*xyz.*/ v."USER_LNAME":/.*xyz.*/').vertices()*.getElement()._().map()
==>{USER_FNAME=xyz, USER_LNAME=xyz, USER_EMAIL=xyz#bar.com}
==>{USER_FNAME=xyz, USER_LNAME=bar, USER_EMAIL=foo#baz.com}
==>{USER_FNAME=foo, USER_LNAME=xyz, USER_EMAIL=abc#bar.com}
==>{USER_FNAME=foo, USER_LNAME=bar, USER_EMAIL=foo#xyz.com}
As you can see I also replaced ENTITY_TYPE with a vertex label. The label can help to keep your index as small as possible. If, for example, another type of vertices (e.g. PROFILE) also uses the property USER_EMAIL, it wouldn't make it into the index (if it was created using .indexOnly(user)).
I'm trying to create edges between existing vertices queried by their indexed IDs, similar to the first answer here, but using this index lookup query instead of the label query:
CREATE EDGE cite
FROM
(SELECT FROM index:<className>.<indexName> WHERE key = "<keyString>")
TO
(SELECT FROM index:<className>.<indexName> WHERE key = "<keyString>")
This gives me the following error: com.orientechnologies.orient.core.exception.OCommandExecutionException: Source vertex '#-1:-1' not exists
Possibly relevant:
When I just query SELECT FROM index:<className>.<indexName> WHERE key = "<keyString>" by itself it returns an array object structured like:
[ { '#type': 'd',
key: '<keyString>',
rid: { cluster: <actual cluster>, position: <actual position> }
#rid: { cluster: -1, position: -1 } } ]
I'm guessing that the error has something to do with the CREATE EDGE query using the #rid instead of the rid but I'm not sure.
The query successfully creates the edges if I simply use the #<actual cluster>:<actual position> instead of the SELECT subquery.
Any ideas what I might be doing wrong?
Edit: In the interest of replicability, I have the same problem in the GratefulDeadConcerts database when I (1) add a property name to the V class schema, (2) create a unique nameIndex index of V using the name property under V, and then (3) use the following query:
create edge followed_by from (select from index:nameIndex where key = 'HEY BO DIDDLEY') to (select from index:nameIndex where key = 'IM A MAN')
Why don't you query the class directly?
CREATE EDGE cite
FROM
(select from Class where field = '<keyString>')
TO
(select from Class where field = '<keyString>')
Select from index return a temp document as result set with key,and rid
you can try but i don't know if it will work
SELECT expand(rid) FROM index:<className>.<indexName> WHERE key = "<keyString>"