2017-07-24 105 views
2

但是索引狀態被安裝,如何將狀態更改爲臨時用戶,然後禁用它來刪除它,請幫助我,如何刪除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

回答

0

你必須拳頭禁用索引,那麼你可以刪除它。

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

當我在janusGraph上建立索引時,索引狀態是安裝,它不能啓用,所以索引狀態被安裝它不能刪除 – lazyfighter

1

如果無法改變索引的狀態,從安裝啓用,我建議你檢查JanusGraph的運行情況,並關閉所有的情況下,除了一個帶「(當前)」,然後嘗試再次刪除索引。

要檢查並關閉實例在小鬼外殼使用下面的命令:

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

我面臨着同樣的問題,並嘗試了很多其他的事情:

mgmt = graph.openManagement() 

mgmt.getOpenInstances() //all open instances 

==>7f0001016161-dunwich1(current) 
==>7f0001016161-atlantis1 

mgmt.forceCloseInstance('7f0001016161-atlantis1') //remove an instance 
mgmt.commit() 

刪除索引使用下面的代碼然後最終上述過程奏效!