Skip to content

neo4j/import-spec

Repository files navigation

Neo4j Import Specification Format

Scope

This library provides a uniform configuration facade for tools running imports to Neo4j. In particular, it offers:

The library does NOT:

  • define any sources, you need to define and register at least one (see examples)
  • implement any actual import to Neo4j (although some end-to-end tests just do that)
  • expose any configuration to locate a Neo4j instance to import data to

Getting Started

First, implement and register a source provider for BigQuery.

Then, save the following import specification into spec.json:

{
  "version": "1",
  "config": {
    "key": "value"
  },
  "sources": [
    {
      "name": "my-bigquery-source",
      "type": "bigquery",
      "query": "SELECT id, name FROM my.table"
    }
  ],
  "targets": {
    "queries": [
      {
        "name": "my-query",
        "source": "my-bigquery-source",
        "query": "UNWIND $rows AS row CREATE (n:ANode) SET n = row"
      }
    ]
  },
  "actions": [
    {
      "name": "my-http-action",
      "type": "http",
      "method": "get",
      "url": "https://example.com"
    }
  ]
}

You can then deserialize it and run your import logic accordingly:

import org.neo4j.importer.v1.ImportSpecificationDeserializer;
import org.neo4j.importer.v1.targets.Targets;

import java.io.Reader;

class GettingStarted {

    public static void main(String... args) {

        try (Reader reader = createReader("spec.json")) {
            var importSpecification = ImportSpecificationDeserializer.deserialize(reader);

            var config = importSpecification.getConfiguration();
            var sources = importSpecification.getSources();
            var actions = importSpecification.getActions();
            var targets = importSpecification.getTargets();
            var nodeTargets = targets.getNodes();
            var relationshipTargets = targets.getRelationships();
            var customQueryTargets = targets.getCustomQueries();
        }
    }
}

Prerequisites

  • Maven
  • JDK 21 (21 is used for tests, 11 for production sources)