【问题标题】:How to remove JanusGraph index?如何删除 JanusGraph 索引?
【发布时间】:2017-12-29 15:12:04
【问题描述】:

但是索引状态已安装,如何将状态更改为已注册然后禁用它以将其删除,请帮助我,

  GraphTraversalSource g = janusGraph.traversal();
    JanusGraphManagement janusGraphManagement = janusGraph.openManagement();
    JanusGraphIndex phoneIndex = 
    janusGraphManagement.getGraphIndex("phoneIndex");
    PropertyKey phone = janusGraphManagement.getPropertyKey("phone");
    SchemaStatus indexStatus = phoneIndex.getIndexStatus(phone);
    String name = phoneIndex.name();
    System.out.println(name);
    if (indexStatus == INSTALLED) {
       janusGraphManagement.commit();
       janusGraph.tx().commit();

【问题讨论】:

    标签: titan janusgraph


    【解决方案1】:

    如果您无法将索引状态从 Install 更改为 Enable,建议您检查 JanusGraph 正在运行的实例并关闭除带有“(当前)”的实例之外的所有实例,然后再次尝试删除索引。

    要检查和关闭实例,请在 gremlin shell 中使用以下命令:

    mgmt = graph.openManagement()
    
    mgmt.getOpenInstances() //all open instances
    
    ==>7f0001016161-dunwich1(current)
    ==>7f0001016161-atlantis1
    
    mgmt.forceCloseInstance('7f0001016161-atlantis1') //remove an instance
    mgmt.commit()
    

    要删除索引,请使用以下代码:

    // Disable the "name" composite index
    this.management = this.graph.openManagement()
    def nameIndex = this.management.getGraphIndex(indexName)
    this.management.updateIndex(nameIndex, SchemaAction.DISABLE_INDEX).get()
    this.management.commit()
    this.graph.tx().commit()
    
    // Block until the SchemaStatus transitions from INSTALLED to REGISTERED
    ManagementSystem.awaitGraphIndexStatus(graph, indexName).status(SchemaStatus.DISABLED).call()
    
    // Delete the index using JanusGraphManagement
    this.management = this.graph.openManagement()
    def delIndex = this.management.getGraphIndex(indexName)
    def future = this.management.updateIndex(delIndex, SchemaAction.REMOVE_INDEX)
    this.management.commit()
    this.graph.tx().commit()
    

    我遇到了同样的问题并尝试了很多其他的东西,最后上面的程序成功了!

    【讨论】:

    • 该方法会删除索引而不是禁用它吗?我想删除我的索引以创建另一个具有相同名称的索引,但收到错误消息:“名称为 'myIndexName' 的索引已被定义”
    【解决方案2】:

    必须先禁用索引,然后才能将其删除。

    // Disable the "phoneIndex" composite index
    janusGraphManagement = janusGraph.openManagement()
    phoneIndex = janusGraphManagement.getGraphIndex('phoneIndex')
    janusGraphManagement.updateIndex(phoneIndex, SchemaAction.DISABLE_INDEX).get()
    janusGraphManagement.commit()
    janusGraph.tx().commit()
    
    // Block until the SchemaStatus transitions from INSTALLED to REGISTERED
    ManagementSystem.awaitGraphIndexStatus(janusGraph, 'phoneIndex').status(SchemaStatus.DISABLED).call()
    
    // Delete the index using TitanManagement
    janusGraphManagement = janusGraph.openManagement()
    phoneIndex = janusGraphManagement.getGraphIndex('phoneIndex')
    future = janusGraphManagement.updateIndex(phoneIndex, SchemaAction.REMOVE_INDEX)
    janusGraphManagement.commit()
    janusGraph.tx().commit()
    

    【讨论】:

    • 我在janusGraph上建索引时,索引状态是install,无法开启,所以索引状态是install,无法删除
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2018-07-14
    • 1970-01-01
    • 2021-08-14
    • 1970-01-01
    • 1970-01-01
    • 2014-02-23
    • 1970-01-01
    相关资源
    最近更新 更多