如何在SDN4中使用嵌入式数据库建立索引?
How to make indexes in SDN4 with embedded database?
Spring Data Neo4j 4 不再支持@Index 注解。对于独立的 Neo4j 数据库,我必须使用其 REST 或 Web 界面自行部署索引。但是,对于嵌入式模式的数据库,没有这样的接口。我是否必须在独立模式下部署数据库,设置适当的索引,然后在嵌入式模式下使用数据库文件夹,或者在使用我的应用程序停止服务器后使用 neo4j-shell 访问 SDN4 部署的数据库?
您可以按照您的建议进行操作,或者您也可以在您的应用程序中获取 GraphDatabaseService 的句柄并使用 Java API 创建索引。这是一个例子:
EmbeddedDriver embeddedDriver = (EmbeddedDriver) Components.driver();
GraphDatabaseService databaseService = embeddedDriver.getGraphDatabaseService();
try (Transaction tx = databaseService.beginTx()) {
databaseService.index().forNodes(indexName);
...
tx.success();
}
根据评论更新:
如果使用 HttpDriver,则可以向 rest 端点发送请求
String uri = Components.driver().getConfiguration().getURI() +
"/db/data/...";
HttpPost httpPost = new HttpPost(uri);
//Construct the JSON statements
try {
httpPost.setEntity(new StringEntity(json.toString()));
HttpRequest.execute(httpClient, httpPost,
Components.driver().getConfiguration().getCredentials());
} catch (Exception e) {
//Handle any exceptions
}
Spring Data Neo4j 4 不再支持@Index 注解。对于独立的 Neo4j 数据库,我必须使用其 REST 或 Web 界面自行部署索引。但是,对于嵌入式模式的数据库,没有这样的接口。我是否必须在独立模式下部署数据库,设置适当的索引,然后在嵌入式模式下使用数据库文件夹,或者在使用我的应用程序停止服务器后使用 neo4j-shell 访问 SDN4 部署的数据库?
您可以按照您的建议进行操作,或者您也可以在您的应用程序中获取 GraphDatabaseService 的句柄并使用 Java API 创建索引。这是一个例子:
EmbeddedDriver embeddedDriver = (EmbeddedDriver) Components.driver();
GraphDatabaseService databaseService = embeddedDriver.getGraphDatabaseService();
try (Transaction tx = databaseService.beginTx()) {
databaseService.index().forNodes(indexName);
...
tx.success();
}
根据评论更新:
如果使用 HttpDriver,则可以向 rest 端点发送请求
String uri = Components.driver().getConfiguration().getURI() +
"/db/data/...";
HttpPost httpPost = new HttpPost(uri);
//Construct the JSON statements
try {
httpPost.setEntity(new StringEntity(json.toString()));
HttpRequest.execute(httpClient, httpPost,
Components.driver().getConfiguration().getCredentials());
} catch (Exception e) {
//Handle any exceptions
}