The best way to delete all indices() with Neo4j API?

1,749 views
Skip to first unread message

Johnny Weng Luu

unread,
Feb 8, 2012, 8:36:18 PM2/8/12
to ne...@googlegroups.com
What's the best way to delete all indices with Neo4j API?

Johnny

Peter Neubauer

unread,
Feb 9, 2012, 3:44:08 AM2/9/12
to ne...@googlegroups.com
Johnny,
you would iterate over the indexes and delete them, something like
this (taken from a testcase):

for ( String indexName : server.getDatabase().graph.index()
.nodeIndexNames() )
{
try{
server.getDatabase().graph.index()
.forNodes( indexName )
.delete();
} catch(UnsupportedOperationException e) {
// Encountered a read-only index.
}
}

for ( String indexName : server.getDatabase().graph.index()
.relationshipIndexNames() )
{
try {
server.getDatabase().graph.index()
.forRelationships( indexName )
.delete();
} catch(UnsupportedOperationException e) {
// Encountered a read-only index.
}
}

Cheers,

/peter neubauer

G:  neubauer.peter
S:  peter.neubauer
P:  +46 704 106975
L:   http://www.linkedin.com/in/neubauer
T:   @peterneubauer

Neo4j 1.6 released                 - dzone.com/6S4K
The Neo4j Heroku Challenge   - http://neo4j-challenge.herokuapp.com/

James Thornton

unread,
Feb 9, 2012, 7:05:36 AM2/9/12
to ne...@googlegroups.com
> What's the best way to delete all indices with Neo4j API?

neo4j = g.getRawGraph()
manager = neo4j.index()
manager.nodeIndexNames().each{ g.dropIndex( it ) }
manager.relationshipIndexNames().each{  g.dropIndex( it )  }

- James

Johnny Weng Luu

unread,
Feb 9, 2012, 8:15:29 AM2/9/12
to ne...@googlegroups.com
Didn't know that Neo4j API could use Gremlin API.

This looks simpler than native Neo4j API.

Johnny

Peter Neubauer

unread,
Feb 9, 2012, 8:16:50 AM2/9/12
to ne...@googlegroups.com
This IS the Neo4j API, but in Groovy :)

Cheers,

/peter neubauer

G:  neubauer.peter
S:  peter.neubauer
P:  +46 704 106975
L:   http://www.linkedin.com/in/neubauer
T:   @peterneubauer

Neo4j 1.6 released                 - dzone.com/6S4K
The Neo4j Heroku Challenge   - http://neo4j-challenge.herokuapp.com/

Johnny Weng Luu

unread,
Feb 9, 2012, 8:19:57 AM2/9/12
to ne...@googlegroups.com
Right. Forgot I am still using Groovy since I am using the Gremlin plugin.

Haha. This whole Java world is so new to me. But I kinda begin to like it more than Cypher since it's an imperative API. Gives more power and you can do whatever you want.

Cypher under the hood is just using Neo4j API right? Or is it using Gremlin/Blueprint as well?

Johnny

Andres Taylor

unread,
Feb 9, 2012, 8:24:45 AM2/9/12
to ne...@googlegroups.com
On Thu, Feb 9, 2012 at 2:19 PM, Johnny Weng Luu <johnny....@gmail.com> wrote:
Cypher under the hood is just using Neo4j API right? Or is it using Gremlin/Blueprint as well?

Cypher is a Neo4j-only thing. For now...

Andrés 

Michael Hunger

unread,
Feb 9, 2012, 8:25:10 AM2/9/12
to ne...@googlegroups.com
Imperative code makes it harder to understand and to reason about.
If you show a someone who knows the domain a cypher query they can understand it. If you show them gremlin code, they don't.

Groovy syntax is much closer to Ruby than Java. 
So you can program against the Neo4j Core API in Groovy the same way you can in Java (just more concise and expressive).
Blueprints is just a convenience layer on top of that. And Gremlin a DSL to set up a set of connected Tinkerpop Pipes.

Cypher uses the Neo4j API, yes, so nothing in between.

Cheers

Michael

James Thornton

unread,
Feb 9, 2012, 8:31:07 AM2/9/12
to ne...@googlegroups.com


On Thursday, February 9, 2012 7:15:29 AM UTC-6, Johnny Weng Luu wrote:
Didn't know that Neo4j API could use Gremlin API.

This looks simpler than native Neo4j API.


This is a perfect example for when you would want to use a Blueprints Java method that encapsulates several steps, rather than writing it out in Groovy -- it will be faster and easier to read.

Look at the Blueprints dropIndex() method:


It's basically the same code that it's in testcase above, but it's wrapped nicely in a single method. 

The only reason you can't use the Blueprints getIndices() method in this case...


...which returns all indices for both nodes and relationships, is because I presume you are trying to delete Neo4j fulltext indices, which don't get returned by the Blueprints method because Blueprints doesn't support them.

- James


Johnny Weng Luu

unread,
Feb 9, 2012, 8:36:58 AM2/9/12
to ne...@googlegroups.com
All this information you have been giving me here in the mailing list is so valuable.

It would be helpful for a lot of people if you put all this into the documentation so they will get the picture of the relations between all the different techs.

And describe why there are a lot of different techs. It's a huge ecosystem compared to other dbs and beginners could be very lost.

Johnny

James Thornton

unread,
Feb 9, 2012, 8:47:18 AM2/9/12
to ne...@googlegroups.com
If you show a someone who knows the domain a cypher query they can understand it. If you show them gremlin code, they don't.

I think the Gremlin one-lines scare some people off...

products = g.idx('vertices')[[name: 'Foo']].as('products').out('parent').filter(it.name == 'Bar').back('products').iterate()

It would probably help to write Gremlin in a more traditional style, which is self-documenting and thus easier to read...

start = g.idx('vertices')[[name: 'Foo']].as('products')
parent = start.out('parent').filter(it.name == 'Bar')
products = parent.back('products').iterate()

- James


Johnny Weng Luu

unread,
Feb 9, 2012, 8:51:20 AM2/9/12
to ne...@googlegroups.com
I love one liners if I don't have to use any intermediate variable.

But yeah, dividing them into different lines could help the eyes.

I love Cypher btw. Just that I think I will always have to drop down to native for parts Cypher doesn't deal with.

I rather learn and use one tech than having to switch context. I hope that JavaScript plugin will be feature rich so I can use JavaScript instead of Java though.

And only developers will read/write the code so no need for other people to get the queries. But it's a nice approach of Cypher to make it human-readable. That's innovation!

Johnny

James Thornton

unread,
Feb 9, 2012, 8:54:26 AM2/9/12
to ne...@googlegroups.com

On Thursday, February 9, 2012 7:36:58 AM UTC-6, Johnny Weng Luu wrote:
All this information you have been giving me here in the mailing list is so valuable.

It would be helpful for a lot of people if you put all this into the documentation so they will get the picture of the relations between all the different techs.

And describe why there are a lot of different techs. It's a huge ecosystem compared to other dbs and beginners could be very lost.


Thanks Johhny. I'm working on setting a blog up and writing documentation at http://bulbflow.com -- right now it's still the old Bulbs 0.2 docs, but the new docs will cover Bulbs 0.3, Neo4j, Blueprints, Gremlin, and graph databases in general. 

- James


 

Johnny Weng Luu

unread,
Feb 9, 2012, 8:57:54 AM2/9/12
to ne...@googlegroups.com
Cool, link saved :)

Johnny
Reply all
Reply to author
Forward
0 new messages