Hi Guys,
I am currently working on a project to migrate one of our java applications from Neo4j embedded 2.3.8 to 5.21. I am referring the below link for my migration. However, I am stuck with creating indexes for node and relationship with multiple properties. Currently my application creates index for a node definition or a relationship definition, which will be applicable for all properties within it. However, I am not finding any sources to create such composite indexes in Neo4j 5.21. Can you please guide and provide details to achieve the same in latest Neo4j would be really helpful to complete my project.
Node Index: will be created for definition "BOARDS "
Definition BOARDS = definition(Board.class);
Keyword<String> BOARD_NAME = keyword("board_name", String.class);
Keyword<BoardId> BOARD_ID = keyword("board_id", BoardId.class);
Create Node Index for definition "BOARDS ":
index = graphDatabaseService.index().forNodes(definition.name());
Insert node using index:
node.setProperty(keyword.name(), value);
index.add(node, keyword.name(), value);
Query node using index:
Query query = lucene.query(predicate);
return index.query(query);
Relationship index: will be created for definition "STOPS_AT"
Definition STOPS_AT = definition(StopsAt.class);
Keyword<Integer> SEQUENCE_ID = keyword("seq", Integer.class);
Keyword<TripId> TRIP_ID = keyword("trip_id", TripId.class);
RelationshipType RELATIONSHIP = DynamicRelationshipType.withName("stops_at");
index = graphDatabaseService.index().forRelationships(definition.name());
[Embedding Neo4j in your Java application - Java Reference] (Embedding Neo4j in your Java application - Java Reference)
[Using indexes - Java Reference (neo4j.com)] (Using indexes - Java Reference)
Regards,
Vijay
Your last link has an example of creating an index. The property is specified with the ‘on’ method on the IndexCreator class. Looking at the ‘on’ method’s description, you will notice a note that states presently only one property is supported.
Interestingly there is a method defined in the IndexDefinition interface called isCompositeIndex that tells you if the index is a composite one. I guess composite indexed are on the roadmap.
Thanks for your input. Is there a migration guide from neo4j embedded 2.3 to 5.21?
I don't think there's an official migration path from a version that old since there are so many major features since then.....however, I think you'd want something like this: 2.3 -> 3.0 or 3.5 -> 4.0 -> 4.4 -> 5.0 -> 5.21. You can follow some documentation here: Neo4j 4 upgrades and migration - Upgrade and Migration Guide. Then there is a tab along the left menu for going to Neo4j 5 after you get to 4.
It's a lot of steps, but this would lower the risk of data corruption issues. We added new property types in 3.4, multi-db and architecture changes to 4.0, further indexes and vector indexes to 5 and many other things in between.
Thank you so much for your inputs.
Can you please guide me how to convert Result (org.neo4j.graphdb.Result) object to Nodes (org.neo4j.graphdb.Node). I am trying to get all nodes that have the destination stop name. I need to convert Result to Nodes and in turn the Nodes to Entities (org.neo4j.graphdb.Entity). Can you please help.
Result result = tx.execute(nodeStopNameExactMatchQuery(destinationStop).toString());
public static Query nodeStopNameExactMatchQuery(StopName stopName) {
return new TermQuery(new Term(GraphNode.LONG_NAME.name(), stopName.value()));
}
Are you using plain Java (not a framework like Spring)? If just via Java driver, then you can add the Object-Graph Mapping (OGM) library. Neo4j - OGM Object Graph Mapper - Getting Started
Are you using the Java driver to query against a hosted db, or the Java api in an embedded environment or custom procedure?
Can you provide the actual Java code you wrote that is causing the error?