Puneet
Puneet

Reputation: 91

Adding index on neo4j node property value

I have imported freebase dump to neo4j. But currently i am facing issue with get queries because of size of db. While import i just created node index and indexed URI property to index for each node. For each node i am adding multiple properties like label_en, type_content_type_en.

props.put(URI_PROPERTY, subject.stringValue());

Long subjectNode = db.createNode(props);

tmpIndex.put(subject.stringValue(), subjectNode);

nodeIndex.add(subjectNode, props);

Now my cypher queries are like this. Which are timing out. I am unable to add index on label_en property. Can anybody help?

match (n)-[r*0..1]->(a) where n.label_en=~'Hibernate.*' return n, a

Update

BatchInserter db = BatchInserters.inserter("ttl.db", config);
BatchInserterIndexProvider indexProvider = new LuceneBatchInserterIndexProvider(db);
BatchInserterIndex index = indexProvider.nodeIndex("ttlIndex", MapUtil.stringMap("type", "exact"));

Question: When i have added node in nodeindex i have added with property URI

props.put(URI_PROPERTY, subject.stringValue());
Long subjectNode = db.createNode(props);
nodeIndex.add(subjectNode, props);

Later in code i have added another property to node(Named as label_en). But I have not added or updated nodeindex. So as per my understanding lucene does not have label_en property indexed. My graph is already built so i am trying to add index on label_en property of my node because my query is on label_en.

Upvotes: 0

Views: 321

Answers (1)

FrobberOfBits
FrobberOfBits

Reputation: 18002

Your code sample is missing how you created your index. But I'm pretty sure what you're doing is using a legacy index, which is based on Apache Lucene.

Your Cypher query is using the regex operator =~. That's not how you use a legacy index; this seems to be forcing cypher to ignore the legacy index, and have the java layer run that regex on every possible value of the label_en property.

Instead, with Cypher you should use a START clause and use the legacy indexing query language.

For you, that would look something like this:

START n=node:my_index_name("label_en:Hibernate.*")
MATCH (n)-[r*0..1]->(a)
RETURN n, a;

Notice the string label_en:Hibernate.* - that's a Lucene query string that says to check that property name for that particular string. Cypher/neo4j is not interpreting that; it's passing it through to Lucene.

Your code didn't provide the name of your index. You'll have to change my_index_name above to whatever you named it when you created the legacy index.

Upvotes: 1

Related Questions