- Create node index
- Create node index with configuration
- Delete node index
- List node indexes
- Add node to index
- Remove all entries with a given node from an index
- Remove all entries with a given node and key from an index
- Remove all entries with a given node, key and value from an index
- Find node by exact match
- Find node by query
Note This documents the legacy indexing in Neo4j, which is no longer the preferred way to handle indexes. Consider looking at Section 20.15, “Indexing”. |
An index can contain either nodes or relationships.
Note To create an index with default configuration, simply start using it by adding nodes/relationships to it. It will then be automatically created for you. |
What default configuration means depends on how you have configured your database. If you haven’t changed any indexing configuration, it means the indexes will be using a Lucene-based backend.
All the examples below show you how to do operations on node indexes, but all of them are just as applicable to relationship indexes. Simple change the "node" part of the URL to "relationship".
If you want to customize the index settings, see the section called “Create node index with configuration”.
Create node index
Note Instead of creating the index this way, you can simply start to use it, and it will be created automatically with default configuration. |
Example request
-
POST
http://localhost:7474/db/data/index/node/
-
Accept:
application/json; charset=UTF-8
-
Content-Type:
application/json
{ "name" : "index_1465360152109_1" }
Example response
-
201:
Created
-
Content-Type:
application/json; charset=UTF-8
-
Location:
http://localhost:7474/db/data/index/node/index_1465360152109_1/
{ "template" : "http://localhost:7474/db/data/index/node/index_1465360152109_1/{key}/{value}" }
Create node index with configuration
This request is only necessary if you want to customize the index settings. If you are happy with the defaults, you can just start indexing nodes/relationships, as non-existent indexes will automatically be created as you do. See Section 34.10, “Configuration and fulltext indexes” for more information on index configuration.
Example request
-
POST
http://localhost:7474/db/data/index/node/
-
Accept:
application/json; charset=UTF-8
-
Content-Type:
application/json
{ "name" : "fulltext", "config" : { "type" : "fulltext", "provider" : "lucene" } }
Example response
-
201:
Created
-
Content-Type:
application/json; charset=UTF-8
-
Location:
http://localhost:7474/db/data/index/node/fulltext/
{ "template" : "http://localhost:7474/db/data/index/node/fulltext/{key}/{value}", "type" : "fulltext", "provider" : "lucene" }
Delete node index
Example request
-
DELETE
http://localhost:7474/db/data/index/node/index_1465360150696_1
-
Accept:
application/json; charset=UTF-8
Example response
-
204:
No Content
List node indexes
Example request
-
GET
http://localhost:7474/db/data/index/node/
-
Accept:
application/json; charset=UTF-8
Example response
-
200:
OK
-
Content-Type:
application/json; charset=UTF-8
{ "index_1465360150178_1" : { "template" : "http://localhost:7474/db/data/index/node/index_1465360150178_1/{key}/{value}", "provider" : "lucene", "type" : "exact" }, "index_1465360150426_1" : { "template" : "http://localhost:7474/db/data/index/node/index_1465360150426_1/{key}/{value}", "provider" : "lucene", "type" : "exact" }, "index_1465360150854_1" : { "template" : "http://localhost:7474/db/data/index/node/index_1465360150854_1/{key}/{value}", "provider" : "lucene", "type" : "exact" }, "index_1465360150194_1" : { "template" : "http://localhost:7474/db/data/index/node/index_1465360150194_1/{key}/{value}", "provider" : "lucene", "type" : "exact" }, "index_1465360149597_1" : { "template" : "http://localhost:7474/db/data/index/node/index_1465360149597_1/{key}/{value}", "provider" : "lucene", "type" : "exact" }, "index_1465360149755_1" : { "template" : "http://localhost:7474/db/data/index/node/index_1465360149755_1/{key}/{value}", "provider" : "lucene", "type" : "exact" }, "index_1465360150510_1" : { "template" : "http://localhost:7474/db/data/index/node/index_1465360150510_1/{key}/{value}", "provider" : "lucene", "type" : "exact" }, "index_1465360150300_1" : { "template" : "http://localhost:7474/db/data/index/node/index_1465360150300_1/{key}/{value}", "provider" : "lucene", "type" : "exact" }, "index_1465360149680_1" : { "template" : "http://localhost:7474/db/data/index/node/index_1465360149680_1/{key}/{value}", "provider" : "lucene", "type" : "exact" }, "index_1465360149691_1" : { "template" : "http://localhost:7474/db/data/index/node/index_1465360149691_1/{key}/{value}", "provider" : "lucene", "type" : "exact" }, "index_1465360150097_1" : { "template" : "http://localhost:7474/db/data/index/node/index_1465360150097_1/{key}/{value}", "provider" : "lucene", "type" : "exact" }, "index_1465360150976_1" : { "template" : "http://localhost:7474/db/data/index/node/index_1465360150976_1/{key}/{value}", "provider" : "lucene", "type" : "exact" }, "index_1465360150770_1" : { "template" : "http://localhost:7474/db/data/index/node/index_1465360150770_1/{key}/{value}", "provider" : "lucene", "type" : "exact" }, "index_1465360150983_1" : { "template" : "http://localhost:7474/db/data/index/node/index_1465360150983_1/{key}/{value}", "provider" : "lucene", "type" : "exact" } }
Add node to index
Associates a node with the given key/value pair in the given index.
Note Spaces in the URI have to be encoded as |
Caution This does not overwrite previous entries. If you index the same key/value/item combination twice, two index entries are created. To do update-type operations, you need to delete the old entry before adding a new one. |
Example request
-
POST
http://localhost:7474/db/data/index/node/index_1465360150194_1
-
Accept:
application/json; charset=UTF-8
-
Content-Type:
application/json
{ "value" : "some value", "uri" : "http://localhost:7474/db/data/node/7", "key" : "some-key" }
Example response
-
201:
Created
-
Content-Type:
application/json; charset=UTF-8
-
Location:
http://localhost:7474/db/data/index/node/index_1465360150194_1/some-key/some%20value/7
{ "extensions" : { }, "metadata" : { "id" : 7, "labels" : [ ] }, "paged_traverse" : "http://localhost:7474/db/data/node/7/paged/traverse/{returnType}{?pageSize,leaseTime}", "outgoing_relationships" : "http://localhost:7474/db/data/node/7/relationships/out", "outgoing_typed_relationships" : "http://localhost:7474/db/data/node/7/relationships/out/{-list|&|types}", "create_relationship" : "http://localhost:7474/db/data/node/7/relationships", "labels" : "http://localhost:7474/db/data/node/7/labels", "traverse" : "http://localhost:7474/db/data/node/7/traverse/{returnType}", "all_relationships" : "http://localhost:7474/db/data/node/7/relationships/all", "all_typed_relationships" : "http://localhost:7474/db/data/node/7/relationships/all/{-list|&|types}", "property" : "http://localhost:7474/db/data/node/7/properties/{key}", "self" : "http://localhost:7474/db/data/node/7", "incoming_relationships" : "http://localhost:7474/db/data/node/7/relationships/in", "properties" : "http://localhost:7474/db/data/node/7/properties", "incoming_typed_relationships" : "http://localhost:7474/db/data/node/7/relationships/in/{-list|&|types}", "data" : { }, "indexed" : "http://localhost:7474/db/data/index/node/index_1465360150194_1/some-key/some%20value/7" }
Remove all entries with a given node from an index
Example request
-
DELETE
http://localhost:7474/db/data/index/node/index_1465360150854_1/12
-
Accept:
application/json; charset=UTF-8
Example response
-
204:
No Content
Remove all entries with a given node and key from an index
Example request
-
DELETE
http://localhost:7474/db/data/index/node/index_1465360151354_1/kvkey2/15
-
Accept:
application/json; charset=UTF-8
Example response
-
204:
No Content
Remove all entries with a given node, key and value from an index
Example request
-
DELETE
http://localhost:7474/db/data/index/node/index_1465360150300_1/kvkey1/value1/8
-
Accept:
application/json; charset=UTF-8
Example response
-
204:
No Content
Find node by exact match
Note Spaces in the URI have to be encoded as |
Example request
-
GET
http://localhost:7474/db/data/index/node/index_1465360152000_1/key/the%2520value
-
Accept:
application/json; charset=UTF-8
Example response
-
200:
OK
-
Content-Type:
application/json; charset=UTF-8
[ { "metadata" : { "id" : 23, "labels" : [ ] }, "data" : { }, "indexed" : "http://localhost:7474/db/data/index/node/index_1465360152000_1/key/the%2520value/23", "paged_traverse" : "http://localhost:7474/db/data/node/23/paged/traverse/{returnType}{?pageSize,leaseTime}", "outgoing_relationships" : "http://localhost:7474/db/data/node/23/relationships/out", "outgoing_typed_relationships" : "http://localhost:7474/db/data/node/23/relationships/out/{-list|&|types}", "create_relationship" : "http://localhost:7474/db/data/node/23/relationships", "labels" : "http://localhost:7474/db/data/node/23/labels", "traverse" : "http://localhost:7474/db/data/node/23/traverse/{returnType}", "extensions" : { }, "all_relationships" : "http://localhost:7474/db/data/node/23/relationships/all", "all_typed_relationships" : "http://localhost:7474/db/data/node/23/relationships/all/{-list|&|types}", "property" : "http://localhost:7474/db/data/node/23/properties/{key}", "self" : "http://localhost:7474/db/data/node/23", "incoming_relationships" : "http://localhost:7474/db/data/node/23/relationships/in", "properties" : "http://localhost:7474/db/data/node/23/properties", "incoming_typed_relationships" : "http://localhost:7474/db/data/node/23/relationships/in/{-list|&|types}" } ]
Find node by query
The query language used here depends on what type of index you are querying. The default index type is Lucene, in which case you should use the Lucene query language here. Below an example of a fuzzy search over multiple keys.
Getting the results with a predefined ordering requires adding the parameter
order=ordering
where ordering is one of index, relevance or score. In this case an additional field will be added to each result, named score, that holds the float value that is the score reported by the query result.
Example request
-
GET
http://localhost:7474/db/data/index/node/index_1465360151905_1?query=Name:Build~0.1%20AND%20Gender:Male
-
Accept:
application/json; charset=UTF-8
Example response
-
200:
OK
-
Content-Type:
application/json; charset=UTF-8
[ { "metadata" : { "id" : 22, "labels" : [ ] }, "data" : { "Name" : "Builder" }, "paged_traverse" : "http://localhost:7474/db/data/node/22/paged/traverse/{returnType}{?pageSize,leaseTime}", "outgoing_relationships" : "http://localhost:7474/db/data/node/22/relationships/out", "outgoing_typed_relationships" : "http://localhost:7474/db/data/node/22/relationships/out/{-list|&|types}", "create_relationship" : "http://localhost:7474/db/data/node/22/relationships", "labels" : "http://localhost:7474/db/data/node/22/labels", "traverse" : "http://localhost:7474/db/data/node/22/traverse/{returnType}", "extensions" : { }, "all_relationships" : "http://localhost:7474/db/data/node/22/relationships/all", "all_typed_relationships" : "http://localhost:7474/db/data/node/22/relationships/all/{-list|&|types}", "property" : "http://localhost:7474/db/data/node/22/properties/{key}", "self" : "http://localhost:7474/db/data/node/22", "incoming_relationships" : "http://localhost:7474/db/data/node/22/relationships/in", "properties" : "http://localhost:7474/db/data/node/22/properties", "incoming_typed_relationships" : "http://localhost:7474/db/data/node/22/relationships/in/{-list|&|types}" } ]