Peu de connaissances de Neo4j

Comment importer un fichier csv Neo4j

La présentation suivante est un fichier csv avec un en-tête de fichier

1. Importez tous le fichier csv à la machine / import dossier
2. Exécutez les instructions d'importation ne peut pas définir le chemin vers
Windows dans le même répertoire répertoire bin Importer
Linux dans / var / lib / Neo4j / import

--导入节点
LOAD CSV WITH HEADERS FROM "file:///person.csv" AS line  CREATE(n:Person{id:line.personId,name:line.name})
                                                                         
--导入关系
--支持 toInt(),toFloat()函数
LOAD CSV WITH HEADERS FROM "file:///relation.csv" AS line
match (from{personId:line.targetId}),(to{personId:line.sourceId})
merge (from)-[r:关系{sourceId:line.sourceId,targetId:line.targetId,关系类型:line.关系类型,借债金额:toFloat(line.借债金额),借债时间:toInt(line.借债时间)}]->(to)


--给关系属性加新数据
match ()-[r]-() set r.开始时间 = toInt('20180101')

Neo4j soutient également de nombreuses fonctions, vous pouvez vérifier l'API officielle

Demande Neo4j

--最短路径查询{路径中不支持定义查询维度}
MATCH (n),(m) ,p=allShortestPaths((n)-[*]-(m))  where id(n)=91 and id(m)=42  RETURN p
                    
--定义路径查询,存在即返回值,否则不返回
MATCH (n),(m) ,p=(n)-[r*..3]-(m)  where id(n)=91 and id(m)=42  RETURN p
                      
--关系筛选[以顶点xxxx开始,3度以内的全部关系满足才会返回数据]
MATCH p=(n)-[r*..3]-() where n.name = 'xxxx' 
and all( x in relationships(p) where x.xxx = xxx)
return p

La relation entre le criblage ci-dessus, répondant aux besoins de base des propriétés de filtration de la projection, et la valeur de retour est non aberrant

Java requête

public class CypherNeo4jOperation {
	private final static Logger logger = LoggerFactory.getLogger(CypherNeo4jOperation.class);

	// NEo4j driver properties
	private String URI;
	private String USER;
	private String PASSWORD;
	private Driver driver;
	private static Session session;
	private StatementResult result;

	private static volatile CypherNeo4jOperation instance = null;

	public static Session getSession() {
		return CypherNeo4jOperation.session;
	}

	public CypherNeo4jOperation() {
	}

	/**
	 * @param
	 * @return
	 */
	public CypherNeo4jOperation(String uri, String user, String password) {
		this.URI = uri.trim();
		this.USER = user.trim();
		this.PASSWORD = password.trim();
		this.driver = GraphDatabase.driver(URI, AuthTokens.basic(USER, PASSWORD));
		this.session = driver.session();
	}

	/**
	 * @param
	 * @return
	 */
	public synchronized static final CypherNeo4jOperation getInstance(String bolt, String username, String password) {

		if (instance == null) {
			// 加锁
			synchronized (CypherNeo4jOperation.class) {
				// 这一次判断也是必须的,不然会有并发问题
				if (instance == null) {
					instance = new CypherNeo4jOperation(bolt, username, password);
				}
			}
		}
		logger.info("Neo4j status " + instance.toString());
		return instance;
	}

	/**
	 * @param cypher neo4j查询语句
	 * @return String
	 * @Description: (返回查询结束的结果)
	 */
	public String cypherJson(String cypher) {
		logger.info(cypher);
		StatementResult result = session.run(cypher); 
    }
Publié six articles originaux · louanges gagnées 0 · Vues 832

Je suppose que tu aimes

Origine blog.csdn.net/csdn960616/article/details/91792885
conseillé
Classement