user3156112
user3156112

Reputation: 1

Create Index - REST API doesn't work, but Cypher Query does?

Follownig the instructions in the user manual, I am trying to create an Index on a label:

POST

http://localhost:7474/db/data/schema/index/person

{
"property_keys" : [ "name" ]
}

I keep getting the following error back: 406 Not Acceptable

But if I try the same using the Cypher Query example from neo4j browser, it works just fine:

CREATE INDEX ON :Person(name)

The same is happening with Constraints.

Any ideas as to what is the issue? Or if I am doing something wrong?

regards, -Piyush

Upvotes: 0

Views: 218

Answers (2)

Roy
Roy

Reputation: 1

Here is an example using curl:

curl -i -u neo4j:password -H "accept:application/json" -H "Content-Type:application/json; charset=UTF-8" -X POST -d '{ "property_keys" : [ "id" ] }' http://localhost:7474/db/data/schema/index/entities

Had some trouble getting it right myself so thought it should be here.

Upvotes: 0

Stefan Armbruster
Stefan Armbruster

Reputation: 39926

Using 'httpie' (a more comfortable variant for cURL) createing a schema index works fine as expected:

$ http -v -j http://localhost:7474/db/data/schema/index/person property_keys=["name"]
POST /db/data/schema/index/person HTTP/1.1
Accept: application/json
Accept-Encoding: gzip, deflate, compress
Content-Length: 27
Content-Type: application/json; charset=utf-8
Host: localhost:7474
User-Agent: HTTPie/0.7.2

{
    "property_keys": "[name]"
}

HTTP/1.1 200 OK
Access-Control-Allow-Origin: *
Content-Length: 58
Content-Type: application/json; charset=UTF-8
Server: Jetty(9.0.5.v20130815)

{
    "label": "person", 
    "property_keys": [
        "[name]"
    ]
}

Please doublecheck:

  1. are you using the right version of Neo4j? 2.0.0 is required for schema indexes?
  2. are you using the correct Http request headers for Accept and Content-Type? Using application/json is crucial.

Upvotes: 1

Related Questions