Using AWS Neptune with Gremlin query language (last version).
Using sample data inserted this way:
g.addV('test_report').property('name', 'REF').property('creationDateTime','2022-07-01 00:00:00.000000')
g.addV('test_reportrelease').property('name', 'A').property('creationDateTime','2022-07-01 01:00:00.000000')
g.addV('test_reportrelease').property('name', 'B').property('creationDateTime','2022-07-01 02:00:00.000000')
g.addV('test_reportrelease').property('name', 'C').property('creationDateTime','2022-07-01 03:00:00.000000')
g.addE('test_has').property('creationDateTime','2022-07-02 01:00:00.000000')
.from(V().hasLabel('test_report').has('name', 'REF'))
.to(V().hasLabel('test_reportrelease').has('name', 'A'))
g.addE('test_has').property('creationDateTime','2022-07-02 02:00:00.000000')
.from(V().hasLabel('test_report').has('name', 'REF'))
.to(V().hasLabel('test_reportrelease').has('name', 'B'))
g.addE('test_has').property('creationDateTime','2022-07-02 03:00:00.000000')
.from(V().hasLabel('test_report').has('name', 'REF'))
.to(V().hasLabel('test_reportrelease').has('name', 'C'))
What I want is:
First of all, get the vertices with label "test_report"
then follow all the next statements (union)
then follow, if exists, all outgoing edges (outE) with the label "test_has" between vertices with label "test_report" and "test_reportrelease"; then follow all ingoing vertices (inV), and apply a constant with name "ref" and value test_has" on every edge browsed
then follow, if exists, as well the edge "test_has" and ingoing vertices but keep only the first result according to an asc order on creationDateTime, and apply a constant with name "ref" and value "test_first" on every edge browsed
then follow, if exists, as well the edge "test_has" but and ingoing vertices keep only the first result according to a desc order on creationDateTime, and apply a constant with name "ref" and value "test_last" on every edge browsed
then use the tree() step to get all browsed vertices and edges as a tree
The main problem is to add the "ref" constant to every edge followed (or change the label at query time).
The sample query I wrote for most of my needs, missing the "ref" constant, is:
g.V().hasLabel('test_report')
.union(optional(
outE().hasLabel('test_has').order().by('creationDateTime').inV()),
optional(outE().hasLabel('test_has').order().by('creationDateTime').limit(1).inV()),
optional(outE().hasLabel('test_has').order().by(coalesce(values('creationDateTime'), constant('')), desc).limit(1).store('last').inV())
).valueMap(true).path()
Question: How to insert a key:value constant property on every edge or vertex traversed ?
So that the result looks like this (but formatted as a tree - path being more readable when testing):
1 path[v[70c0dcd5-a6b9-4532-28bf-85705e94697e], e[66c0dcd7-31ed-e381-5331-e8c73bb91be1][70c0dcd5-a6b9-4532-28bf-85705e94697e-test_has->c0c0dcd5-c102-4031-d739-b5bd8fe161bc], v[c0c0dcd5-c102-4031-d739-b5bd8fe161bc], {<T.id: 1>: 'c0c0dcd5-c102-4031-d739-b5bd8fe161bc', <T.label: 4>: 'test_reportrelease', 'name': ['A'], 'creationDateTime': ['2022-07-01 01:00:00.000000'], 'ref': ['test_has']}]
2 path[v[70c0dcd5-a6b9-4532-28bf-85705e94697e], e[b0c0dcd7-4d99-1f3c-077d-decd2e251c46][70c0dcd5-a6b9-4532-28bf-85705e94697e-test_has->68c0dcd5-c5c5-c869-d789-96acbb88131f], v[68c0dcd5-c5c5-c869-d789-96acbb88131f], {<T.id: 1>: '68c0dcd5-c5c5-c869-d789-96acbb88131f', <T.label: 4>: 'test_reportrelease', 'name': ['B'], 'creationDateTime': ['2022-07-01 02:00:00.000000'], 'ref': ['test_has']}]
3 path[v[70c0dcd5-a6b9-4532-28bf-85705e94697e], e[70c0dcd7-72ac-204f-1341-cc843d165a38][70c0dcd5-a6b9-4532-28bf-85705e94697e-test_has->5ac0dcd5-cb10-f392-7d80-69541c4f22eb], v[5ac0dcd5-cb10-f392-7d80-69541c4f22eb], {<T.id: 1>: '5ac0dcd5-cb10-f392-7d80-69541c4f22eb', <T.label: 4>: 'test_reportrelease', 'name': ['C'], 'creationDateTime': ['2022-07-01 03:00:00.000000'], 'ref': ['test_has']}]
4 path[v[70c0dcd5-a6b9-4532-28bf-85705e94697e], e[66c0dcd7-31ed-e381-5331-e8c73bb91be1][70c0dcd5-a6b9-4532-28bf-85705e94697e-test_has->c0c0dcd5-c102-4031-d739-b5bd8fe161bc], v[c0c0dcd5-c102-4031-d739-b5bd8fe161bc], {<T.id: 1>: 'c0c0dcd5-c102-4031-d739-b5bd8fe161bc', <T.label: 4>: 'test_reportrelease', 'name': ['A'], 'creationDateTime': ['2022-07-01 01:00:00.000000'], 'ref': ['test_first']}]
5 path[v[70c0dcd5-a6b9-4532-28bf-85705e94697e], e[70c0dcd7-72ac-204f-1341-cc843d165a38][70c0dcd5-a6b9-4532-28bf-85705e94697e-test_has->5ac0dcd5-cb10-f392-7d80-69541c4f22eb], v[5ac0dcd5-cb10-f392-7d80-69541c4f22eb], {<T.id: 1>: '5ac0dcd5-cb10-f392-7d80-69541c4f22eb', <T.label: 4>: 'test_reportrelease', 'name': ['C'], 'creationDateTime': ['2022-07-01 03:00:00.000000'], 'ref': ['test_last']}]
I have tried those approaches, but both interrupt the graph traversal when using valueMap:
g.V().hasLabel('test_report').outE().hasLabel('test_has')
.order().by('creationDateTime').limit(1).valueMap(true).unfold().inject(['ref':'test_first']).fold()
And
g.V().hasLabel('test_report').outE().hasLabel('test_has')
.order().by('creationDateTime').limit(1).union(valueMap(true).unfold(), project('ref').by(constant('test_first'))).fold()
Is there a way to achieve such thing ?
I don't want to have the results stored in the database, just need to have the values in the results.
PS: I'm querying my graph db from a Jupyter SageMaker Notebook.
Your case sounds somewhat similar to one that came up on the Gremlin Users list recently.
Using the air-routes data set, we can add additional key/value pairs to a result set using a query such as this one.
gremlin> g.V().has('code','DAL').
......1> union(valueMap('city','desc').by(unfold()),
......2> constant(['special':1234])).unfold().
......3> group().
......4> by(keys).
......5> by(values)
==>[special:[1234],city:[Dallas],desc:[Dallas Love Field]]
You should be able to use a similar construct in your query. All the query above does is to get some properties and their values from a vertex, and then supplement those using a constant step to add the special key with the 1234 value into the result. The unfold gives access to each "row" of the map. The group builds a new single map containing all three k/v pairs.
UPDATED
Here is a second example that shows how to let the query accumulate the results and do some additional traversing afterwards.
gremlin> g.V().has('code','DAL').
......1> sideEffect(
......2> union(valueMap('city','desc').by(unfold()),
......3> constant(['special':1234])).unfold().
......4> group('x').
......5> by(keys).
......6> by(values)).
......7> project('map','count').
......8> by(select('x')).
......9> by(out().count())
==>[map:[special:[1234],city:[Dallas],desc:[Dallas Love Field]],count:57]
FURTHER UPDATED
To use a sack instead of sideEffect
gremlin> g.V().has('code','DAL').
......1> sack(assign).
......2> by(union(valueMap('city','desc').by(unfold()),
......3> constant(['special':1234])).unfold().
......4> group().
......5> by(keys).
......6> by(values)).
......7> project('map','count').
......8> by(sack()).
......9> by(out().count())
==>[map:[special:[1234],city:[Dallas],desc:[Dallas Love Field]],count:57]
Hi I'm new to gremlin and need to, basically, get everything current to return as a json file. I'm using Syndeia which has a raw query option. I'm having difficulty figuring out how to get both vertices and edges to output. This is what I have thus far:
g.V().has('sLabel','Artifact').has('_isLatest','TRUE').both()
But I also need
g.V().has('sLabel','Artifact').has('_isLatest','TRUE').bothE()
Which gives me all the edges I need, but not the vertices. I realize that g.V() gives vertices and g.E() gives edges, but am unsure how to obtain both/combine them in the one line query. My json comes back as either
"vertices":[] 0 items
"edges":[...] 90 items
Or
"vertices":[...] 90 items
"edges":[] 0 items
My next idea is to do multiple queries into java to parse, combine, and manipulate there. I would really like to avoid doing this, but will if it's the only way. Thank you for being kind and understanding and for your help. I appreciate you all.
You can write a Gremlin query that gives you both the vertices and the edges. There are a few ways to do that. Probably the easiest way is to use path as shown below.
g.V().has('sLabel','Artifact').
has('_isLatest','TRUE').
bothE().
otherV().
path()
as an alternative, you could do:
g.V().has('sLabel','Artifact').
has('_isLatest','TRUE').
bothE().as('e').
otherV().as('v').
select('v','e')
You can do it as follows,
Just see the code below have demonstrated the following,
Vertex query
Edge query
combined query
converted combined query into valueMap
Converted the combined query valueMap into JSON (using version 3)
Converted the combined query valueMap into JSON (using version 1)
Vertex Query
gremlin> g.V(131200).both()
==>v[40992]
==>v[12336]
==>v[20608]
==>v[180376]
gremlin>
Edge query
gremlin> g.V(131200).bothE()
==>e[7rps-2t8g-1fdh-vmo][131200-locatedin->40992]
==>e[3qpy-9io-1bf9-2t8g][12336-containedin->131200]
==>e[7rbk-fwg-1bf9-2t8g][20608-containedin->131200]
==>e[7l03-3v6g-1bf9-2t8g][180376-containedin->131200]
gremlin>
Combined query
gremlin>
gremlin>g.V(131200).project('nodes','edges').by(both().fold()).by(bothE().fold())
==>[nodes:[v[40992],v[12336],v[20608],v[180376]],edges:[e[7rps-2t8g-1fdh-vmo][131200-locatedin->40992],e[3qpy-9io-1bf9-2t8g][12336-containedin->131200],e[7rbk-fwg-1bf9-2t8g][20608-containedin->131200],e[7l03-3v6g-1bf9-2t8g][180376-containedin->131200]]]
gremlin>
converted combined query into valueMap
gremlin>
gremlin> output = g.V(131200).project('nodes','edges').by(both().valueMap().fold()).by(bothE().valueMap().fold()).next()
==>nodes=[{gId=[0b98e8d5-681d-4155-8aaf-5d86babc0cff], isDeleted=[FALSE], isEntity=[TRUE], name=[TotsukaCDC], basetype=[GeoLocation], source=[RCP-Base], type=[DC], geographyL2DisplayName=[KANAGAWA], geographyL2Name=[KANAGAWA], geographyL4Name=[KNG-TOTSUKAKU-NORTH], geographyL4DisplayName=[KNG-TOTSUKAKU-NORTH], displayName=[TotsukaCDC], latitude=[139.525166], locationType=[CDC], geographyL1Name=[KANTO], geographyL3DisplayName=[YOKOHAMA-SHI], geographyL3Name=[YOKOHAMA-SHI], geographyL1DisplayName=[KANTO], locationCode=[tt], longitude=[35.416535]}, {gId=[90e7407c-cd34-44b0-9bf9-1a8866aac429], isDeleted=[FALSE], isEntity=[TRUE], name=[UHN2KNGcdcttRA01_HundredGigE0/0/0/6], basetype=[Entity], source=[RCP-Base], type=[PhysicalPort], portInUse=[TRUE], portNum=[HundredGigE0/0/0/6]}, {gId=[d0fc7284-4cd8-4cba-8d3d-be3c4ca2ba31], isDeleted=[FALSE], isEntity=[TRUE], name=[UHN2KNGcdcttRA01_Hu0/2/0/35], basetype=[Entity], source=[RCP-Base], type=[PhysicalPort], portInUse=[TRUE], portNum=[Hu0/2/0/35]}, {gId=[2f4f5a3a-b88f-4915-acd5-a1d873507f11], isDeleted=[FALSE], isEntity=[TRUE], name=[UHN2KNGcdcttRA01_HundredGigE0/1/0/6], basetype=[Entity], source=[RCP-Base], type=[PhysicalPort], portInUse=[TRUE], portNum=[HundredGigE0/1/0/6]}]
==>edges=[{destName=TotsukaCDC, srcName=UHN2KNGcdcttRA01, gId=1133ff0f-2f4b-4d21-b2d6-fed796ed13f9}, {gId=220d7d2b-8b96-4331-bdc1-50127685946a, destName=UHN2KNGcdcttRA01, srcName=UHN2KNGcdcttRA01_HundredGigE0/0/0/6}, {gId=ebd78fc0-a66c-4033-a776-f80210c02e63, destName=UHN2KNGcdcttRA01, srcName=UHN2KNGcdcttRA01_Hu0/2/0/35}, {srcName=UHN2KNGcdcttRA01_HundredGigE0/1/0/6, gId=0df0f3d0-037a-4caa-9f81-6a6df1c22e25, destName=UHN2KNGcdcttRA01}]
gremlin>
Converted the combined query valueMap into JSON (Using Version 3)
gremlin>
gremlin> mapper = GraphSONMapper.build().version(GraphSONVersion.V3_0).create().createMapper()
==>org.apache.tinkerpop.shaded.jackson.databind.ObjectMapper#10a907ec
gremlin>
gremlin> mapper.writeValueAsString(output) // output is a variable in which data is collected in step 4
==>{"#type":"g:Map","#value":["nodes",{"#type":"g:List","#value":[{"#type":"g:Map","#value":["gId",{"#type":"g:List","#value":["0b98e8d5-681d-4155-8aaf-5d86babc0cff"]},"isDeleted",{"#type":"g:List","#value":["FALSE"]},"isEntity",{"#type":"g:List","#value":["TRUE"]},"name",{"#type":"g:List","#value":["TotsukaCDC"]},"basetype",{"#type":"g:List","#value":["GeoLocation"]},"source",{"#type":"g:List","#value":["RCP-Base"]},"type",{"#type":"g:List","#value":["DC"]},"geographyL2DisplayName",{"#type":"g:List","#value":["KANAGAWA"]},"geographyL2Name",{"#type":"g:List","#value":["KANAGAWA"]},"geographyL4Name",{"#type":"g:List","#value":["KNG-TOTSUKAKU-NORTH"]},"geographyL4DisplayName",{"#type":"g:List","#value":["KNG-TOTSUKAKU-NORTH"]},"displayName",{"#type":"g:List","#value":["TotsukaCDC"]},"latitude",{"#type":"g:List","#value":[{"#type":"g:Double","#value":139.525166}]},"locationType",{"#type":"g:List","#value":["CDC"]},"geographyL1Name",{"#type":"g:List","#value":["KANTO"]},"geographyL3DisplayName",{"#type":"g:List","#value":["YOKOHAMA-SHI"]},"geographyL3Name",{"#type":"g:List","#value":["YOKOHAMA-SHI"]},"geographyL1DisplayName",{"#type":"g:List","#value":["KANTO"]},"locationCode",{"#type":"g:List","#value":["tt"]},"longitude",{"#type":"g:List","#value":[{"#type":"g:Double","#value":35.416535}]}]},{"#type":"g:Map","#value":["gId",{"#type":"g:List","#value":["90e7407c-cd34-44b0-9bf9-1a8866aac429"]},"isDeleted",{"#type":"g:List","#value":["FALSE"]},"isEntity",{"#type":"g:List","#value":["TRUE"]},"name",{"#type":"g:List","#value":["UHN2KNGcdcttRA01_HundredGigE0/0/0/6"]},"basetype",{"#type":"g:List","#value":["Entity"]},"source",{"#type":"g:List","#value":["RCP-Base"]},"type",{"#type":"g:List","#value":["PhysicalPort"]},"portInUse",{"#type":"g:List","#value":["TRUE"]},"portNum",{"#type":"g:List","#value":["HundredGigE0/0/0/6"]}]},{"#type":"g:Map","#value":["gId",{"#type":"g:List","#value":["d0fc7284-4cd8-4cba-8d3d-be3c4ca2ba31"]},"isDeleted",{"#type":"g:List","#value":["FALSE"]},"isEntity",{"#type":"g:List","#value":["TRUE"]},"name",{"#type":"g:List","#value":["UHN2KNGcdcttRA01_Hu0/2/0/35"]},"basetype",{"#type":"g:List","#value":["Entity"]},"source",{"#type":"g:List","#value":["RCP-Base"]},"type",{"#type":"g:List","#value":["PhysicalPort"]},"portInUse",{"#type":"g:List","#value":["TRUE"]},"portNum",{"#type":"g:List","#value":["Hu0/2/0/35"]}]},{"#type":"g:Map","#value":["gId",{"#type":"g:List","#value":["2f4f5a3a-b88f-4915-acd5-a1d873507f11"]},"isDeleted",{"#type":"g:List","#value":["FALSE"]},"isEntity",{"#type":"g:List","#value":["TRUE"]},"name",{"#type":"g:List","#value":["UHN2KNGcdcttRA01_HundredGigE0/1/0/6"]},"basetype",{"#type":"g:List","#value":["Entity"]},"source",{"#type":"g:List","#value":["RCP-Base"]},"type",{"#type":"g:List","#value":["PhysicalPort"]},"portInUse",{"#type":"g:List","#value":["TRUE"]},"portNum",{"#type":"g:List","#value":["HundredGigE0/1/0/6"]}]}]},"edges",{"#type":"g:List","#value":[{"#type":"g:Map","#value":["destName","TotsukaCDC","srcName","UHN2KNGcdcttRA01","gId","1133ff0f-2f4b-4d21-b2d6-fed796ed13f9"]},{"#type":"g:Map","#value":["gId","220d7d2b-8b96-4331-bdc1-50127685946a","destName","UHN2KNGcdcttRA01","srcName","UHN2KNGcdcttRA01_HundredGigE0/0/0/6"]},{"#type":"g:Map","#value":["gId","ebd78fc0-a66c-4033-a776-f80210c02e63","destName","UHN2KNGcdcttRA01","srcName","UHN2KNGcdcttRA01_Hu0/2/0/35"]},{"#type":"g:Map","#value":["srcName","UHN2KNGcdcttRA01_HundredGigE0/1/0/6","gId","0df0f3d0-037a-4caa-9f81-6a6df1c22e25","destName","UHN2KNGcdcttRA01"]}]}]}
gremlin>
Converted the combined query valueMap into JSON (Using Version 1)
gremlin>
gremlin> mapper1 = GraphSONMapper.build().version(GraphSONVersion.V1_0).create().createMapper()
==>org.apache.tinkerpop.shaded.jackson.databind.ObjectMapper#1a7163e3
gremlin>
gremlin> mapper1.writeValueAsString(output)
==>{"nodes":[{"gId":["0b98e8d5-681d-4155-8aaf-5d86babc0cff"],"isDeleted":["FALSE"],"isEntity":["TRUE"],"name":["TotsukaCDC"],"basetype":["GeoLocation"],"source":["RCP-Base"],"type":["DC"],"geographyL2DisplayName":["KANAGAWA"],"geographyL2Name":["KANAGAWA"],"geographyL4Name":["KNG-TOTSUKAKU-NORTH"],"geographyL4DisplayName":["KNG-TOTSUKAKU-NORTH"],"displayName":["TotsukaCDC"],"latitude":[139.525166],"locationType":["CDC"],"geographyL1Name":["KANTO"],"geographyL3DisplayName":["YOKOHAMA-SHI"],"geographyL3Name":["YOKOHAMA-SHI"],"geographyL1DisplayName":["KANTO"],"locationCode":["tt"],"longitude":[35.416535]},{"gId":["90e7407c-cd34-44b0-9bf9-1a8866aac429"],"isDeleted":["FALSE"],"isEntity":["TRUE"],"name":["UHN2KNGcdcttRA01_HundredGigE0/0/0/6"],"basetype":["Entity"],"source":["RCP-Base"],"type":["PhysicalPort"],"portInUse":["TRUE"],"portNum":["HundredGigE0/0/0/6"]},{"gId":["d0fc7284-4cd8-4cba-8d3d-be3c4ca2ba31"],"isDeleted":["FALSE"],"isEntity":["TRUE"],"name":["UHN2KNGcdcttRA01_Hu0/2/0/35"],"basetype":["Entity"],"source":["RCP-Base"],"type":["PhysicalPort"],"portInUse":["TRUE"],"portNum":["Hu0/2/0/35"]},{"gId":["2f4f5a3a-b88f-4915-acd5-a1d873507f11"],"isDeleted":["FALSE"],"isEntity":["TRUE"],"name":["UHN2KNGcdcttRA01_HundredGigE0/1/0/6"],"basetype":["Entity"],"source":["RCP-Base"],"type":["PhysicalPort"],"portInUse":["TRUE"],"portNum":["HundredGigE0/1/0/6"]}],"edges":[{"destName":"TotsukaCDC","srcName":"UHN2KNGcdcttRA01","gId":"1133ff0f-2f4b-4d21-b2d6-fed796ed13f9"},{"gId":"220d7d2b-8b96-4331-bdc1-50127685946a","destName":"UHN2KNGcdcttRA01","srcName":"UHN2KNGcdcttRA01_HundredGigE0/0/0/6"},{"gId":"ebd78fc0-a66c-4033-a776-f80210c02e63","destName":"UHN2KNGcdcttRA01","srcName":"UHN2KNGcdcttRA01_Hu0/2/0/35"},{"srcName":"UHN2KNGcdcttRA01_HundredGigE0/1/0/6","gId":"0df0f3d0-037a-4caa-9f81-6a6df1c22e25","destName":"UHN2KNGcdcttRA01"}]}
I want a path from vertex A,C,D,E,G,H,
I tired with following code
g.V().hasLabel('a').repeat(out().simplePath()).until(hasLabel('h')).
path().by(values('vehicle','time').fold())
my received output
[[10.00,8.30,v1,v2],[10.30,9.00,9.30,v1,v2,v3],[11.00,9.30,10.00,v1,v2,v3],[1
1.30,10.00,10.30,v1,v2,v3],[12.00,11.00,v1,v3],[12.30,11.30,v1,v3]]
expected output
[a:[10.00,v1],c:[11.00,v1],d:[11.30,v1],e:[12.00,v1],g:[12.30,v1],h:[1.00,v1]],[a:[8.30,v2],c:[9.00,v2],d:[9.30,v2],e:[10.00,v2],g:[11.00,v3],h:[11.30,v3]]
the following is a sample graph
v1 = graph.addVertex(id,1,label,'a','vehicle','v1','time',10.00)
v2 = graph.addVertex(id,2,label,'b','vehicle','v1','time',10.30)
v3 = graph.addVertex(id,3,label,'c','vehicle','v1','time',11.00)
v4 = graph.addVertex(id,4,label,'d','vehicle','v1','time',11.30)
v5 = graph.addVertex(id,5,label,'e','vehicle','v1','time',12.00)
v7 = graph.addVertex(id,7,label,'g','vehicle','v1','time',12.30)
v8 = graph.addVertex(id,8,label,'h','vehicle','v1','time',1.00)
v1.addEdge('traveles',v3)
v3.addEdge('traveles',v4)
v4.addEdge('traveles',v5)
v5.addEdge('traveles',v7)
v7.addEdge('traveles',v8)
g.V(1).property(list,'vehicle','v2').property(list,'time',8.30)
g.V(3).property(list,'vehicle','v2').property(list,'time',9.00).property(list,'vehicle','v3').property(list,'time',9.30)
g.V(4).property(list,'vehicle','v2').property(list,'time',9.30).property(list,'vehicle','v3').property(list,'time',10.00)
g.V(5).property(list,'vehicle','v2').property(list,'time',10.00).property(list,'vehicle','v3').property(list,'time',10.30)
g.V(7).property(list,'vehicle','v3').property(list,'time',11.00)
g.V(8).property(list,'vehicle','v3').property(list,'time',11.30)
can anyone help me please
If your property has multiple values then the values step will return them all. Assuming you have two values you can select one or the other using limit or tail.
gremlin> g.addV('test').property(list,'x',1).property(list,'x',2)
==>v[61316]
gremlin> g.V(61316).values('x')
==>1
==>2
gremlin> g.V(61316).values('x').tail(1)
==>2
gremlin> g.V(61316).values('x').limit(1)
==>1
If you have more than 2 values and you need to select one from the middle of a list or set you can use the range step to select that value.
gremlin> g.V(61316).property(list,'x',5)
==>v[61316]
gremlin> g.V(61316).values('x')
==>1
==>2
==>5
gremlin> g.V(61316).values('x').range(1,2)
==>2
All of this said if you could edit your question with some sample data it would help give a better answer as it seems your data model has lots of values for each property so Gremlin is doing what you are asking it to.
Also, in your example you are finding vertices by their label and not testing the values at all. You can test a multi-property just as you would a single property
gremlin> g.V().has('x',2)
==>v[61316
EDITED to add:
Using these techniques, you could change your path statement to something like this:
path().
by(union(label,
values('time').limit(1),
values('vehicle').limit(1)).fold())
I want the details of a vertex along with details of vertices that are joined to it.
I have a group vertex, incoming 'member' edges to user vertices. I want the details of the vertices.
g.V(1).as('a').in('member').valueMap().as('b').select('a','b').unfold().dedup()
==>a=v[1]
==>b={image=[images/profile/friend9.jpg], name=[Thomas Thompson], email=[me#thomasthompson.co.uk]}
==>b={image=[images/profile/friend13.jpg], name=[Laura Tostevin], email=[me#lauratostevin.co.uk]}
==>b={image=[images/profile/friend5.jpg], name=[Alan Thompson], email=[me#alanthompson.co.uk]}
==>b={image=[images/profile/friend10.jpg], name=[Laura Bourne], email=[me#laurabourne.co.uk]}
Ideally what I'd want is:
{label: 'group', id=1, name='A Group', users=[{id=2, label="user",name=".."}, ... }]}
When I tried a project, it didn't like me using 'in'
gremlin> g.V('1').project('name','users').by('name').by(in('member').select())
groovysh_parse: 1: unexpected token: in # line 1, column 83.
'name','users').by('name').by(in('member
To get your preferred output format, you have to join the group's valueMap() with the list of users. On TinkerPop's modern toy graph you would do something like this:
gremlin> g.V(3).union(valueMap(true).
by(unfold()),
project('users').
by(__.in('created').
valueMap(true).
by(unfold()).
fold())).
unfold().
group().
by(keys).
by(select(values))
==>[name:lop,id:3,lang:java,label:software,users:[[id:1,label:person,name:marko,...],...]]
Mapping this to your graph should be pretty straight-forward, it's basically just about changing labels.
Because in is a reserved keyword in Groovy you must use the verbose syntax __.in
try:
g.V('1').project('name','users').by('name').by(__.in('member').valueMap(true).fold())