gpt4 book ai didi

indexing - Neo4j:在密码语句中使用索引

转载 作者:行者123 更新时间:2023-12-04 05:04:20 24 4
gpt4 key购买 nike

我正在努力研究如何在 cypher 中使用索引。

在java中创建和 inode 之后
我可以在这些节点上执行密码查询。
我也可以使用 java 中创建的索引查询这些节点。

但是,当我在 cypher 语句中调用索引时,我得到一个 MissingIndexException。

那么,为什么cypher找不到索引呢?我是否必须创建一个单独的密码索引? (我没有发现任何关于那个)

我使用的是 1.8.2 版
这是我所做的:

public class IndexTester {

String DB_PATH = "target/java-query-db";
String resultString ="";

GraphDatabaseService db = new GraphDatabaseFactory().newEmbeddedDatabase( DB_PATH );
ExecutionEngine engine = new ExecutionEngine( db );

IndexManager index = db.index();
Index<Node> personIndex;

Node n;
Node n1;

public static void main( String[] args )
{
IndexTester indexTester = new IndexTester();
indexTester.runIndex();
}


public void runIndex(){

Transaction tx = db.beginTx();
try
{

personIndex = index.forNodes( "person" );

n = createAndIndexNode("type", "adult", personIndex, db);
addPropertyAndIndexNode("name", "John", personIndex, n);
addPropertyAndIndexNode("id", "1", personIndex, n);


n1 = createAndIndexNode("type", "adult", personIndex, db);
addPropertyAndIndexNode("name", "Jane", personIndex, n1);
addPropertyAndIndexNode("id", "2", personIndex, n1);

//这很好用!!
            Node foundNode = personIndex.get("name", "John").getSingle();
System.out.println("Found Node: " + foundNode.getProperty("name"));

//这会抛出一个 MissingIndexException
            resultString = engine.execute( "start m=node:personIndex(name= 'John')  return m" ).toString();
System.out.println(resultString);

n.delete();
n1.delete();

tx.success();
}
finally
{
tx.finish();
}


}

private Node createAndIndexNode(final String property, final String name, Index<Node> nodeIndex, GraphDatabaseService db ) {
Node node = db.createNode();
node.setProperty(property , name);
nodeIndex.add(node, property, name);
return node;
}

public Node addPropertyAndIndexNode(String property, String name, Index<Node> nodeIndex, Node node)
{
node.setProperty( property, name );
nodeIndex.add( node, property, node.getProperty( property ) );
return node;
}

}

任何想法/建议如何解决这个问题?
谢谢!!

最佳答案

我认为您的索引的实际名称只是 person (如此处指定: index.forNodes( "person" ); ),而不是 personIndex .

尝试:

start m=node:person(name= 'John')  return m

关于indexing - Neo4j:在密码语句中使用索引,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15718247/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com