简体   繁体   中英

HowTo create a hash index in ArangoDB via its HTTP API

I'm trying to create a hash index in ArangoDB via its HTTP API via CURL.

Within my ArangoDB I have several databases like:

  • production
  • staging
  • test

As mentioned in the docs in https://docs.arangodb.com/3.4/HTTP/Indexes/Hash.html one should call the "Index API" with an URL scheme as follows:

  • http://localhost:8529/_api/index?collection=products

Applied to my use case I have the following URL:

  • http://localhost:8529/_api/index?colletion=NodesElectric

Executing the CURL command always returns with an error like:

{  
  "error": true,
  "errorMessage": "collection or view not found",
  "code": 404,
  "errorNum": 1203
}

I suppose that the problem is caused by having the collection "NodesElectric" in all databases "production", "staging",...

My question is how do I specify the according database for the mentioned collection?

Have not found an hint in the docs herein.

Thanks for any help!

Any operation triggered via ArangoDB's HTTP REST API is executed in the context of exactly one database. To explicitly specify the database in a request, the request URI must contain the database name in front of the actual path:

http://localhost:8529/_db/mydb/ ... where ... is the actual path to the accessed resource. In the example, the resource will be accessed in the context of the database mydb. Actual URLs in the context of mydb could look like this:

http://localhost:8529/_db/mydb/_api/version

This information can be found in the documentation:

https://docs.arangodb.com/3.4/HTTP/Database/

If no database is specified in the request URL, the _system database is used by default.

To create a hash index on collection NodesElectric in your database production the following URL has to be used:

http://localhost:8529/_db/production/_api/index?collection=NodesElectric

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