You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何为远程GraphTraversalSource创建Vertex Index

问题

如何使用traversal().withRemote("conf/remote-graph.properties")创建顶点索引(Vertex Indexes)?

具体疑问

  • 是否必须创建org.apache.tinkerpop.gremlin.structure.Graph实例?
    Graph graph = TinkerGraph.open(configuration);
    
  • 若是,JanusGraph所需的配置在哪里获取?
    对比OrientDB 3.2.18 GA Community Edition搭配Orientdb-Gremlin的OrientGraph.java示例代码:
    Configuration configuration = new BaseConfiguration();
    configuration.setProperty(OrientGraph.CONFIG_URL, orientGraph_configUrl);
    configuration.setProperty(OrientGraph.CONFIG_USER, orientGraph_configUser);
    configuration.setProperty(OrientGraph.CONFIG_PASS, orientGraph_configPass);
    configuration.setProperty(OrientGraph.CONFIG_TRANSACTIONAL, true);
    OrientGraph orientGraph = OrientGraph.open(configuration);
    GraphTraversalSource g = orientGraph.traversal();
    
  • 若必须创建,如何编写可正常连接的最简JanusGraphManagement实例代码?

调研发现

  • g.V().index();方法位于org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversal中
    有相关示例,但目前仍未完全理解该方法的用法:
    g.V().hasLabel("software").index() //1
    g.V().hasLabel("software").values("name").fold().
        order(Scope.local).
        index().
        unfold().
        order().
            by(__.tail(Scope.local, 1)) //2
    g.V().hasLabel("software").values("name").fold().
        order(Scope.local).
        index().
          with(WithOptions.indexer, WithOptions.list).
        unfold().
        order().
          by(__.tail(Scope.local, 1)) //3
    g.V().hasLabel("person").values("name").fold().
        order(Scope.local).
        index().
            with(WithOptions.indexer, WithOptions.map)  //4
    
  • Tinkergraph有createIndex()方法,示例代码:
    graph = TinkerGraph.open()
    graph.createIndex("username",Vertex.class)
    
  • JanusGraph索引使用JanusGraphManagement.buildIndex(String, Class)方法,但希望编写更贴近Gremlin、更通用的代码

现有代码

已知如何在Gremlin中使用空白TinkerGraph实现,但需要连接localhost:8182上已有的JanusGraph:

graph = TinkerGraph.open()
g = traversal().withEmbedded(graph)
g.io('data/grateful-dead.xml').read().iterate()
clock(1000) {g.V().has('name','Garcia').iterate()} //// (1)
graph = TinkerGraph.open()
g = traversal().withEmbedded(graph)
graph.createIndex('name',Vertex.class)
g.io('data/grateful-dead.xml').read().iterate()
clock(1000){g.V().has('name','Garcia').iterate()} //2

内容的提问来源于stack exchange,提问作者Zach

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.22 19:04:59