Indexing in Spring Data Neo4j

Posted By : Abhay Garg | 12-Mar-2015

Indexing -> Indexing is used in Neo4j to quickly find nodes and relationships to start graph operations from Schema (Label based) Indexing .

 

STEP 1  Create Index  -> You can use either of them 

 

Using Cypher-> By using Cypher you can create index with this Cypher Query 

                   CREATE INDEX ON :Person(name);

 Using Spring Data Neo4j

import org.springframework.data.neo4j.annotation.Indexed
import org.springframework.data.neo4j.annotation.NodeEntity

@NodeEntit
class Person{
@Indexed
String name
}

So it creates schema Indexing on Person Domain at name property.

 

STEP 2  Use Index -> In cypher you can find Data like match (person:Person) where person.name="oodles" return person .

So now you can get data in O(1) , otherwise it will search on all Person Nodes.

 

Legacy Indexing in Neo4j -> The default index implementation is provided by the neo4j-lucene-index. So you can use lucene Query to get the Data . 

 

STEP 1  Create Index -> In Spring Data Neo4j 


import org.springframework.data.neo4j.support.index.IndexType
import org.springframework.data.neo4j.annotation.Indexed
import org.springframework.data.neo4j.annotation.NodeEntity

@NodeEntity

class Job{
@Indexed
String name
@Indexed(indexName = jobSearch, indexType=IndexType.FULLTEXT,numeric=false)
String publishDate
}
STEP 2  Use Index -> In cypher you can find Data like ,
 
START jobWithDate=node:jobSearch("publishDate:[2015-03-18T18:30:00.000Z TO 2015-03-18T18:30:00.000Z]")  match (jobWithDate) where jobWithDate.name="oodles" return jobWithDate.
 
So Indexing helps to filter on specific Nodes otherwise it filter from all Nodes .
 
NOTE -> Please note that the lucene based manual indexes are deprecated with Neo4j 2.0 and Spring Data Neo4j 3.0. The default index is now based on labels and schema indexes and the related old APIs have been deprecated as well. The "legacy" index framework should only be used for fulltext and spatial indexes which are not currently supported via schema based indexes.

For More information visit this  link

THANKS

 

About Author

Author Image
Abhay Garg

Abhay is a Grails Developer expertise in OptaPlanner and Angular js framework.

Request for Proposal

Name is required

Comment is required

Sending message..