> For the complete documentation index, see [llms.txt](https://tech.socialsafety.net/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://tech.socialsafety.net/developer-resources/creating-a-neo4j-instance-on-gcp-vm.md).

# Creating a Neo4j instance on GCP vm

To create a single instance of Neo4j in a GC virtual machine, follow the steps below:

## Set up Docker in VM

* SSH into your vm
* Update apt-get

  ```
  sudo apt-get update
  ```
* Download the following

  ```
  sudo apt-get install     apt-transport-https     ca-certificates     curl     gnupg-agent     software-properties-common
  ```
* Add docker key

  ```
  curl -fsSL https://download.docker.com/linux/debian/gpg | sudo apt-key add -
  ```
* Add fingerprint:

  ```
  sudo apt-key fingerprint 0EBFCD88
  ```
* Add the following:

  ```
  sudo add-apt-repository    "deb [arch=amd64] https://download.docker.com/linux/debian $(lsb_release -cs) stable"
  ```
* Update app-get again

  ```
  sudo apt-get update
  ```
* Now install docker

  ```
  sudo apt-get install docker-ce docker-ce-cli containerd.io
  ```

## Create Neo4J image

* Run commands to create an instance:&#x20;

  ```bash
  sudo docker run --name ssn-neo4j-production -p7474:7474 -p7687:7687 -d -v $HOME/neo4j/data:/data -v $HOME/neo4j/logs:/logs -v $HOME/neo4j/import:/var/lib/neo4j/import -v $HOME/neo4j/plugins:/plugins --env NEO4J_AUTH=neo4j/test neo4j:latest
  ```

  Or Start an existing instance:

  ```bash
     sudo docker start testneo4j
  ```
* View Neo4j in browser by navigating to http\://\<vm external ip>:7474/browser
* You can change the password from the browser console by running the following command:

  ```
  :SERVER change-password
  ```

## Install APOC on Neo4j Docker

### Install apoc jar file:

```
mkdir plugins
pushd plugins
wget https://github.com/neo4j-contrib/neo4j-apoc-procedures/releases/download/4.1.0.6/apoc-4.1.0.6-all.jar
popd
```

### Install/start neo4j with plugins directory enabled:

```
sudo docker run --name ssn-cbo-staging --rm -d -e NEO4J_AUTH=neo4j/test -p 7474:7474 -v $PWD/plugins:/plugins -p 7687:7687 neo4j:4.1
```

## Full text search on Neo4j

Ref: <https://graphaware.com/neo4j/2019/01/11/neo4j-full-text-search-deep-dive.html>

* Create a FTS index on neo4j browser or via lib

  ```
  CALL db.index.fulltext.createNodeIndex('services', ['Service'], ['name', 'alternate_name', 'description', 'taxonomy', 'program_title', 'eligibility', 'service_area', 'languages', 'address', 'region', 'city', 'country', 'zip_code','state'])
  ```
* Search based on constraints. For instance to search for `food stamps` in and only in zip\_code `76104` do the following:

  ```
  CALL db.index.fulltext.queryNodes('services', 'zip_code:76104 AND food stamps')
  ```
* Add LIMIT, SKIP and ORDER BY params:

  ```
  CALL db.index.fulltext.queryNodes('services', 'zip_code:76104 OR food stamps') YIELD node, score
  RETURN node as services, score
  ORDER BY node.name
  SKIP 1
  LIMIT 2
  ```

## Resources and Links

Uses HERE <https://developer.here.com/projects/PROD-9ad03b9a-5f17-41a1-89f6-8e337f469983/usage>

Middleware: <https://expressjs.com/en/guide/using-middleware.html#middleware.router>

Remove duplicate nodes in Neo4j: <https://gist.github.com/jruts/fe782ff2531d509784a24b655ad8ae76>

[BUILDING WITH GRANDSTACK: GraphQL, React, Apollo, and Neo4j](https://www.youtube.com/watch?v=j0FzSfP2_TE)
