2014-01-26 124 views
1

是否可以使用自动索引功能在Neo4J上导入数据?我试图导入使用BatchInserter和BatchInserterIndex类似于下面的示例数据:Neo4J:批量执行自动索引

BatchInserter inserter = BatchInserters.inserter("/home/fmagalhaes/Neo4JDatabase"); 
BatchInserterIndexProvider indexProvider = new LuceneBatchInserterIndexProvider(inserter); 
BatchInserterIndex nodeIndex = indexProvider.nodeIndex("node_auto_index", MapUtil.stringMap("type","exact")); 
BatchInserterIndex relIndex = indexProvider.relationshipIndex("relationship_auto_index", MapUtil.stringMap("type","exact")); 
... 
inserter.createNode(vertexId, properties); 
nodeIndex.add(vertexId, properties); 
... 

的问题是,当完成批量处理,我想通过以下操作来打开这个数据库蓝图通用API:

Graph g = new Neo4jGraph("/home/fmagalhaes/Neo4JDatabase"); 
Set<String> nodeIndices = ((KeyIndexableGraph)g).getIndexedKeys(Vertex.class); 
Set<String> relIndices = ((KeyIndexableGraph)g).getIndexedKeys(Edge.class); 

并且nodeIndices和relIndices都是空的。当我在Blueprints API上打开图形数据库时,自动索引功能被禁用。是否可以在批处理过程中创建一个自动索引,以便在使用Blueprints API打开数据库时,该索引将可见(并且将继续索引数据,因为属性会添加到顶点和边)。

回答

1
  1. 你已经彻底关闭这两个批次指数以及批量插入
  2. 你可能不希望索引的所有属性,只是你用来查找节点
  3. 关键的人
  4. 您必须启用自动索引在Neo4j的配置为你算账启动数据库,并为你批量插入
+0

1.我中省略上面的例子,但我在索引相同的属性关闭IndexProvider和BatchInserter。 2.正确。事实上,我正在测试Blueprints和Neo4J,我使用的唯一属性是:“__id”。我想索引这个属性,因为我想使用来自Blueprints API的IdGraph包装。 3.如何在嵌入式Neo4j数据库上启用自动索引?打开数据库时,我应该使用node_auto_indexing = true和relationship_auto_indexing = true配置吗? –

+0

此外,当我仅使用Blueprints API(和Neo4jGraph类实现)导入我的数据而不是使用BatchInserts时,当我使用createKeyIndex()方法时,我能够在以后直接打开数据库而无需设置node_auto_indexing = true和relationship_auto_indexing = true。不知何故,这种配置嵌入数据库本身。使用BathInserts时,是否可以在数据库中嵌入此auto_index行为,而不必在打开数据库时在配置上手动设置它们? –