{"id":10259,"date":"2023-05-12T20:50:56","date_gmt":"2023-05-13T01:50:56","guid":{"rendered":"https:\/\/www.rushworth.us\/lisa\/?p=10259"},"modified":"2023-08-28T13:53:27","modified_gmt":"2023-08-28T18:53:27","slug":"neo4j-setting-up-and-basic-record-management","status":"publish","type":"post","link":"https:\/\/www.rushworth.us\/lisa\/?p=10259","title":{"rendered":"Neo4J &#8212; Setting Up and Basic Record Management"},"content":{"rendered":"<h2>Setting up a Neo4J Database<\/h2>\n<p>Ostensibly, you can create a new database using \u201ccreate database somethingorother\u201d. However, that is if you are using the <em>enterprise<\/em> edition. Running the community edition, you can only run one database. Attempting to create a new database will produce an error indicating <strong>Neo.ClientError.Statement.UnsupportedAdministrationCommand<\/strong><\/p>\n<p>To use a database with a custom name, I need to edit neo4j.conf and set initial.dbms.default_database<\/p>\n<p><a href=\"https:\/\/www.rushworth.us\/lisa\/wp-content\/uploads\/2023\/08\/neo4j-image1.png\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-10263\" src=\"https:\/\/www.rushworth.us\/lisa\/wp-content\/uploads\/2023\/08\/neo4j-image1.png\" alt=\"\" width=\"950\" height=\"229\" srcset=\"https:\/\/www.rushworth.us\/lisa\/wp-content\/uploads\/2023\/08\/neo4j-image1.png 950w, https:\/\/www.rushworth.us\/lisa\/wp-content\/uploads\/2023\/08\/neo4j-image1-300x72.png 300w, https:\/\/www.rushworth.us\/lisa\/wp-content\/uploads\/2023\/08\/neo4j-image1-768x185.png 768w, https:\/\/www.rushworth.us\/lisa\/wp-content\/uploads\/2023\/08\/neo4j-image1-750x181.png 750w\" sizes=\"auto, (max-width: 950px) 100vw, 950px\" \/><\/a><\/p>\n<p>Then create a Docker container \u2013 I am mapping \/data to an external directory to persist my data and \/var\/lib\/neo4j\/conf to an external directory to persist configuration<\/p>\n<p><tt>docker run -dit --name neo4j --publish=7474:7474 --publish=7687:7687 --env=NEO4J_AUTH=none --volume=\/docker\/neo4j\/data:\/data --volume=\/docker\/neo4j\/conf:\/var\/lib\/neo4j\/conf neo4j<\/tt><\/p>\n<p>Listing the databases using \u201cshow databases\u201d will show my custom database name<\/p>\n<p><a href=\"https:\/\/www.rushworth.us\/lisa\/wp-content\/uploads\/2023\/08\/neo4j-image2.png\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-10264\" src=\"https:\/\/www.rushworth.us\/lisa\/wp-content\/uploads\/2023\/08\/neo4j-image2.png\" alt=\"\" width=\"1823\" height=\"423\" srcset=\"https:\/\/www.rushworth.us\/lisa\/wp-content\/uploads\/2023\/08\/neo4j-image2.png 1823w, https:\/\/www.rushworth.us\/lisa\/wp-content\/uploads\/2023\/08\/neo4j-image2-300x70.png 300w, https:\/\/www.rushworth.us\/lisa\/wp-content\/uploads\/2023\/08\/neo4j-image2-1024x238.png 1024w, https:\/\/www.rushworth.us\/lisa\/wp-content\/uploads\/2023\/08\/neo4j-image2-768x178.png 768w, https:\/\/www.rushworth.us\/lisa\/wp-content\/uploads\/2023\/08\/neo4j-image2-1536x356.png 1536w, https:\/\/www.rushworth.us\/lisa\/wp-content\/uploads\/2023\/08\/neo4j-image2-750x174.png 750w\" sizes=\"auto, (max-width: 1823px) 100vw, 1823px\" \/><\/a><\/p>\n<p>Switch to our database with the \u201c:use\u201d instruction<\/p>\n<p><a href=\"https:\/\/www.rushworth.us\/lisa\/wp-content\/uploads\/2023\/08\/neo4j-image3.png\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-10265\" src=\"https:\/\/www.rushworth.us\/lisa\/wp-content\/uploads\/2023\/08\/neo4j-image3.png\" alt=\"\" width=\"1452\" height=\"269\" srcset=\"https:\/\/www.rushworth.us\/lisa\/wp-content\/uploads\/2023\/08\/neo4j-image3.png 1452w, https:\/\/www.rushworth.us\/lisa\/wp-content\/uploads\/2023\/08\/neo4j-image3-300x56.png 300w, https:\/\/www.rushworth.us\/lisa\/wp-content\/uploads\/2023\/08\/neo4j-image3-1024x190.png 1024w, https:\/\/www.rushworth.us\/lisa\/wp-content\/uploads\/2023\/08\/neo4j-image3-768x142.png 768w, https:\/\/www.rushworth.us\/lisa\/wp-content\/uploads\/2023\/08\/neo4j-image3-750x139.png 750w\" sizes=\"auto, (max-width: 1452px) 100vw, 1452px\" \/><\/a><\/p>\n<h2>Create single nodes<\/h2>\n<p>CREATE (:PLANTS {name: &#8216;Black Krim&#8217;, year: 1856, color: &#8216;deep red&#8217;, flavor: &#8216;sweet&#8217;, notes: &#8216;Heirloom seedstock&#8217;})<\/p>\n<p><a href=\"https:\/\/www.rushworth.us\/lisa\/wp-content\/uploads\/2023\/08\/neo4j-image4.png\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-10266\" src=\"https:\/\/www.rushworth.us\/lisa\/wp-content\/uploads\/2023\/08\/neo4j-image4.png\" alt=\"\" width=\"1815\" height=\"192\" srcset=\"https:\/\/www.rushworth.us\/lisa\/wp-content\/uploads\/2023\/08\/neo4j-image4.png 1815w, https:\/\/www.rushworth.us\/lisa\/wp-content\/uploads\/2023\/08\/neo4j-image4-300x32.png 300w, https:\/\/www.rushworth.us\/lisa\/wp-content\/uploads\/2023\/08\/neo4j-image4-1024x108.png 1024w, https:\/\/www.rushworth.us\/lisa\/wp-content\/uploads\/2023\/08\/neo4j-image4-768x81.png 768w, https:\/\/www.rushworth.us\/lisa\/wp-content\/uploads\/2023\/08\/neo4j-image4-1536x162.png 1536w, https:\/\/www.rushworth.us\/lisa\/wp-content\/uploads\/2023\/08\/neo4j-image4-750x79.png 750w\" sizes=\"auto, (max-width: 1815px) 100vw, 1815px\" \/><\/a><\/p>\n<p><em>Note: <\/em>After I started using my data, I realized that \u201cPLANTS\u201d is a silly label to use since they will <em>all<\/em> be plants. I recreated all of my data with nodes labeled \u201cTOMATO\u201d so I can also track peppers, daffodils, and any other plants we start hybridizing.<\/p>\n<p>Load of all records:<\/p>\n<pre>CREATE(:TOMATO {flavor: \"air\",notes: \"hypothetical\",color: \"invisible\",year: \"1\",name: \"PLANT0\"});\r\nCREATE(:TOMATO {flavor: \"acidic\",notes: \"Heirloom seedstock\",color: \"purple\",year: 1890,name: \"Cherokee Purple\"});\r\nCREATE(:TOMATO {flavor: \"sweet\",notes: \"Heirloom seedstock\",color: \"bright red\",name: \"Whittemore\"});\r\nCREATE(:TOMATO {flavor: \"sweet\",notes: \"Heirloom seedstock\",color: \"deep red\",year: 1856,name: \"Black Krim\"});\r\nCREATE(:TOMATO {name: 'Kellogg', color: 'bright red', flavor: 'sweet', year: '1900', notes: 'beautiful and tasty'});\r\nCREATE(:TOMATO {name: 'Brandywine', color: 'bright red', flavor: 'sweet', year: '1900', notes: 'very tasty'});\r\nCREATE(:TOMATO {name: 'Japanese Trifele Black', color: 'dark purple red', flavor: 'sweet', year: '1900', notes: 'nice acidic flavor'});\r\nCREATE(:TOMATO {name: 'Sweet Apertif', color: 'bright red', flavor: 'sweet', year: '1900', notes: 'cherry'});\r\nCREATE(:TOMATO {name: 'Eva Purple', color: 'dark purple red', flavor: 'sweet', year: '1900', notes: 'did not grow well'});\r\nCREATE(:TOMATO {name: 'Mortgage Lifter', color: 'bright red', flavor: 'sweet', year: '1900', notes: 'huge but lacking flavor and lots of bad spots'});\r\nCREATE(:TOMATO {flavor: \"sweet\",notes: \"\",color: \"deep red\",year: \"2021\",name: \"Tomato0000001\"});\r\nCREATE(:TOMATO {flavor: \"bland\",notes: \"small tomatoes with little flavor\",color: \"red\",year: \"2021\",name: \"Tomato0000002\"});\r\nCREATE(:TOMATO {flavor: \"watery\",notes: \"not much acid\",color: \"pinkish\",year: \"2022\",name: \"Tomato0000003\"});\r\nCREATE(:TOMATO {flavor: \"sweet\",notes: \"sweet, slightly acidic\",color: \"red\",year: \"2022\",name: \"Tomato0000004\"}) ;\r\nCREATE (:TOMATO {name: 'Tomato0000005', color: 'bright red', flavor: 'sweet', year: '2022', notes: 'amazing'});\r\nCREATE (:TOMATO {name: 'Tomato0000006', color: 'bright red', flavor: 'sweet', year: '2023', notes: 'beautiful and tasty but no bigger than parent'});\r\nCREATE (:TOMATO {name: 'Tomato0000007', color: 'bright red', flavor: 'sweet', year: '2023', notes: 'beautiful and tasty but no bigger than parent'});\r\nCREATE (:TOMATO {name: 'Tomato0000008', color: 'bright red', flavor: 'sweet', year: '2023', notes: 'beautiful and tasty, slightly larger than parent'});<\/pre>\n<h2>Show records with MATCH<\/h2>\n<p>The search starts with the verb \u201cMATCH\u201d. In parenthesis, we add the matching rule. This begins with an object name variable \u2013 you can have anonymous nodes (no variable names assigned) by omitting this string and just typing the colon. This is followed by the label that we want to match \u2013 basically the type of node we are looking for. Then, in curly braces, a filter \u2013 in this case, I am looking for nodes where the \u201cname\u201d field has the value \u201cBlack Krim\u201d. Finally, there\u2019s a return statement that indicates that we want to output the matched results.<\/p>\n<p><a href=\"https:\/\/www.rushworth.us\/lisa\/wp-content\/uploads\/2023\/08\/neo4j-image5.png\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-10267\" src=\"https:\/\/www.rushworth.us\/lisa\/wp-content\/uploads\/2023\/08\/neo4j-image5.png\" alt=\"\" width=\"1045\" height=\"627\" srcset=\"https:\/\/www.rushworth.us\/lisa\/wp-content\/uploads\/2023\/08\/neo4j-image5.png 1045w, https:\/\/www.rushworth.us\/lisa\/wp-content\/uploads\/2023\/08\/neo4j-image5-300x180.png 300w, https:\/\/www.rushworth.us\/lisa\/wp-content\/uploads\/2023\/08\/neo4j-image5-1024x614.png 1024w, https:\/\/www.rushworth.us\/lisa\/wp-content\/uploads\/2023\/08\/neo4j-image5-768x461.png 768w, https:\/\/www.rushworth.us\/lisa\/wp-content\/uploads\/2023\/08\/neo4j-image5-750x450.png 750w\" sizes=\"auto, (max-width: 1045px) 100vw, 1045px\" \/><\/a><\/p>\n<p>You can include <em>relationships<\/em> in the query \u2013 parenthesis around nodes and square brackets around relationships.<\/p>\n<p><tt>(placeholdername:nodes)-[:RELATIONSHIP_CONNECTION_TYPE]-&gt;(anotherplaceholdername:otherNodes)<\/tt><\/p>\n<p>This is what makes graph databases interesting for tracking hybridization \u2013 we can easily produce the lineage of the plants we develop.<\/p>\n<h2>Deleting a record<\/h2>\n<p>Deleting a record is used in conjunction with match &#8212; use the DELETE verb on the collections of objects returned into your variable name. Here, the variable is &#8216;x&#8217;:<\/p>\n<pre>MATCH (x:PLANTS{name: 'Black Krim'})\r\nDELETE x<\/pre>\n<h2>Deleting a record and relationships by ID<\/h2>\n<p>When deleting a record, you can include relationship matches:<\/p>\n<pre>MATCH (p:PLANTS) where ID(p)=1\r\nOPTIONAL MATCH (p)-[r]-()\r\nDELETE r,p<\/pre>\n<h2>Create a relationship<\/h2>\n<p>To create a relationship, we first need to match two objects \u2013 here I am finding a plant named PLANT0 and all of the \u201cheirloom seedstock\u201d plants to which I assigned year 1900 \u2013 and create parent\/child relationships. Since there is both a male and female parent, that is included in the relationship name:<\/p>\n<pre>MATCH (a:TOMATO), (b:TOMATO)\r\nWHERE a.name = 'PLANT0' AND b.year = '1900'\r\nCREATE (a)-[r:PARENT_M]-&gt;(b)\r\n\r\nMATCH (a:TOMATO), (b:TOMATO)\r\nWHERE a.name = 'PLANT0' AND b.year = '1900'\r\nCREATE (a)-[r:PARENT_F]-&gt;(b)<\/pre>\n<h2>Create records with parent\/child relationships<\/h2>\n<p>You can create records and relationships in a single command, too:<\/p>\n<pre>CREATE p = (:PLANTS {name: 'Black Krim', year: 1856, color: 'deep red', flavor: 'sweet', notes: 'Heirloom seedstock'})-[:PARENT_M]-&gt;(:PLANTS {name: 'Tomato0000001', color: 'deep red', flavor: 'sweet', year: '2023', notes: ''})&lt;-[:PARENT_F]-(:PLANTS {name: 'Cherokee Purple', color: 'purple', flavor: 'acidic', year: 1890, notes: 'Heirloom seedstock'})\r\n\r\nRETURN p<\/pre>\n<h2><a href=\"https:\/\/www.rushworth.us\/lisa\/wp-content\/uploads\/2023\/08\/neo4j-image7.png\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-10268\" src=\"https:\/\/www.rushworth.us\/lisa\/wp-content\/uploads\/2023\/08\/neo4j-image7.png\" alt=\"\" width=\"1436\" height=\"674\" srcset=\"https:\/\/www.rushworth.us\/lisa\/wp-content\/uploads\/2023\/08\/neo4j-image7.png 1436w, https:\/\/www.rushworth.us\/lisa\/wp-content\/uploads\/2023\/08\/neo4j-image7-300x141.png 300w, https:\/\/www.rushworth.us\/lisa\/wp-content\/uploads\/2023\/08\/neo4j-image7-1024x481.png 1024w, https:\/\/www.rushworth.us\/lisa\/wp-content\/uploads\/2023\/08\/neo4j-image7-768x360.png 768w, https:\/\/www.rushworth.us\/lisa\/wp-content\/uploads\/2023\/08\/neo4j-image7-750x352.png 750w\" sizes=\"auto, (max-width: 1436px) 100vw, 1436px\" \/><\/a><\/h2>\n<h2>Viewing Records with Relationships<\/h2>\n<p>When you match records, you will also get their relationships:<\/p>\n<p><a href=\"https:\/\/www.rushworth.us\/lisa\/wp-content\/uploads\/2023\/08\/neo4j-image8.png\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-10269\" src=\"https:\/\/www.rushworth.us\/lisa\/wp-content\/uploads\/2023\/08\/neo4j-image8.png\" alt=\"\" width=\"1445\" height=\"675\" srcset=\"https:\/\/www.rushworth.us\/lisa\/wp-content\/uploads\/2023\/08\/neo4j-image8.png 1445w, https:\/\/www.rushworth.us\/lisa\/wp-content\/uploads\/2023\/08\/neo4j-image8-300x140.png 300w, https:\/\/www.rushworth.us\/lisa\/wp-content\/uploads\/2023\/08\/neo4j-image8-1024x478.png 1024w, https:\/\/www.rushworth.us\/lisa\/wp-content\/uploads\/2023\/08\/neo4j-image8-768x359.png 768w, https:\/\/www.rushworth.us\/lisa\/wp-content\/uploads\/2023\/08\/neo4j-image8-750x350.png 750w\" sizes=\"auto, (max-width: 1445px) 100vw, 1445px\" \/><\/a><\/p>\n<h2>Bulk importing data<\/h2>\n<p>LOAD CSV WITH HEADERS FROM &#8216;https:\/\/www.rushworth.us\/lisa\/ljr_plant_history.csv&#8217;<\/p>\n<p>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Setting up a Neo4J Database Ostensibly, you can create a new database using \u201ccreate database somethingorother\u201d. However, that is if you are using the enterprise edition. Running the community edition, you can only run one database. Attempting to create a new database will produce an error indicating Neo.ClientError.Statement.UnsupportedAdministrationCommand To use a database with a custom &hellip;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1805,983,1896],"tags":[1899,1898,1897],"class_list":["post-10259","post","type-post","status-publish","format-standard","hentry","category-business-homesteading","category-fruits-and-vegetables","category-neo4j","tag-genetics","tag-graph-database","tag-neo4j"],"_links":{"self":[{"href":"https:\/\/www.rushworth.us\/lisa\/index.php?rest_route=\/wp\/v2\/posts\/10259","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.rushworth.us\/lisa\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.rushworth.us\/lisa\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.rushworth.us\/lisa\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.rushworth.us\/lisa\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=10259"}],"version-history":[{"count":4,"href":"https:\/\/www.rushworth.us\/lisa\/index.php?rest_route=\/wp\/v2\/posts\/10259\/revisions"}],"predecessor-version":[{"id":10306,"href":"https:\/\/www.rushworth.us\/lisa\/index.php?rest_route=\/wp\/v2\/posts\/10259\/revisions\/10306"}],"wp:attachment":[{"href":"https:\/\/www.rushworth.us\/lisa\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=10259"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.rushworth.us\/lisa\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=10259"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.rushworth.us\/lisa\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=10259"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}