日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁(yè) > 编程资源 > 编程问答 >内容正文

编程问答

neo4j整理

發(fā)布時(shí)間:2024/4/13 编程问答 22 豆豆
生活随笔 收集整理的這篇文章主要介紹了 neo4j整理 小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.

語(yǔ)法

數(shù)據(jù)庫(kù)

列出所有數(shù)據(jù)庫(kù)

:dbs

選擇數(shù)據(jù)庫(kù)

:use neo4j

一個(gè)實(shí)例就只能有一個(gè)數(shù)據(jù)庫(kù)。

如果節(jié)點(diǎn)分應(yīng)用,則通過label區(qū)分

?

學(xué)習(xí)

:play start?

查詢

match(n:bot) return n limit 20

查詢屬性分組并過濾

with用于分組后再處理。

Match( n:bot)?
with n.name as name ,count(1) as c
?where c > 1?
?return ?name ,c ;

返回:

╒══════╤═══╕ │"name"│"c"│ ╞══════╪═══╡ │"盆地" │2 │ ├──────┼───┤ │"圈閉" │2 │ └──────┴───┘

?

通過id刪除實(shí)體及其關(guān)系

MATCH (r:bot)
WHERE id(r) = 377
detach delete r
?

獲取屬性

return properties(n) AS properties,ID(n) as id, labels(n) AS label

返回值:

╒═════════════════════════════════════════════════════════╤════╤═══════╕ │"properties" │"id"│"label"│ ╞═════════════════════════════════════════════════════════╪════╪═══════╡ │{"name":"圈閉","id":"6184e0fa-d1d6-4618-8c9a-ff27f5f2af10"}│361 │["bot"]│ ├─────────────────────────────────────────────────────────┼────┼───────┤ │{"name":"圈閉","id":"syxz-d1d6-4618-8c9a-ff27f5f2af10"} │376 │["bot"]│ └─────────────────────────────────────────────────────────┴────┴───────┘

?

Match( n:bot{name:"圈閉"}) return n.name;

返回

╒════════╕ │"n.name"│ ╞════════╡ │"圈閉" │ ├────────┤ │"圈閉" │ └────────┘

修改

修改標(biāo)簽

create ( n:AAA {name:"testlabel"}) return n;

Match( n:AAA ) set n:aaa remove n:AAA return n;

?

數(shù)據(jù)加載

加載方式

?create語(yǔ)句load csv語(yǔ)句Batch InserterBatch Importneo4j-import
適用場(chǎng)景1~1w nodes1w~10w nodes千萬以上 nodes千萬以上 nodes千萬以上 nodes
速度很慢(1000 nodes/s)一般(5000 nodes/s)非常快(數(shù)萬nodes/s)非常快(數(shù)萬nodes/s)非常快(數(shù)萬nodes/s)
優(yōu)點(diǎn)使用方便,可實(shí)時(shí)插入。使用方便,可以加載本地遠(yuǎn)程CSV;可實(shí)時(shí)插入基于Batch Inserter,可以直接運(yùn)行編譯好的jar包;可以在已存在的數(shù)據(jù)庫(kù)中導(dǎo)入數(shù)據(jù)官方出品,比Batch Import占用更少的資源
缺點(diǎn)速度慢需要將數(shù)據(jù)轉(zhuǎn)換成csv需要轉(zhuǎn)成CSV;只能在JAVA中使用;且插入時(shí)必須停止neo4j需要轉(zhuǎn)成CSV;必須停止neo4j需要轉(zhuǎn)成CSV;必須停止neo4j;只能生成新的數(shù)據(jù)庫(kù),而不能在已存在的數(shù)據(jù)庫(kù)中插入數(shù)據(jù)

load csv

使用的是windows下的neo4j browser,在導(dǎo)入數(shù)據(jù)之前,需要將EXCEL另存為CSV,如果有多個(gè)sheet,則需要分開單獨(dú)存儲(chǔ)

USING PERIODIC COMMIT 300 LOAD CSV WITH HEADERS FROM “file:///test.csv” AS line MERGE (a:actors{name:line.name,type:line.type,id:line.id})

本地?cái)?shù)據(jù)文件放在\Neo4j\graph.db\import文件夾內(nèi),遠(yuǎn)程數(shù)據(jù)文件可以使用文件URL

在import文件夾里放了一個(gè)actors.csv 文件,然后指定file:///actors.csv 即可訪問該文件

可變參數(shù)解釋:

1、USING PERIODIC COMMIT 300

使用自動(dòng)提交,每滿300條提交一次,防止內(nèi)存溢出

2、WITH HEADERS

從文件中讀取第一行作為參數(shù)名,只有在使用了該參數(shù)后,才可以使用line.name這樣的表示方式,否則需使用line[0]的表示方式

3、AS line

為每行數(shù)據(jù)重命名

4、MERGE

用merge比用create好一點(diǎn),可以防止數(shù)據(jù)重復(fù) 上面的語(yǔ)句可修改為如下

USING PERIODIC COMMIT 10
LOAD CSV FROM "file:///actors.csv" AS line
create (a:actors{personId:line[0],name:line[1],type:line[2]})

USING PERIODIC COMMIT 10

LOAD CSV FROM “file:///roles.csv” AS line

MATCH (from:movies{movieId:line[2]}),(to:actors{personId:line[0]})

merge (from)-[r:ACTED_IN{miles:line[1]}]-> (to) return r

?

actors.csv 文件位于neo4j 的import 文件目錄下。

?

shell加載文件

cypher-shell可以執(zhí)行腳本文件.

交互式命令

? :begin??? Open a transaction
? :commit?? Commit the currently open transaction
? :exit???? Exit the logger
? :help???? Show this help message
? :history? Print a list of the last commands executed
? :param??? Set the value of a query parameter
? :params?? Print all currently set query parameters and their values
? :rollback Rollback the currently open transaction
? :source?? Interactively executes cypher statements from a file
? :use????? Set the active database

?

執(zhí)行文件:

:source /data/temp/pt.r.txt

或者

cypher-shell load csv ...

?

?

sh命令

?-host????? Domain name or IP of host to connect to (default: localhost)
?-port????? Port of host to connect to (default: 1337)
?-name????? RMI name, i.e. rmi://<host>:<port>/<name> (default: shell)
?-pid?????? Process ID to connect to
?-c???????? Command line to execute. After executing it the shell exits
?-file????? File containing commands to execute, or '-' to read from stdin. After executing it the shell exits
?-readonly? Connect in readonly mode (only for connecting with -path)
?-path????? Points to a neo4j db path so that a local server can be started there
?-config??? Points to a config file when starting a local server

?Example arguments for remote:
??????? -port 1337
??????? -host 192.168.1.234 -port 1337 -name shell
??????? -host localhost -readonly
??????? ...or no arguments for default values
Example arguments for local:
??????? -path /path/to/db
??????? -path /path/to/db -config /path/to/neo4j.config
??????? -path /path/to/db -readonly

示例:

./bin/neo4j-shell -c < /data/stale/data01/neo4j/create_index.cypher

./bin/neo4j-shell -path /data/stale/data01/neo4j/neo4j-community-3.1.0/data/dbms/ -conf /data/stale/data01/neo4j/neo4j-community-3.1.0/conf/neoo4j.conf -file /data/stale/data01/neo4j/create_index.cypther

?

?

?

總結(jié)

以上是生活随笔為你收集整理的neo4j整理的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯(cuò),歡迎將生活随笔推薦給好友。