MonkeyBonkey
MonkeyBonkey

Reputation: 47911

how do I create a compound index after the fact in neo4j

Can I use the power tool console in the neo4j admin to create a compound index after the objects have been created? I currently add a node than add it's "name" property to an "Apps" index. Now I also want to create a "platform" and "storeId" compound index as well. BTW, should I add that to the same Apps index or create a new index.

Upvotes: 1

Views: 595

Answers (1)

Michael Hunger
Michael Hunger

Reputation: 41706

Of course you can create new indexes and also add existing nodes through the console.

Most sensibly by executing a script fragment, see the console online manual and issue help index the console.

So either use something like this:

index -q Apps "name:*" -c cd -a $i && index -i Apps storeId

Otherwise use eval to evaluate a javascript fragment:

eval                                                   
  index=db.index().forNodes("Apps")                   
  nodes=index.query("name:*")                            
  while ( nodes.hasNext() ) {                            
     node=nodes.next()                                   
     index.add(node,"storeId",node.getProperty("storeId"))
  }

Upvotes: 1

Related Questions