简体   繁体   中英

Create single-property indexes on a loop in cypher

Is it possible to do something like this in cypher?

WITH ["John", "Jane"] AS names
FOREACH (name IN names | CREATE INDEX ON :Person(name))

If not, is there any APOC alternative to achieve the same?

Thanks!

Note:

I am using Neo4j 3.5

What exactly are you trying to do?

You can create John and Jane like this (see the docs on UNWIND )

WITH ['John','Jane'] AS names
UNWIND names AS name
CREATE (p:Person {name:name})
RETURN p

But when you create an index, you create an index for a property on all Nodes of that type. So to index "name" you only need (see docs on INDEX ):

CREATE INDEX ON :Person(name)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM