简体   繁体   中英

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

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.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM