How do I create a spacial index in neo4j using only cypher? - neo4j

I want to play with neo4j and spacial indexes. I can't find any documentation that demonstrates how to do this through cypher, only through the REST API.
Is it possibly to create spacial indexes through Cypher, say in the neo4j web console?

There is currently no way to create a spatial index using Cypher. You can either use java API or a REST call, see docs at http://neo4j-contrib.github.io/spatial/#rest-api-create-a-spatial-index for details. Since Neo4j browser allows to send HTTP POST you can type there:
:POST /db/data/index/node {"name":"geom", "config":
{"provider":"spatial", "geometry_type":"point", "lat":"lat", "lon":"lon"}
}
Alternatively you can use the index command within neo4j-shell.
Update for Neo4j 3.0
Neo4j Spatial for 3.0 provides stored procedures to manage the spatial index - and therefore everything can be done through cypher. See https://github.com/neo4j-contrib/spatial/blob/master/src/main/java/org/neo4j/gis/spatial/procedures/SpatialProcedures.java.
Note: this version is not yet released, so you have to build from source yourself.

Related

Please comment on this use-case for accessing the Lucene API directly from the context of a Neo4j User Defined Procedure

I would like to build an in-memory Lucene index from a collection of node properties and then search against that index.
These search transactions will be happening in parallel, I need to be able to construct a separate search index for each transaction. It seems like this would not be possible using native (manual) Neo4j indexes, since they are "global", hence the use of a memory-based search index, am I mistaken?
This is working great for our use case. A couple of notes:
Use MemoryIndex rather than RAMDirectory.
Be sure to specify "provided" in your dependencies for Lucene.
You can only use 5.5.0, which is what is used natively by Neo4j.

Neo4j full text index

I am using node.js to connect to the neo4j database. Whenever I have to set an index for a node, I do it manually by going to the neo4j browser (localhost:7474).
CREATE INDEX ON :user(username)
First of all to be clear, this is an automatic index? Any changes or additions to :user are automatically maintained? Let me know if I am wrong.
If so, how does full text index work on neo4j? Is it the same process and neo manages automatically? For example does the following create full text index? Or we need to do something else?
CREATE INDEX ON :user(aboutme)
I built my own nodejs adapter to connect to neo4j, and so I only have access to cypher queries at the moment. To create an index I only have access to cypher or the browser (7474). So what is the proper way to create automatic fulltext index, preferably from the browser itself? And how do I access it using the cypher (or do I have to access it? does neo automatically figure out what index to use?). Online documentation and tutorials are a bit complicated for beginners :/ .
(I want to be able to do text search on the :user(aboutme) property)
If you want a full text index (where you can use the index to match on parts of the string and not the full, exact string), that isn't currently supported by the new cypher automatic indexes (like CREATE INDEX ON :user(username)). To do that you need to use what are called the legacy indexes. These use lucene under the covers and are much more powerful, but I believe they will eventually go away once that same functionality is supported with the new indexes.
Personally for full-text search I prefer using something like elasticsearch as it is easier to set up and use.

Neo4jClient: Does it support timeout parameter for executing queries?

I am using neo4j 1.9.4 community and soon will upgrade to 2.x. I know that neo4j can be configured with timeout in 2 ways as described here
But I wanna know if the second approach i.e. including max-execution-timeout in REST call header is supported by any of the Neo4jClient method so that I can pass that value as a parameter before returning my results? Also, will it be supported by future neo4j release?
The goal is to define a timeout for each query rather global setting.
Something like :
GraphClient
.Root
.StartCypher("root")
.Match("root-[:HAS]->childs")
.Return("childs")
.Results(5000) // passing timeout value in ms
At present, no, Neo4jClient doesn't have this capability.
Will it be supported? That depends on a few things, but as it's open source (https://github.com/Readify/Neo4jClient) you can always add it yourself and get it into the next release.
PS. For using against a 2.x db, you will want to look at the .Cypher so your query will look more like:
GraphClient.Cypher
.Match("root-[:HAS]->child")
.Return(child => child.As<ChildObj>())
.Results();

Caching Index with Neo4jClient

My Neo4j index has over 1.4M entries. My queries are running very slow. I have cached most of the database. However, now I have found that lot of disk read of the lucene index are taking place.
Per this article following code will help witch caching the index.
Index<Node> index = graphDb.index().forNodes( "actors" );
((LuceneIndex<Node>) index).setCacheCapacity( "name", 300000 );
Anyway I can do it via Neo4jClient? I have got so far as
var indexes = _graphClient.GetIndexes(IndexFor.Node);
var index = indexes.ElementAt(0);
But then it does not give me an option to set the cache capacity. Any thoughts how I can set the cache parameters via Neo4jClient or reduce the index look up time? TIA.
Neo4jClient works via the REST API. The behaviour you are describing is from the native Java API, and not exposed via the REST API. There is no way to do this via Neo4jClient, or any other REST based driver. You may be able to do it via config instead.

neo4j Auto indexing for a REST Server

Im trying to use auto indexing with the neo4j REST server (Community - 1.4.M04). This is in a Rails project, so im using the neography wrapper.
I couldnt find a consolidated tutorial online, from what i could follow from multiple blogs, here is what i did:
In conf/neo4j.properties:
node_keys_indexable=title,bucket_type
node_auto_indexing=true
relationship_auto_indexing=true
After that, using a rails console:
neo = Neography::Rest.new
neo.create_node_index("node_auto_index", "fulltext", "lucene")
I can see the index in the webadmin, but querying data:
localhost:7474/db/data/index/node/node_auto_index/name/test_name
does not return any data.
Any help would be much appreciated.
Adding an index doesn't add older data to the index. This has to be done manually.

Resources