1.gremlin控制台访问:
(1)E:\janusgraph\janusgraph-0.3.1-hadoop2\elasticsearch\bin中打开elasticsearch.bat
(2)E:\janusgraph\janusgraph-0.3.1-hadoop2\bin打开gremlin.bat
启动成功,在gremlin.bat中使用gremlin语言对janusgraph进行控制操作。
2.通过python连接:
(1)修改gremlin-server.yaml配置文件:
修改位置如图。
(2)修改janusgraph-berkeleyje-es-server.properties:
把janusgraph-berkeleyje-es-server.properties里面的index.search.hostname改为127.0.0.1。
(3)安装gremlinpython
在anacoda prompt中输入
pip install gremlinpyton
gremlinpython版本需要适应janusgraph和python的版本,否则会出错,例如我用的janusgraph-0.3.1只能适配3.3.3:
pip install gremlinpython==3.3.3
安装版本错误只需要卸载重装即可:
pip uninstall gremlinpython
(4)连接Python时,需要依次启动es.bat、gremlin.bat、gremlin-server.bat从而远程访问,之后打开pycharm新建脚本:
from gremlin_python import statics
from gremlin_python.structure.graph import Graph
from gremlin_python.process.graph_traversal import __
from gremlin_python.driver.driver_remote_connection import DriverRemoteConnection
graph = Graph()
connection = DriverRemoteConnection('ws://localhost:8182/gremlin', 'g')
# The connection should be closed on shut down to close open connections with connection.close()
g = graph.traversal().withRemote(connection)
# Reuse 'g' across the application
herculesAge = g.V().has('name', 'hercules').values('age').next()
print('Hercules is {} years old.'.format(herculesAge))
connection.close()
ws://localhost:8182/gremlin这个地址是在本机上使用。
至此,可以用python访问操作janusgraph了。