Neo4j vs ElasticSearch & Full Text Search In Neo4j

Table of contents
Reading Time: 3 minutes

Hello Graphistas,

Are you missing this series 🙂 ?

Welcome back again in the series of Neo4j with Scala 😉 . Let’s start our journey again. Till now we have talked and learnt about the use of Neo4j with Scala and how easily we can integrated both two amazing technologies.

Before starting the blog here is recap :

  1. Getting Started Neo4j with Scala : An Introduction
  2. Neo4j with Scala: Defining User Defined Procedures and APOC
  3. Neo4j with Scala: Migrate Data From Other Database to Neo4j
  4. Neo4j with Scala: Awesome Experience with Spark

ElasticSearch is a modern search and analytic engine based on Apache Lucene. ElasticSearch is a full-text search engine and is highly scalable. It allows RESTful web interface and schema-free documents. ElasticSearch is able to achieve fast search responses because it searches an index instead of searching the text directly. ElasticSearch also provides the capability of store data but we shouldn’t use it as a primary database, because ES does not provide following support :

  1. Security: ES does not provide any access control and authentication.
  2. Maturity of tools: ES does not provide mature client libraries and 3rd party tools, it makes developer life much harder.
  3. Transaction: ES doesn’t provide transaction and processing for data manipulation.
  4. Long Computation: ES commands for searching data are not suited to “large” scans of data and advanced computation on the database side.
  5. Durability:
    ES is scalable and distributed but backup and durability is not high as much as in other database. You can lose your data, if you are going to make it primary database.

These are some concern areas when we are going to use ES. Neo4j provides the way to overcome from all the concern which we mention above with ES and also provides full text search with the 3.x version.

We can use cypher keywords “CONTAINS”, “STARTS WITH”, “ENDS WITH” for the full text search but it is limited to the single schema. So when we will try to use it with multiple schema we have to use “UNION” key word and have to implement multiple cypher query.

MATCH (r:Restaurant) WHERE STARTS WITH {search_term} RETURN count(*);
MATCH (c:City) WHERE CONTAINS {search_term} RETURN count(*);
MATCH (a:Address) WHERE ENDS WITH {search_term} RETURN count(*);

But this will work only for the limited schema. when you have to make full text searching on the multiples schemas, it is better to use indexes and it will be better choice to gain it. We have to make changes these changes (which mention below) in the conf file.

# Set this parameter equal to true to enable it
# A list of node property names (comma separated) that will be indexed by default.

After making changes in the conf, we have to restart the neo4j and create node.

CREATE (c:Country {country:"india"})

Now we have almost finished with the primary set-up. Now to see the whole picture we have to start the neo4j-shell and run this command.

index --get-config node_auto_index

Output :
    "provider": "lucene",
    "type": "exact"


Great, we are ready …. wait here we find “exact” so now what can we do? We run the following command to change it.

index --set-config node_auto_index type fulltext

Output :

When we run the above cypher it leads to a very specific information, what do we do here? we can simply reset the name property of each type of node we want to index to itself.

MATCH (c:Country) SET =

Now we have done with our indexing work and ready for the test the result. Run this command for the searching in neo4j :

START n=node:node_auto_index("country:*india*") RETURN n;


Here we see that how can we use neo4j for the full text search, with Neo4j we get the advantages of database with the searching.. This is a sample example on very less amount of data but we can use it on the large amount of data effectively.

I hope it will help you to set-up Full Text Search with Neo4j.

Thanks 🙂 .


Automatic Full Text Search on Neo4j3.x


Written by 

Anurag is the Sr. Software Consultant @ Knoldus Software LLP. In his 3 years of experience, he has become the developer with proven experience in architecting and developing web applications.