Search code examples
pythongremlingremlin-server

Gremlin adding multi label in created vertex


I am trying to add multi labels in the vertex. I found doc this, this is adding multi-label at the time of creating the node. I tried some query for adding multi-label in created vertex.

g.V().has('Test', "title", "test1").next().addLabel('BU1')

But this is given an error

File "/usr/lib/python3.6/concurrent/futures/_base.py", line 432, in result
    return self.__get_result()
  File "/usr/lib/python3.6/concurrent/futures/_base.py", line 384, in __get_result
    raise self._exception
  File "/usr/local/lib/python3.6/dist-packages/gremlin_python/driver/resultset.py", line 81, in cb
    f.result()
  File "/usr/lib/python3.6/concurrent/futures/_base.py", line 425, in result
    return self.__get_result()
  File "/usr/lib/python3.6/concurrent/futures/_base.py", line 384, in __get_result
    raise self._exception
  File "/usr/lib/python3.6/concurrent/futures/thread.py", line 56, in run
    result = self.fn(*self.args, **self.kwargs)
  File "/usr/local/lib/python3.6/dist-packages/gremlin_python/driver/connection.py", line 77, in _receive
    self._protocol.data_received(data, self._results)
  File "/usr/local/lib/python3.6/dist-packages/gremlin_python/driver/protocol.py", line 106, in data_received
    "{0}: {1}".format(status_code, data["status"]["message"]))
gremlin_python.driver.protocol.GremlinServerError: 597: Cannot invoke method range() on null object

Solution

  • I'm afraid that those methods won't work in Python. The documentation should be more clear on that (I've made a note to do that). From Python, you can only interface with the graph through the Gremlin language (which is the only way you should interface with the graph no matter what language you are working with) and those methods listed in the link you provided, like addLabel(), are not part of the Gremlin language - they happen to be specific to the Java API of Neo4jGraph. The only way you can add multiple labels in python is by way of:

    g.addV('human::animal')
    

    or I suppose that you could send a script to the server to use those Java API methods in the documentation. I suppose Neo4j could (should?) expose extensions to the Gremlin language (perhaps using with() step, thinking out loud). If you'd like to create an issue in JIRA for further discussion, perhaps that could be considered.