I am creating a vertex with multiple edges but need a bit of help writing a query to retrieve the data.
Creation query
g.addV("referral")
.as("r")
.property("createdAt", Date.now())
.addE("prospect")
.from_("r")
.to(__.V(user.id))
.addE("opportunity")
.from_("r")
.to(__.V(second_user.id))
.addE("referredBy")
.from_("r")
.to(__.V(business.id))
.select("r")
.next()
I want to run a query that gets data from the first and second user. So far I have
g.V(business.id) //business
.in_("opportunity")
.as("referral")
.outV("referredBy")
.as("referrer")
.inV("prospect")
.as("prospect")
.select("referral", "referrer", "prospect")
.toList()
.next()
I'm getting an error when running this query. I basically want an array of a referral, referrer and prospect in one object that I can iterate through. Also any help on making my initial query better would be helpful.
Please let me know if this makes sense or if you need any other info. Any help would be appreciated.
The errors are because you are using outV when you should be using out. You only need to use inV and outV after outE and inE. So your query should be
g.V(business.id) //business
.in("opportunity")
.as("referral")
.out("referredBy")
.as("referrer")
.in("prospect")
.as("prospect")
.select("referral", "referrer", "prospect")
.toList()
Also you don't need next as you already have toList.
Lastly rather than use as and select I would look at the path step instead.
g.V(business.id) //business
.in("opportunity")
.out("referredBy")
.in("prospect")
.path()
.toList()
Related
Is possible in gremlin to count something inside choose() and then go back to a previous step in the traversal?:
g.V()
.hasLabel("user1")
.as("firstStep")
.V()
.as("secondStep")
.fold()
.choose(
count(local).is(gt(1)),
select('firstStep'),
select('secondStep')
)
The select('firstStep') line is executed but nothing is returned because at that point everything stored by .as("firstStep") was removed by fold()
Of course I can always solve this kind of problem at the expense of performance, duplicating the cost by searching 2 times:
g.V()
.hasLabel("user1")
.choose(
V().fold().count(local).is(lt(2)),
V().fold()
)
I'm looking for a better solution than this.
This is like if I go to a store and pay something, because I have to count the change I forget how to go back to my hose, the gremlins of the movie are more intelligent than that. I hope there is a solution that I ignore.
EDIT:
There is an answer recommending to replace as() by store() but that is not a general solution, doesn't work in most situations becase these are very different tools, for example this query has the same problem and replacing as() by store() gives a different result:
g.V()
.hasLabel('user')
.project("user")
.by(
as("singleUser")
.V()
.fold()
.choose(
count(local).is(gt(1)),
select('singleUser'),
unfold()
)
)
In this pattern you can use store step, that way the "firstStep" will be saved after the fold.
g.V().hasLabel('user1').store('firstStep').
V().
fold().choose(
count(local).is(gt(1)),
select('firstStep').unfold(),
select('secondStep')
)
example: https://gremlify.com/mg7noyf1cdq
I was wondering if there is a way for me use a result from search function in MarkLogic and use it in multiple transformation queries that I have.
For eg.
let $uris := cts:uris(("/example/"),(),cts:element-query(xs:QName("cd:documentTitle"),cts:element-value-query(xs:QName("cd:id"),"abc")))
return (fn:count($uris), $uris)[1 to 20]
The above query say returns me URI for 20 documents. How can I save this result or re-use this result for multiple transformations that I have. All of them working on the same result set but performing different tasks.
Any help would be greatly appreciated.
I'm going to guess you're using CORB to process data based on that return.
You could instead run your query in QConsole or similar and write the following in your URIs module:
let $uris = ("/1.xml", "/2.xml", ...)
return (fn:count($uris), $uris)
Using the gremlin console connected remotely to a Neptune DB instance, I am grabbing all edges with a specific label and want to sort them by the id of the out vertex. I'm getting this error: "code":"UnsupportedOperationException","detailedMessage":"com.amazon.neptune.storage.volcano.ast.CutoffNode cannot be cast to com.amazon.neptune.storage.volcano.ast.AbstractGroupNode".
Sample data:
g.addV('user').property(id,'1').
addV('content').property(id,'2').
addE('history').property('val',9).from(g.V('1')).to(g.V('2'))
Queries and outputs:
g.E().hasLabel('history').order().by('val')
==>e[3][1-history>2]
g.E().hasLabel('history').outV().id()
==>1
g.E().hasLabel('history').order().by(outV().id())
{"requestId":<stuff>,"code":"UnsupportedOperationException","detailedMessage":
"com.amazon.neptune.storage.volcano.ast.CutoffNode cannot be cast to
com.amazon.neptune.storage.volcano.ast.AbstractGroupNode"}
I expect the result of that last one to be the same as the first. I've tried the same traversal in a TinkerGraph and didn't get an error, so judging by that and the message it's specifically a Neptune problem. Googling hasn't brought up anything.
Is there a traversal that will do what I'm looking for? What am I doing wrong?
I will look into why the error is being thrown but in the near term I think this workaround should work. Please let me know if it does not.
g.E().order().by(identity().outV().id())
Cheers,
Kelvin
In the openstreetmap overpass API-documentation there is the following example:
area[name="Bonn"];
node(area)[highway=bus_stop];
node(around:100)[amenity=cinema];
out;
Why does this query does not give the Kinopolis (in Bonn Bad Godesberg) as a result? See here: http://rpubs.com/hrbrmstr/overpass for the results from the API. The following two images illustrate that it really is <100m by foot.
Unfortunately i wasnt able to show it graphically on the openstreetmap... I dont know how to get the busstop as startingpoint of a route in the web interface...
Here is the Google-Maps version.
Since you've asked for cinema nodes only in your example query, the result will not include way 42473787. Here's how your query should look like to return ways with amenity=cinema instead:
area[name="Bonn"];
node(area)[highway=bus_stop];
way(around:100)[amenity=cinema];
(._;>;);
out meta;
To get both nodes and ways in one query, simply use a union:
area[name="Bonn"];
node(area)[highway=bus_stop]->.bus_stops;
(
way(around.bus_stops:100)[amenity=cinema];
node(around.bus_stops:100)[amenity=cinema];
);
(._;>;);
out meta;
Try it in overpass turbo!
I need to fetch from BaaS data store all records that doesn't match condition
I use query string like:
https://api.usergrid.com/<org>/<app>/<collection>?ql=location within 10 of 30.494697,50.463509 and Partnership eq 'Reject'
that works right (i don't url encode string after ql).
But any attempt to put "not" in this query cause "The query cannot be parsed".
Also i try to use <>, !=, NE, and some variation of "not"
How to configure query to fetch all records in the range but Partnership NOT Equal 'Reject' ?
Not operations are supported, but are not performant because it requires a full scan. When coupled with a geolocation call, it could be quite slow. We are working on improving this in the Usergrid core.
Having said that, in general, it is much better to inverse the call if possible. For example, instead of adding the property when the case is true, always write the property to every new entity (even when false), then edit the property when the case is true.
Instead of doing this:
POST
{
'name':'fred'
}
PUT
{
'name':'fred'
'had_cactus_cooler':true
}
Do this:
POST
{
'name':'fred'
'had_cactus_cooler':'no'
}
PUT
{
'name':'fred'
'had_cactus_cooler':'yes'
}
In general, try to put your data in the way you want to get it out. Since you know upfront that you want to query on whether this property exists, simply add it, but with a negative value. The update it when the condition becomes true.
You should be able to use this syntax:
https://api.usergrid.com/<org>/<app>/<collection>?ql=location within 10 of 30.494697,50.463509 and not Partnership eq 'Reject'
Notice that the not operator comes before the expression (as indicated in the docs).