创建&;使用索引-Neo4j 2.0
我在Neo4j中使用/创建索引时遇到问题 我正在进行大规模插入,因此使用BatchInserter-import org.neo4j.unsafe.batchinsert.BatchInserter 但是-插入后,索引不出现 我创建如下索引:创建&;使用索引-Neo4j 2.0,neo4j,Neo4j,我在Neo4j中使用/创建索引时遇到问题 我正在进行大规模插入,因此使用BatchInserter-import org.neo4j.unsafe.batchinsert.BatchInserter 但是-插入后,索引不出现 我创建如下索引: BatchInserter inserter = BatchInserters.inserter( DB_CONNECTION_STRING ); Label personLabel = DynamicLabel.label( "Person" );
BatchInserter inserter = BatchInserters.inserter( DB_CONNECTION_STRING );
Label personLabel = DynamicLabel.label( "Person" );
Label transactionLabel = DynamicLabel.label( "Transaction" );
BatchInserter inserter = inserter.createDeferredSchemaIndex( personLabel ).on( "personid" ).create();
BatchInserter inserter = inserter.createDeferredSchemaIndex( transactionLabel ).on( "txid" ).create();
然后,插入节点
Map<String, Object> properties = new HashMap<>();
properties.put( "personid", myPersonID );
long nodeID = inserter.createNode( properties, personLabel );
最后,我尝试使用Cypher查询。然而,它报告说该索引不存在
START n=node:Person(personid='12345')
MATCH (n)-[:MYEDGE]-(x)
RETURN count(x);
结果:
STATEMENT_EXECUTION_ERROR: Index `Person` does not exist
有线索吗 您在批插入期间创建架构索引,而在Cypher查询中使用START子句,该子句使用旧索引,您必须单独创建和更新。 尝试将查询重写为:
MATCH (n:Person)-[:MYEDGE]-(x)
WHERE n.persionid='12345'
RETURN count(x)
然后,Cypher将自动选择正确的索引以加快查询速度
MATCH (n:Person)-[:MYEDGE]-(x)
WHERE n.persionid='12345'
RETURN count(x)