简体   繁体   English

我如何在Java应用程序中创建的Neo4j Web admin中查看索引及其节点?

[英]how can i see the index and its nodes in Neo4j web admin i created in java application?

I am trying to access and persist data to my neo4j server, however despite the fact that both my code and server-properties.file shows the same database location, I can't see the results in webadmin interface. 我正在尝试访问和持久保存数据到neo4j服务器,但是尽管我的代码和server-properties.file都显示相同的数据库位置,但在webadmin界面中看不到结果。

Here is the code I wrote (as I created users earlier, the user creation code is not included): 这是我编写的代码(如我之前创建的用户,不包括用户创建代码):

package graph;

import java.util.Iterator;
import java.util.Random;

import org.neo4j.graphdb.Direction;
import org.neo4j.graphdb.GraphDatabaseService;
import org.neo4j.graphdb.Node;
import org.neo4j.graphdb.Relationship;
import org.neo4j.graphdb.RelationshipType;
import org.neo4j.graphdb.Transaction;
import org.neo4j.graphdb.factory.GraphDatabaseFactory;
import org.neo4j.graphdb.index.Index;

public class GraphTest {

    static GraphDatabaseService graphDb = new GraphDatabaseFactory().newEmbeddedDatabase( "data/graph.db" );
    static Index<Node> nodeIndex = graphDb.index().forNodes("nodes");

    private static enum RelTypes implements RelationshipType
    {
        CALLED
    }

    public static void addRelationships(){
        int caller;
        int temp=0;
        int callee;
        Random rand = new Random();

        for(int i = 0 ;i<1000;i++){
            caller=rand.nextInt(100);
            temp=rand.nextInt(100);
            while(temp==caller)
                temp=rand.nextInt(100);
            callee=temp;


            String callerName = idToUserName( caller );
            Node foundCaller= nodeIndex.get( "uname", callerName ).getSingle();
            System.out.println( "The username of user " + caller + " is "
            + foundCaller.getProperty( "uname" ) );

            String calleeName = idToUserName( callee);
            Node foundCallee= nodeIndex.get( "uname", calleeName ).getSingle();
            System.out.println( "The username of user " + callee + " is "
            + foundCallee.getProperty( "uname" ) );


            System.out.println(callerName+" called " + calleeName);

            foundCaller.createRelationshipTo(foundCallee, RelTypes.CALLED);
            Iterable<Relationship> rels = foundCaller.getRelationships(RelTypes.CALLED, Direction.OUTGOING);
            Iterator<Relationship> x = rels.iterator();
            while(x.hasNext()){
                Relationship r = x.next();
                System.out.println(r.toString());
            }

        }

    }

    private static String idToUserName( final int id )
    {
        return "user" + String.valueOf(id) ;
    }

    private static Node createAndIndexUser( final String username )
    {
        Node node = graphDb.createNode();
        node.setProperty( "uname", username );
        nodeIndex.add( node,"uname", username );
        return node;
    }
    /**
     * @param args
     */
    public static void main(String[] args) {
        // TODO Auto-generated method stub

        Node firstNode;
        Node secondNode;
        Relationship relationship;

        System.out.println(nodeIndex.getName()+"  " +
nodeIndex.getGraphDatabase().getNodeById(45).getProperty("uname") );
        registerShutdownHook( graphDb );

        Transaction tx = graphDb.beginTx();
        try
        {
        // Updating operations go here
            // Create some users and index their names with the IndexService

            int idToFind = 67;
            String userName = idToUserName( idToFind );
            Node foundUser = nodeIndex.get( "uname", userName ).getSingle();
            System.out.println( "The username of user " + idToFind + " is "
            + foundUser.getProperty( "uname" ) );


            addRelationships();





            tx.success();

        }
        finally
        {
            tx.finish();

        }

        graphDb.shutdown();

    }

    private static void registerShutdownHook(final GraphDatabaseService graphDb) {
        // TODO Auto-generated method stub
        // Registers a shutdown hook for the Neo4j instance so that it
        // shuts down nicely when the VM exits (even if you "Ctrl-C" the
        // running application).
        Runtime.getRuntime().addShutdownHook( new Thread()
        {
        @Override
        public void run()
        {
        graphDb.shutdown();
        }
        } );

    }

}

And this is the content of conf/neo4j-server.properties file: 这是conf / neo4j-server.properties文件的内容:

# location of the database directory 
org.neo4j.server.database.location=data/graph.db

When I try to write a query in webadmin interface (at http://localhost:7474/webadmin ) such as: 当我尝试在webadmin界面(位于http://localhost:7474/webadmin )中编写查询时,例如:

START n=node:nodes(uname="user45")
RETURN n

I get the error message: Index 'nodes' doesnt exist So how can I see it? 我收到错误消息: Index 'nodes' doesnt exist那么我怎么看呢? Or what am I doing wrong? 还是我做错了什么?

Neo4j version: 1.9.3 Neo4j版本:1.9.3

Are you REALLY SURE that your code is running in the same working directory as your Neo4j Server? 您是否真的确定您的代码与Neo4j Server在同一工作目录中运行? Maybe you can print out the path of the current working directory in your Java program? 也许您可以在Java程序中打印出当前工作目录的路径?

在Web控制台上,您可以键入index --indexes以查看所有可用索引。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何查看从Neo4J Java应用程序创建的节点的可视图形表示? - How can I view the visual graph representation of the nodes created from a Neo4J Java Application? 如何索引neo4j中的多个日期间隔? - How can I index multiple date intervals in neo4j? 如何让java和neo4j在eclipse中工作 - How can I get java and neo4j to work in eclipse 在使用EmbeddedJava程序创建的neo4j Web界面上看不到节点 - Cannot see nodes on neo4j web interface created using EmbeddedJava program 如何从Java获取Neo4j图形数据库的节点数,如何从磁盘存储和重用graphdb? - How can I get the number of nodes of a Neo4j graph database from java and can we store and reuse graphdb from disk? 如何使用Neo4j 2.0.x中的Java API找到具有特定标签的所有节点? - How can I find all nodes with a specific label using the Java API in Neo4j 2.0.x? 在java中的neo4j嵌入式数据库中,我应该如何检查两个节点是否相互关联? - How should I check if two nodes have relationship with each other,in neo4j embedded database in java? 通过java获取neo4j中具有相同索引值的所有节点? - Get all the nodes with same index value in neo4j by java? 我将如何在Neo4j中创建此索引? - How would I create this index in Neo4j? spring neo4j:如何按不区分大小写的索引字段搜索数据? - spring neo4j: how can I search data by index field case insensitive?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM