Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/neo4j/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Neo4j 如何使用嵌入式数据库在SDN4中创建索引?_Neo4j_Spring Data Neo4j 4 - Fatal编程技术网

Neo4j 如何使用嵌入式数据库在SDN4中创建索引?

Neo4j 如何使用嵌入式数据库在SDN4中创建索引?,neo4j,spring-data-neo4j-4,Neo4j,Spring Data Neo4j 4,Spring数据Neo4j 4不再支持@Index注释。对于独立的Neo4j数据库,我必须使用REST或web界面自行部署索引。然而,当数据库处于嵌入式模式时,就没有这样的接口。我是否必须在独立模式下部署数据库,设置适当的索引,然后在嵌入式模式下使用database folder,或者在使用我的应用程序停止服务器后,使用neo4j shell访问SDN4部署的数据库?您可以按照建议执行,或者,您也可以在应用程序中获取GraphDatabaseService的句柄,并使用JavaAPI创建索引。下

Spring数据Neo4j 4不再支持@Index注释。对于独立的Neo4j数据库,我必须使用REST或web界面自行部署索引。然而,当数据库处于嵌入式模式时,就没有这样的接口。我是否必须在独立模式下部署数据库,设置适当的索引,然后在嵌入式模式下使用database folder,或者在使用我的应用程序停止服务器后,使用neo4j shell访问SDN4部署的数据库?

您可以按照建议执行,或者,您也可以在应用程序中获取GraphDatabaseService的句柄,并使用JavaAPI创建索引。下面是一个例子:

 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
      }

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

 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
      }

我假设只有使用EmbeddedDriver才能进行这种直接操作?只有使用EmbeddedDriver才能访问GraphDatabaseService,是的。更新了我的答案,包含了HttpDriverI的示例代码。假设只有使用EmbeddedDriver才能进行这种直接操作?只有使用EmbeddedDriver才能访问GraphDatabaseService,是的。更新了我的答案以包含HttpDriver的示例代码