mirror of https://gitee.com/bigwinds/arangodb
196 lines
8.2 KiB
HTML
196 lines
8.2 KiB
HTML
<html><head><title>ArangoDB Manual</title> <style media="screen" type="text/css" style="display:none">body{background-color:white;font:13px Helvetica,arial,freesans,clean,sans-serif;line-height:1.4;color:#333;}#access{font-size:16px;margin-left:12px;display:block;margin-left:10px;margin-right:10px;background-color:#F3F1EE!important;}#access a{border-right:1px solid #DBDEDF;color:#A49F96;display:block;line-height:38px;padding:0 10px;text-decoration:none;}#navigation ul{text-transform:uppercase;list-style:none;margin:0;}#navigation li{float:left;position:relative;}#container{width:920px;margin:0 auto;}a{color:#4183C4;text-decoration:none;}.contents h2{font-size:24px;border-bottom:1px solid #CCC;color:black;}.contents h1{font-size:33px;border-bottom:1px solid #CCC;color:black;}.clearfix:after{content:".";display:block;clear:both;font-size:0;height:0;visibility:hidden;}/**/ *:first-child+html .clearfix{min-height:0;}/**/ * html .clearfix{height:1%;}</style></head><body><div id="container"><img src="images/logo_arangodb.png" width="397" height="67" alt="ArangoDB"><div id="access" role="navigation"><div id="navigation"><ul id="menu-ahome" class="menu"><li><a href="Home.html">Table of contents</a></li> <li><a href="http://www.arangodb.org">ArangoDB homepage</a></li></ul></div><div class="clearfix"></div></div><div>
|
|
<!-- Generated by Doxygen 1.7.5.1 -->
|
|
</div>
|
|
<div class="header">
|
|
<div class="headertitle">
|
|
<h1>Accessing Hash Indexes via Http </h1> </div>
|
|
</div>
|
|
<div class="contents">
|
|
<div class="textblock"><p>If a suitable hash index exists, then <a class="el" href="HttpSimple.html#HttpSimpleByExample">/_api/simple/by-example</a> will use this index to execute a query-by-example.</p>
|
|
<hr/>
|
|
<ul>
|
|
<li>
|
|
<a class="el" href="IndexHashHttp.html">Accessing Hash Indexes via Http</a> <ul>
|
|
<li>
|
|
<a class="el" href="IndexHashHttp.html#IndexHashHttpEnsureHash">POST /_api/index</a> </li>
|
|
<li>
|
|
<a class="el" href="IndexHashHttp.html#IndexHashHttpByExample">POST /_api/simple/by-example</a> </li>
|
|
<li>
|
|
<a class="el" href="IndexHashHttp.html#IndexHashHttpFirstExample">POST /_api/simple/first-example</a> </li>
|
|
</ul>
|
|
</li>
|
|
</ul>
|
|
<hr/>
|
|
<a class="anchor" id="IndexHashHttpEnsureHash"></a> <hr/>
|
|
<em>POST /_api/index</em> (creates a hash index)<hr/>
|
|
<br/>
|
|
<code><b>POST /_api/index?collection=<em>collection-identifier</em></b></code></p>
|
|
<p>Creates a hash index for the collection <em>collection-identifier</em>, if it does not already exist. The call expects an object containing the index details.</p>
|
|
<ul>
|
|
<li><code>type</code>: must be equal to <code>"hash"</code>.</li>
|
|
</ul>
|
|
<ul>
|
|
<li><code>fields</code>: A list of attribute paths.</li>
|
|
</ul>
|
|
<ul>
|
|
<li><code>unique</code>: If <code>true</code>, then create a unique index.</li>
|
|
</ul>
|
|
<p>If the index does not already exists and could be created, then a <code>HTTP 201</code> is returned. If the index already exists, then a <code>HTTP 200</code> is returned.</p>
|
|
<p>If the <em>collection-identifier</em> is unknown, then a <code>HTTP 404</code> is returned. It is possible to specify a name instead of an identifier.</p>
|
|
<p>If the collection already contains documents and you try to create a unique hash index in such a way that there are documents violating the uniqueness, then a <code>HTTP 400</code> is returned.</p>
|
|
<p><b>Examples</b><br/>
|
|
</p>
|
|
<p>Creating an unique constraint:</p>
|
|
<div class="fragment"><pre class="fragment">> curl --data @- -X POST --dump - http://localhost:8529/_api/index?collection=102901008
|
|
{ "type" : "hash", "unique" : true, "fields" : [ "a", "b" ] }
|
|
|
|
HTTP/1.1 201 Created
|
|
content-type: application/json
|
|
|
|
{
|
|
"code": 201,
|
|
"fields": [
|
|
"a",
|
|
"b"
|
|
],
|
|
"id": "102901008/168054969",
|
|
"type": "hash",
|
|
"isNewlyCreated": true,
|
|
"unique": true,
|
|
"error": false
|
|
}
|
|
</pre></div><p>Creating a hash index:</p>
|
|
<div class="fragment"><pre class="fragment">> curl --data @- -X POST --dump - http://localhost:8529/_api/index?collection=105981200
|
|
{ "type" : "hash", "unique" : false, "fields" : [ "a", "b" ] }
|
|
|
|
HTTP/1.1 201 Created
|
|
content-type: application/json
|
|
|
|
{
|
|
"code": 201,
|
|
"fields": [
|
|
"a",
|
|
"b"
|
|
],
|
|
"id": "105981200/171069625",
|
|
"type": "hash",
|
|
"isNewlyCreated": true,
|
|
"unique": false,
|
|
"error": false
|
|
}
|
|
</pre></div> <p><a class="anchor" id="IndexHashHttpByExample"></a> <hr/>
|
|
<em>PUT /_api/simple/by-example</em> (executes simple query "by-example")<hr/>
|
|
<br/>
|
|
<code><b>PUT /_api/simple/by-example</b></code></p>
|
|
<p>This will find all documents matching a given example.</p>
|
|
<p>The call expects a JSON hash array as body with the following attributes:</p>
|
|
<ul>
|
|
<li><code>collection</code>: The identifier or name of the collection to query.</li>
|
|
</ul>
|
|
<ul>
|
|
<li><code>example</code>: The example.</li>
|
|
</ul>
|
|
<ul>
|
|
<li><code>skip</code>: The documents to skip in the query. (optional)</li>
|
|
</ul>
|
|
<ul>
|
|
<li><code>limit</code>: The maximal amount of documents to return. (optional)</li>
|
|
</ul>
|
|
<p>Returns a cursor containing the result, see <a class="el" href="HttpCursor.html">HTTP Interface for AQL Query Cursors</a> for details.</p>
|
|
<p><b>Examples</b><br/>
|
|
</p>
|
|
<p>Matching an attribute:</p>
|
|
<div class="fragment"><pre class="fragment">> curl --data @- -X PUT --dump - http://localhost:8529/_api/simple/by-example
|
|
{ "collection" : "3179705695", "example" : [ { "i" : 1 } ] }
|
|
|
|
HTTP/1.1 201 Created
|
|
content-type: application/json
|
|
|
|
{
|
|
"result": [
|
|
{ "a": { "k": 2, "j": 2 }, "i": 1, "_rev": 3181802847, "_id": "3179705695/3181802847" },
|
|
{ "a": { "j": 1 }, "i": 1, "_rev": 3181475167, "_id": "3179705695/3181475167" },
|
|
{ "a": { "k": 1, "j": 1 }, "i": 1, "_rev": 3181737311, "_id": "3179705695/3181737311" },
|
|
{ "i": 1, "_rev": 3181147487, "_id": "3179705695/3181147487" }
|
|
],
|
|
"count": 4,
|
|
"error": false,
|
|
"hasMore": false,
|
|
"code": 201
|
|
}
|
|
</pre></div><p>Matching an attribute which is a sub-document:</p>
|
|
<div class="fragment"><pre class="fragment">> curl --data @- -X PUT --dump - http://localhost:8529/_api/simple/by-example
|
|
{ "collection" : "3179705695", "example" : [ { "a" : { "j" : 1 } } ] }
|
|
|
|
HTTP/1.1 201 Created
|
|
content-type: application/json
|
|
|
|
{
|
|
"result": [
|
|
{ "a": { "j": 1 }, "i": 1, "_rev": 3181475167, "_id": "3179705695/3181475167" }
|
|
],
|
|
"count": 1,
|
|
"error": false,
|
|
"hasMore": false,
|
|
"code": 201
|
|
}
|
|
</pre></div><p>Matching an attribute within a sub-document:</p>
|
|
<div class="fragment"><pre class="fragment">> curl --data @- -X PUT --dump - http://localhost:8529/_api/simple/by-example
|
|
{ "collection" : "3179705695", "example" : [ "a.j", 1 ] }
|
|
|
|
HTTP/1.1 201 Created
|
|
content-type: application/json
|
|
|
|
{
|
|
"result": [
|
|
{ "a": { "j": 1 }, "i": 1, "_rev": 3181475167, "_id": "3179705695/3181475167" },
|
|
{ "a": { "k": 1, "j": 1 }, "i": 1, "_rev": 3181737311, "_id": "3179705695/3181737311" }
|
|
],
|
|
"count": 2,
|
|
"error": false,
|
|
"hasMore": false,
|
|
"code": 201
|
|
}
|
|
</pre></div> <p><a class="anchor" id="IndexHashHttpFirstExample"></a> <hr/>
|
|
<em>PUT /_api/simple/first-example</em> (executes simple query "first-example")<hr/>
|
|
<br/>
|
|
<code><b>PUT /_api/simple/first-example</b></code></p>
|
|
<p>This will return the first document matching a given example.</p>
|
|
<p>The call expects a JSON hash array as body with the following attributes:</p>
|
|
<ul>
|
|
<li><code>collection</code>: The identifier or name of the collection to query.</li>
|
|
</ul>
|
|
<ul>
|
|
<li><code>example</code>: The example.</li>
|
|
</ul>
|
|
<p>Returns a result containing the document or <code>HTTP 404</code> if no document matched the example.</p>
|
|
<p><b>Examples</b><br/>
|
|
</p>
|
|
<p>If a matching document was found:</p>
|
|
<div class="fragment"><pre class="fragment">> curl --data @- -X PUT --dump - http://localhost:8529/_api/simple/first-example
|
|
{ "collection" : "666351134", "example" : [ "a.j", 1, "a.k", 1 ] }
|
|
|
|
HTTP/1.1 200 OK
|
|
content-type: application/json
|
|
|
|
{
|
|
"error": false,
|
|
"code": 200,
|
|
"document": { "_rev": 668382750, "_id": "666351134/668382750", "a": { "k": 1, "j": 1, "l" : 10 }, "i": 1 }
|
|
}
|
|
</pre></div><p>If no document was found:</p>
|
|
<div class="fragment"><pre class="fragment">> curl --data @- -X PUT --dump - http://localhost:8529/_api/simple/first-example
|
|
{ "collection" : "666351134", "example" : [ "a.j", 1, "a.k", 2 ] }
|
|
|
|
HTTP/1.1 404 Not Found
|
|
content-type: application/json
|
|
|
|
{
|
|
"errorMessage": "no match",
|
|
"error": true,
|
|
"code": 404,
|
|
"errorNum": 404
|
|
}
|
|
</pre></div> </div></div>
|
|
</div></body></html>
|