Over a million developers have joined DZone.

Enabling Legacy Automatic Full-Text Search on Neo4j 3.X

DZone's Guide to

Enabling Legacy Automatic Full-Text Search on Neo4j 3.X

Wouldn't it be great to search one index that covers multiple models? See how some buried configuration settings can be tuned to let you cover more ground in Neo4j.

· Database Zone
Free Resource

Finding a database that fits with a container-based deployment model can be frustrating. Learn what to look for in a Docker database

Image title

Neo4j 3.x has made inroads toward full-text search capabilities using some Cypher keywords, like “STARTS WITH”, “ENDS WITH”, and “CONTAINS”. However, this search capability is limited to a single schema index and can be a problem when you need a very flexible search interface. To search across multiple models, you can use this trick:

MATCH (n:Person) WHERE n.name CONTAINS {search_term} RETURN n
MATCH (n:Place) WHERE n.name CONTAINS {search_term} RETURN n
MATCH (n:Thing) WHERE n.name CONTAINS {search_term} RETURN n

This works out OK when dealing with just a few models, but let’s say we have to search across 10? That’s 10 separate search queries. Wouldn’t it be nice if you could just search one index and avoid the overhead? Well yes Virginia, there really is a Santa Claus. He comes in the form of the badly named “Legacy Indexes,” specifically the “node_auto_index”. To enable this feature, you have to edit your neo4j.conf file and add these lines:

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

Now, once you restart the server, the index won’t be created just yet. You first have to set an indexable property, and then the index will be created. So, for example, we can create a node with a name property.

CREATE (p:Place {name:"Chicago"})

Now, if we start the Neo4j shell ( /bin/neo4j-shell ), we can run this command to see our node auto index.

index --get-config node_auto_index

The result we get is:

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

So great, the index was created, but it’s “exact” — not what we want. So, we need to issue this command to change it:

index --set-config node_auto_index type fulltext

This command leads to a very helpful message:


So, what do we do here? Well, we can simply reset the name property of each type of node we want to index to itself.

MATCH (p:Person) SET p.name = p.name

Now we are able to perform a full text search query using the “legacy” START clause:

START n=node:node_auto_index("name:*m*") RETURN n;

That’s it. One single index to rule them all.

When you're looking for a SQL database that can scale elastically, while still preserving ACID guarantees, you only have a few choices. Find out how these elastic SQL databases perform in thishead-to-head YCSB benchmark.

database ,neo4j ,cypher ,data model

Published at DZone with permission of Max De Marzi, DZone MVB. See the original article here.

Opinions expressed by DZone contributors are their own.

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}