Create index using Gremlin

1,856 views
Skip to first unread message

Johnny Weng Luu

unread,
Feb 2, 2012, 12:38:46 AM2/2/12
to ne...@googlegroups.com
I have difficulties understanding Gremlin. I am trying to create an index.

Can't I use Java in Gremlin since it's a superset? It didn't work.

IndexManager index = graphDb.index();
Index<Node> actors = index.forNodes( "actors" );
Index<Node> movies = index.forNodes( "movies" );
RelationshipIndex roles = index.forRelationships( "roles" );

Eg. looking at the Blueprint there is a createAutomaticIndex(), but here is the result when running it:

  • gremlin> g.createAutomaticIndex('groups', Vertex.class, ['name'])
  • ==> No signature of method: groovy.lang.MissingMethodException.createAutomaticIndex() is applicable for argument types: () values: []

Johnny

Marko Rodriguez

unread,
Feb 2, 2012, 12:44:16 AM2/2/12
to ne...@googlegroups.com
Hello,

You can't pass in an Array<String>. It requires a Set<String>. Thus:

gremlin> g.createAutomaticIndex('test',Vertex.class, ['name'] as Set) ==>AUTOMATIC[test:Vertex][autoIndexKeys:[name]]

Enjoy!,
Marko.

James Thornton

unread,
Feb 2, 2012, 4:06:59 AM2/2/12
to ne...@googlegroups.com
gremlin> g.createAutomaticIndex('groups', Vertex.class, ['name'])

Hi Johnny-

That may not do what you think it's going to do.

Creating an automatic index using Vertex.class will create a global index that indexes all vertices. Therefore each new automatic index you create, even though it has a different name, will index all vertices.

If you want to create separate automatic indices for each type/model, you need to create a class for each respective type and use that class when you create the automatic index.

Here's an example on how to create and use domain-specific automatic indices...


That's one approach to automatic indices. 

But it's important to understand that Blueprints a automatic index is using a Neo4j manual index under the hood -- it's doing something like this:


Note that when you create an automatic index in Blueprints, you specify the keys when you create it. 

If keys are null, it indexes all properties. But if you specify keys to index and you add or remove a key in your domain model, you'll need to update the index.

Another approach to this would be not using the Blueprints methods and putting the logic into your Gremlin script:


- James








Johnny Weng Luu

unread,
Feb 2, 2012, 10:36:20 AM2/2/12
to ne...@googlegroups.com
I don't quite get the last method you were suggesting.

Can't I just use createManualIndex() and then manage them manually like explained here: https://github.com/tinkerpop/blueprints/wiki/Graph-Indices

Johnny

Johnny Weng Luu

unread,
Feb 2, 2012, 10:56:55 AM2/2/12
to ne...@googlegroups.com
Also I can't get https://github.com/espeed/bulbs/blob/0.3.x/bulbs/neo4jserver/gremlin.groovy#L8

How do I use the method?

As a beginner I feel this is too complicated (not to mention I'm not a Java/Groovy guy) and the documentation is very vague around this.

Instead of spending time to just code my app I have spent several hours trying to get it all, jumping between doc and mailing list.

I really second this one https://github.com/neo4j/community/issues/143 so you just create your nodes with properties and they will be auto indexed. Perhaps you could specify which index to use to index the fields? That would just solve a lot of having to understand it all beneath!

Johnny

Peter Neubauer

unread,
Feb 2, 2012, 10:59:20 AM2/2/12
to ne...@googlegroups.com
Right,
second that. Just a matter of time to get it done. Feel yourself heard!

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/

On Thu, Feb 2, 2012 at 4:56 PM, Johnny Weng Luu

Johnny Weng Luu

unread,
Feb 2, 2012, 11:04:52 AM2/2/12
to ne...@googlegroups.com
Great!

In the meanwhile I just put them all in a global automatic index for the sake of simplicity :)

Will I be able to create multiple auto indexes to index different types for example Users, Products, Organizations etc once its ready?

Johnny

Johnny Weng Luu

unread,
Feb 2, 2012, 11:06:20 AM2/2/12
to ne...@googlegroups.com
Since I rather want them in different indexes than one big index indexing all "name" fields.

Johnny Weng Luu

unread,
Feb 2, 2012, 11:31:50 AM2/2/12
to ne...@googlegroups.com
I just recall that creating an automatic index is a terrible choice since we still have the "can't find index" bug (that you fixed) in the Heroku addon :/

Johnny

Marko A. Rodriguez

unread,
Feb 2, 2012, 11:59:09 AM2/2/12
to ne...@googlegroups.com, ne...@googlegroups.com
Hi,

James' recommendation is a bit advanced. Just stick with what I stated last and you should be good to go and off and running.

Good luck Johnny,
Marko.

http://markorodriguez.com

Johnny Weng Luu

unread,
Feb 2, 2012, 12:02:46 PM2/2/12
to ne...@googlegroups.com
Mark: Yeah I did a shortcut, I'm using g.clear() and it's creating "vertices" that index everything :)

I'll stick with that for now :)

Thanks for all the help all!

Johnny

Peter Neubauer

unread,
Feb 2, 2012, 12:20:53 PM2/2/12
to ne...@googlegroups.com
No problem,
that's what makes a community!

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/

On Thu, Feb 2, 2012 at 6:02 PM, Johnny Weng Luu

James Thornton

unread,
Feb 5, 2012, 4:42:10 PM2/5/12
to ne...@googlegroups.com
Here's an example on how to create and use domain-specific automatic indices...

I just realized the example I posted was from when we were saving Gremlin scripts in Yaml files -- this won't work with bind vars. 

Here's an updated script for creating domain-specific automatic indices...


- James
Reply all
Reply to author
Forward
0 new messages