Create new entries in an empty JanusGraph with Gremlinpython

154 views
Skip to first unread message

Benjamin Ricaud

unread,
Sep 20, 2017, 8:09:18 AM9/20/17
to Gremlin-users

Hi,

I want to handle myself the cardinality of the node properties in my graph so I have put in my graph.properties
```
schema.default=none
```

I am using JausGraph 0.1.1 with Gremlin server 3.2.3.
I start with an empty graph.
When I want to create my first node in python:
```
graph = Graph()
g = self.graph.traversal().withRemote(
DriverRemoteConnection('ws://'+server_address+'/gremlin','g', message_serializer=GraphSONSerializersV2d0())
)
vertex = g.addV('word').property('node_id','id_1').next()
```
I get:
```
gremlin_python.driver.protocol.GremlinServerError: 500: Vertex Label with given name does not exist: word
```
It seems that Janusgraph is first expecting that we define what will be the nodes label and properties before starting creating entries. 
I have seen you can do that in java here: http://docs.janusgraph.org/latest/schema.html
But I can't figure out how to do it with gremlinpython. Any solution?

Benjamin

David Brown

unread,
Sep 20, 2017, 12:34:49 PM9/20/17
to Gremlin-users
Hi Benjamin,

How about submitting your schema definition as a string with the gremlinpython client? Here is an untested example:

from gremlin_python.driver.client import Client
client = Client('ws://localhost:45940/gremlin', 'g')
schema_def = """mgmt = graph.openManagement()
                word = mgmt.makeVertexLabel('word').make()
                node_id = mgmt.makePropertyKey('node_id').dataType(String.class).cardinality(Cardinality.SINGLE).make()"""
result_set = client.submit(schema_def)
result_set.all()

David Brown

unread,
Sep 20, 2017, 12:36:35 PM9/20/17
to Gremlin-users
Sorry, add you will need to commit the schema. Add this to the schema string:

"mgmt.commit()"

Benjamin Ricaud

unread,
Sep 21, 2017, 5:35:46 AM9/21/17
to Gremlin-users
Thanks very much David! It works. This is exactly what I needed.
Reply all
Reply to author
Forward
0 new messages