天天看點

neo4j通過腳本建立索引

場景:neo4j通過neo4j-admin import導數完成後由腳本執行建立索引(neo4j load csv則不存在這個問題,因為其用jar包方式導數,在此期間可以在java導數的業務中加入執行建立索引的方法,當然也可以選擇此腳本建立的方式)。

用腳本調用cypher-shell執行index.cypher檔案中的建立腳本語句;

sh檔案中加入指令:

    cat <filepath> | <cypher-shell path> -u <username> -p <password> --format plain

filepath : 執行建立索引語句檔案的絕對路徑

cypher-shell path : cypher-shell工具的絕對路徑

username : neo4j使用者名稱

password :neo4j使用者密碼

    例如:

    cat index.cypher | /home/neo4j/neo4j-community-3.3.5/bin/cypher-shell -u neo4j -p neo4j --format plain

 index.cypher檔案内容(建立索引的Cypher語句):

    create index on : Lable(id);

    create index on : Lable(name);

繼續閱讀