针对节点删除,加了一些逻辑,代码地址
需要强大的检索功能,所有需要被查询的数据都在neo4j。
Storage
类。当有新数据通过RestAPI存入Neo4j时,同时存一份到ElasticSearch方案的选择采用第二种,原因有二
实验环境: Ubuntu16.04
Docker 17.12.1-ce
(由于采用Docker,环境对实验影响不大)
wget https://github.com/neo4j-contrib/neo4j-elasticsearch/releases/download/3.2.3/neo4j-elasticsearch-3.2.3.jar
docker run -p 9200:9200 -d --name es elasticsearch:2.3
docker run -p 7474:7474 -p 7687:7687 -v /home/bonsai/Demo/conf:/var/lib/neo4j/conf -v /home/bonsai/Demo/plugins:/var/lib/neo4j/plugins --name neo -d --link es:es neo4j:3.2.3
cp neo4j-elasticsearch-3.2.3.jar /home/bonsai/Demo/plugins
vim /home/bonsai/Demo/conf/neo4j.conf
elasticsearch.host_name=http://es:9200
elasticsearch.index_spec=people:Person(first_name,last_name), places:Place(name)
docker exec neo /bin/bash -c "echo 'neo4j:SHA-256,BC43474518A71BA7BEB54461F769A76195226474BFE892FF2562211DFD8043FA,B6070629C73CE74455674D39D65BA3DF:' > data/dbms/auth"
docker restart neo
docker exec neo cat /var/lib/neo4j/logs/debug.log | grep elastic
在Neo4j-ElasticSearch插件中,引用了index_spec
这个配置。具体实现细节下节分析。试用的时候只要知道我们定义了
elasticsearch.index_spec=people:Person(first_name,last_name), places:Place(name)
表示会将Person
标签的Node的first_name
与last_name
属性存入ES people
索引中,会将Place
标签的Node的name
属性存入ES places
索引中
curl -X POST \
http://localhost:7474/db/data/cypher \
-H 'authorization: Basic bmVvNGo6bmVvNGo=' \
-H 'content-type: application/json' \
-d '{
"query" : "CREATE (n:Person { first_name : {firstname}, last_name: {lastname} }) RETURN n",
"params" : {
"firstname" : "Bonsai",
"lastname": "Y"
}
}
'
成功创建后访问ES数据库查看
curl -X GET 'http://127.0.0.1:9200/people/_search?pretty='
curl -X POST \
http://localhost:7474/db/data/cypher \
-H 'authorization: Basic bmVvNGo6bmVvNGo=' \
-H 'content-type: application/json' \
-d '{
"query" : "MATCH (n:Person) SET n.first_name = { newfirstname } RETURN n",
"params" : {
"newfirstname" : "new_bonsai"
}
}'
成功修改后访问ES数据库查看
curl -X GET 'http://127.0.0.1:9200/people/_search?pretty='
curl -X POST \
http://localhost:7474/db/data/cypher \
-H 'authorization: Basic bmVvNGo6bmVvNGo=' \
-H 'content-type: application/json' \
-d '{
"query" : "MATCH (n:Person) Delete n"
}'
成功删除后访问ES数据库查看
curl -X GET 'http://127.0.0.1:9200/people/_search?pretty='