Amar jaiswal
Amar jaiswal

Reputation: 55

How to define large set of properties of a node without having to type them all?

I have imported a csv file into neo4j. I have been trying to define a large number of properties (all the columns) for each node. How can i do that without having to type in each name?

I have been trying this:

USING PERIODIC COMMIT
load csv WITH headers from "file:///frozen_catalog.csv" AS line

//Creating nodes for each product id with its properties
CREATE (product:product{id : line.`o_prd`,
Gross_Price_Average: TOINT(line.`Gross_Price_Average`),
O_PRD_SPG: TOINT(line.`O_PRD_SPG`)});

Upvotes: 1

Views: 198

Answers (2)

InverseFalcon
InverseFalcon

Reputation: 30407

The LOAD CSV command cannot perform automatic type conversion to ints on certain fields, that must be done explicitly (though you can avoid having to explicitly mention all other fields by using the map projection feature to transform your line data before setting it via stdob--'s suggestion).

You may want to take a look at Neo4j's import tool, as this will allow you to specify field type in headers, which should perform type conversion for you.

That said, 77 columns is a lot of data to all store on individual nodes. You may want to take another look at your data and figure out if some of those properties would be better modeled as nodes with their own label with relationships to your product nodes. You mentioned some of these were categorical properties. Categories are well suited to be modeled separately as nodes instead of as properties, and maybe some of your other properties would work better as nodes as well.

Upvotes: 0

stdob--
stdob--

Reputation: 29157

You can adding properties from maps. For example:

LOAD CSV WITH HEADERS FROM "http://data.neo4j.com/northwind/products.csv" AS row
MERGE (P:Product {productID: row.productID})
SET P += row

http://neo4j.com/docs/developer-manual/current/cypher/clauses/set/#set-adding-properties-from-maps

Upvotes: 1

Related Questions