Introduction to neo4j graph database

  • Introduction to neo4j
    • Graph database
    • Environment variable configuration (requires Java environment): NEO4J_HOME+file directory; Path: %NEO4J_HOME%\bin; input in the command window: neo4j console and then enter neo4j install-service to install the service locally; neo4j start starts the service and
      opens the data browser: http ://localhost:7474/browser/
    • Data storage: Store data in a graph structure, which can store graph nodes, attributes (key-value pairs), and edges. Attributes and nodes are stored separately, and the relationship between attributes and nodes constitutes edges.
    • Data reading and writing: In Neo4j, Index-free Adjacency technology is used when storing nodes, that is, each node has a pointer to its neighbor node, which allows us to find the neighbor node when the time complexity is O(1) . In addition, according to the official statement, the edge is the most important in Neo4j, which is First-class Entities, so it is stored separately, which is more conducive to improving the speed when traversing the graph, and it can also be easily traversed in any direction.
    • Other similar: Flockdb, Orientdb, Arangodb. Neo4j has the best stability
  • Neo4j use
    • The relationship is directional (use merge when creating a relationship, then return, if not, create; use create, it will always create)

    • The graph database stores all its data in nodes and relationships, and stores the data in the form of graphs in the native format

    • Use native GPE engine to use its native image storage format

    • A relationship can have an attribute as a key-value pair. For example: ID= 123

    • Labels associate a set of common nodes or relationships, and nodes or relationships can contain one or more labels

    • Use () to identify the node, use [] to identify the relationship

    • create Create node, relationship and attribute
      match Retrieve related node, relationship and attribute
      return Return query result
      where Provide condition to retrieve data
      delete delete node and relationship
      remove delete node and relationship attribute
      order by sorting retrieve data
      set Add or update label

    • boolean Boolean type: true, false
      byte 8-bit integer
      short 16-bit integer
      int 32-bit integer
      long 64-bit integer
      float 32-bit floating-point number
      double 64-bit floating-point number
      char 16-bit character
      String string

    • Neo4j database server uses <node-name> to store the node details in Database.As as Neo4j DBA or Developer, and it cannot be used to access node details.
      Neo4j database server creates a <label-name> as an alias for the internal node name . Use this tag name to access node details

    • match should be used with return, set and delete

    • Modification of neo4j configuration file

    • match (a:author) set a.name="wu" return a      #增加属性或者修改属性。这里'a'是给'author'起个"变量名",下面类似
      match (n:author) where n.name=~'w*' return n   #可以使用正则匹配
      match (n:author) where n.name contains 'w' return n   #包含查询
      DETACH DELETE    #子句允许你删除一个节点的同时删除与其相连的所有关系
      match(c:Customer) where id(c)=110 delete c return c    #根据节点id删除节点
      match (c:Creditcard) where id(c)=111 set c.name="工商银行" return c  #根据节点id增加属性
      match (c:Customer) match (a:Creditcard) create (a)-[r:消费]->(c)  return r    #创建关系                                                
      match (w:weibo),(c:chaping) where w.emot=0 create (w)-[r1:差评]->(c) return r1 #根据属性建立节点关系
      MATCH p=()-[r:`消费`]->() where id(r)=0 set r.`额度`=200000 return r #创建关系的属性
      match (c:Customer) return c.name as name,c.id as id union match (a:Creditcard) return a.id as id,a.name as name        #联合查询,此处id只能返回节点属性里设置的id,默认节点id会返回null.(union查询会过滤掉重复行,union all 返回所有数据)
      create(drop) index on :author(name)   #创建/删除索引
      create(drop) constraint on (a:author) assert (a:author) is unique  #创建/删除约束
      
    • APOC(a package of component):

      • Two jar packages, put them in the plugins directory of neo4j: apoc-3.4.0.3.jar and mysql-connector-java-5.1.21.jar
      • Text and Lookup indexes (text and index search)
      • utility functions (utility functions): domain name extraction, time, date, data format conversion and other functions
      • graph algorithms: community detection, PageRank, central algorithm, etc.
      • Spatial (spatial function): geocoding, location calculation, space and time search, etc.
      • data integration: JSON, JDBC, CSV and other data loading
      • graph refactorings: node merging, attribute specification and classification, etc.
      • virtual nades/rels (virtual nodes/relations): Provides the creation of virtual graphs
      • cypher operations: single and multiple cypher statement operation and script operation
      • Triggers (triggers): the same way of understanding triggers as relational databases
    • Neo4j import triple data group

      • Turn off the computer's neo4j service
      • Delete the default database file \data\databases\graph.db of neo4j, otherwise create a new database file under this path, the file name is ***.db, and then modify the configuration file of neo4j \conf\neo4j.conf, modify Office: #dbms.active_database=graph.db, change the name of your newly created database and uncomment
      • There are many ways to import data, I used the import method to put the organized node csv and relationship csv into the import file of neo4j
      • 导入文件命令:neo4j-admin import --nodes E:\neo4j-community-3.5.14\import\entity.csv --relationships E:\neo4j-community-3.5.14\import\relationship.csv --multiline-fields=true --ignore-missing-nodes=true
      • Open the neo4j service, enter the built-in visualization website to view the graph database

Guess you like

Origin blog.csdn.net/weixin_46046193/article/details/108632351