如何删除JanusGraph索引?

时间:2017-07-24 06:11:30

标签: titan janusgraph

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

  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();

image

2 个答案:

答案 0 :(得分:2)

如果您无法将索引的状态从“安装”更改为“启用”,我建议您检查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()

我遇到了同样的问题并尝试了很多其他的事情,最后上述程序工作了!

答案 1 :(得分:1)

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

// 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()