如何使用嵌入式数据库在SDN4中制作索引?

时间:2016-03-09 08:44:43

标签: neo4j spring-data-neo4j-4

Spring Data Neo4j 4不再支持@Index注释。使用独立的Neo4j数据库,我必须使用其REST或Web界面自行部署索引。但是,在嵌入式模式下,数据库没有这样的接口。我是否必须以独立模式部署数据库,设置适当的索引,然后在嵌入模式下使用数据库文件夹,或者在使用我的应用程序停止服务器后使用neo4j-shell访问SDN4部署的数据库?

1 个答案:

答案 0 :(得分:4)

您可以按照建议执行操作,也可以在应用程序中获取GraphDatabaseService的句柄,并使用Java API创建索引。这是一个例子:

 EmbeddedDriver embeddedDriver = (EmbeddedDriver) Components.driver();
 GraphDatabaseService databaseService =  embeddedDriver.getGraphDatabaseService();
 try (Transaction tx = databaseService.beginTx()) {
    databaseService.index().forNodes(indexName);
    ...
    tx.success();
  }

根据评论进行更新:

如果使用HttpDriver,则可以向其余端点发送请求

 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
      }