Take the 2-minute tour ×

I am using Gremlin and Neo4j to manipulate the ENRON dataset from infochimps. This dataset has two types of vertexes, Message and Email Addresss and two types of edges, SENT and RECEVIED_BY. I would like to create a custom index on this dataset that creates a Lucene document for each vertex of type: 'Message' and incorporates information from associated vertexes (e.g., v.in(), v.out()) as additional fields in the Lucene document.

I am thinking of code along the lines of

g = new Neo4jGraph('enron');

PerFieldAnalyzerWrapper analyzer =
    new PerFieldAnalyzerWrapper(new StandardAnalyzer());
analyzer.addAnalyzer("sender", new KeywordAnalyzer());
analyzer.addAnalyzer("recipient", new KeywordAnalyzer());

IndexWriter idx = new IndexWriter (dir,analyzer,IndexWriter.MaxFieldLength.UNLIMITED);

g.V.filter{it.type == 'Message'}.each { v ->
    Document doc = new Document();
    doc.add(new Field("subject", v.subject));
    doc.add(new Field("body", v.body));
    doc.add(new Field("sender", v.in().address);
    v.out().each { recipient -> 
        doc.add(new Field("recipient", recipient.address));

My questions are:

  1. Is there a better way to enumerate vertexes for indexing?
  2. Can I use auto-indexing for this, and if so, how to I specify what should be indexed?
  3. Can I specify my own Analyzer, or am I stuck with the default? What is the default?
  4. If I must create my own index, should I be using gremlin for this, or am I better off with a Java program?
share|improve this question
Did you manage to solve this? I'm facing the same issues... (specifically, i'm concerned about bullets 1 & 2 in your question). –  royv May 8 '13 at 22:29
add comment

1 Answer

I will be talking about direct Neo4j access here since I'm not well travelled in Gremlin.

So you'd like to build a Lucene index "outside of" the graph itself? Otherwise you can use the built in graphDb.index().forNodes( "myIndex", configForMyIndex ) to get (created on demand) a Lucene index associated with neo4j. You can then add multiple fields to each document by calling index.add( node, key, value ), where each node will be represented by one document in that Lucene index.

1) In Gremiln... I don't know

2) See http://docs.neo4j.org/chunked/milestone/auto-indexing.html

3) See http://docs.neo4j.org/chunked/milestone/indexing-create-advanced.html

4) Do you need to create it outside of the db entirely? If so, why?

share|improve this answer
I had seen that example, but it doesn't allow me to specify analyzers. See the comments at the bottom of the page on advanced indexing (second link above). –  Gene Golovchinsky Oct 25 '12 at 15:41
add comment

Your Answer


