mirror of https://gitee.com/bigwinds/arangodb
165 lines
8.3 KiB
HTML
165 lines
8.3 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>Handling Indexes </h1> </div>
|
|
</div>
|
|
<div class="contents">
|
|
<div class="textblock"><p>This is an introduction to ArangoDB's interface for indexs in general. There are special sections for <a class="el" href="IndexCap.html">cap constraints</a>, <a class="el" href="IndexGeo.html">geo-spatial indexes</a>, <a class="el" href="IndexHash.html">hash indexes</a>, and <a class="el" href="IndexSkiplist.html">skip-lists</a>.</p>
|
|
<hr/>
|
|
<ul>
|
|
<li>
|
|
<a class="el" href="ShellIndex.html">Handling Indexes</a> <ul>
|
|
<li>
|
|
<a class="el" href="ShellIndex.html#ShellIndexIntro">Indexes, Identifiers, Handles</a> </li>
|
|
<li>
|
|
<a class="el" href="ShellIndex.html#ShellIndexResource">Address and ETag of an Index</a> </li>
|
|
<li>
|
|
<a class="el" href="ShellIndex.html#ShellIndexShell">Working with Indexes</a> <ul>
|
|
<li>
|
|
<a class="el" href="ShellIndex.html#ShellIndexCollectionMethods">Collection Methods</a> <ul>
|
|
<li>
|
|
<a class="el" href="ShellIndex.html#ShellIndexRead">collection.index</a> </li>
|
|
<li>
|
|
<a class="el" href="ShellIndex.html#ShellIndexReadAll">collection.getIndexes</a> </li>
|
|
<li>
|
|
<a class="el" href="ShellIndex.html#ShellIndexDelete">collection.dropIndex</a> </li>
|
|
</ul>
|
|
</li>
|
|
<li>
|
|
<a class="el" href="ShellIndex.html#ShellIndexDatabaseMethods">Database Methods</a> <ul>
|
|
<li>
|
|
<a class="el" href="ShellIndex.html#ShellIndexDbRead">db._index</a> </li>
|
|
<li>
|
|
<a class="el" href="ShellIndex.html#ShellIndexDbDelete">db._dropIndex</a> </li>
|
|
</ul>
|
|
</li>
|
|
</ul>
|
|
</li>
|
|
</ul>
|
|
</li>
|
|
</ul>
|
|
<hr/>
|
|
<h2><a class="anchor" id="ShellIndexIntro"></a>
|
|
Indexes, Identifiers, Handles</h2>
|
|
<p><b>Index</b>: Indexes are used to allow fast access to documents. For each collection there is always the primary index which is a hash index for the document identifier. </p>
|
|
<p><b>Index Handle</b>: An index handle uniquely identifies an index in the database. It is a string and consists of a collection identifier and a index identifier separated by <code>/</code>. </p>
|
|
<p><b>Geo Index</b>: A geo index is used to find places on the surface of the earth fast. </p>
|
|
<p><b>Hash Index</b>: A hash index is used to find documents based on examples. </p>
|
|
<p><b>Skiplist Index</b>: A skiplist is used to find ranges of documents. </p>
|
|
<h2><a class="anchor" id="ShellIndexResource"></a>
|
|
Address and ETag of an Index</h2>
|
|
<p>All indexs in ArangoDB have an index handle. This handle uniquely defines an index and is managed by ArangoDB. The interface allows you to access the indexs of a collection as:</p>
|
|
<p><code>db.<em>collection</em>.index(<em>index-handle</em>)</code></p>
|
|
<p>For example: Assume that the index handle, which is stored in the <code>_id</code> field of the index, is <code>7254820/362549736</code> and the index lives in a collection named <em>demo</em>, then that index can be accessed as:</p>
|
|
<p><code>db.demo.index("7254820/362549736")</code></p>
|
|
<p>Because the index handle is unique within the database, you can leave out the <em>collection</em> and use the shortcut:</p>
|
|
<p><code>db._index("7254820/362549736")</code></p>
|
|
<h2><a class="anchor" id="ShellIndexShell"></a>
|
|
Working with Indexes</h2>
|
|
<h3><a class="anchor" id="ShellIndexCollectionMethods"></a>
|
|
Collection Methods</h3>
|
|
<p><a class="anchor" id="ShellIndexRead"></a> <hr/>
|
|
<code><b><em>collection</em>.index(<em>index-handle</em>)</b></code><hr/>
|
|
Returns the index with <em>index-handle</em> or null if no such index exists.</p>
|
|
<p><b>Examples</b><br/>
|
|
</p>
|
|
<div class="fragment"><pre class="fragment">arango> db.example.getIndexes().map(function(x) { return x.id; });
|
|
["93013/0"]
|
|
arango> db.example.index("93013/0");
|
|
{ "id" : "93013/0", "type" : "primary", "fields" : ["_id"] }
|
|
</pre></div> <hr/>
|
|
<p><a class="anchor" id="ShellIndexReadAll"></a> <hr/>
|
|
<code><b>getIndexes()</b></code><hr/>
|
|
Returns a list of all indexes defined for the collection.</p>
|
|
<p><b>Examples</b><br/>
|
|
</p>
|
|
<div class="fragment"><pre class="fragment">arango> db.demo.getIndexes()
|
|
[
|
|
{ "id" : "1439003/0",
|
|
"type" : "primary",
|
|
"fields" : ["_id"]
|
|
},
|
|
{
|
|
"id" : "1439003/2290971",
|
|
"unique" : true,
|
|
"type" : "hash",
|
|
"fields" : ["a"]
|
|
},
|
|
{
|
|
"id" : "1439003/2946331",
|
|
"unique" : false,
|
|
"type" : "hash",
|
|
"fields" : ["b"]
|
|
},
|
|
{
|
|
"id" : "1439003/3077403",
|
|
"unique" : false,
|
|
"type" : "skiplist",
|
|
"fields" : ["c"]
|
|
}
|
|
]
|
|
</pre></div> <hr/>
|
|
<p><a class="anchor" id="ShellIndexDelete"></a> <hr/>
|
|
<code><b><em>collection</em>.dropIndex(<em>index</em>)</b></code><hr/>
|
|
Drops the index. If the index does not exist, then <code>false</code> is returned. If the index existed and was dropped, then <code>true</code> is returned. Note that you cannot drop the primary index.</p>
|
|
<hr/>
|
|
<code><b><em>collection</em>.dropIndex(<em>index-handle</em>)</b></code><hr/>
|
|
Same as above. Instead of an index an index handle can be given.</p>
|
|
<p><b>Examples</b><br/>
|
|
</p>
|
|
<div class="fragment"><pre class="fragment">arango> db.example.ensureSkiplist("a", "b");
|
|
{ "id" : "73650/991154", "unique" : false, "type" : "skiplist", "fields" : ["a", "b"], "isNewlyCreated" : true }
|
|
|
|
arango> i = db.example.getIndexes();
|
|
[{ "id" : "73650/0", "type" : "primary", "fields" : ["_id"] },
|
|
{ "id" : "73650/991154", "unique" : false, "type" : "skiplist", "fields" : ["a", "b"] }]
|
|
|
|
arango> db.example.dropIndex(i[0])
|
|
false
|
|
|
|
arango> db.example.dropIndex(i[1].id)
|
|
true
|
|
|
|
arango> i = db.example.getIndexes();
|
|
[{ "id" : "73650/0", "type" : "primary", "fields" : ["_id"] }]
|
|
</pre></div> <hr/>
|
|
<h3><a class="anchor" id="ShellIndexDatabaseMethods"></a>
|
|
Database Methods</h3>
|
|
<p><a class="anchor" id="ShellIndexDbRead"></a> <hr/>
|
|
<code><b>db._index(<em>index-handle</em>)</b></code><hr/>
|
|
Returns the index with <em>index-handle</em> or null if no such index exists.</p>
|
|
<p><b>Examples</b><br/>
|
|
</p>
|
|
<div class="fragment"><pre class="fragment">arango> db.example.getIndexes().map(function(x) { return x.id; });
|
|
["93013/0"]
|
|
arango> db._index("93013/0");
|
|
{ "id" : "93013/0", "type" : "primary", "fields" : ["_id"] }
|
|
</pre></div> <hr/>
|
|
<p><a class="anchor" id="ShellIndexDbDelete"></a> <hr/>
|
|
<code><b>db._dropIndex(<em>index</em>)</b></code><hr/>
|
|
Drops the <em>index</em>. If the index does not exists, then <code>false</code> is returned. If the index existed and was dropped, then <code>true</code> is returned. Note that you cannot drop the primary index.</p>
|
|
<hr/>
|
|
<code><b>db._dropIndex(<em>index-handle</em>)</b></code><hr/>
|
|
Drops the index with <em>index-handle</em>.</p>
|
|
<p><b>Examples</b><br/>
|
|
</p>
|
|
<div class="fragment"><pre class="fragment">arango> db.example.ensureSkiplist("a", "b");
|
|
{ "id" : "73650/1577138", "unique" : false, "type" : "skiplist", "fields" : ["a", "b"], "isNewlyCreated" : true }
|
|
|
|
arango> i = db.example.getIndexes();
|
|
[{ "id" : "73650/0", "type" : "primary", "fields" : ["_id"] },
|
|
{ "id" : "73650/1577138", "unique" : false, "type" : "skiplist", "fields" : ["a", "b"] }]
|
|
|
|
arango> db._dropIndex(i[0]);
|
|
false
|
|
|
|
arango> db._dropIndex(i[1].id);
|
|
true
|
|
|
|
arango> i = db.example.getIndexes();
|
|
[{ "id" : "73650/0", "type" : "primary", "fields" : ["_id"] }]
|
|
</pre></div> </div></div>
|
|
</div></body></html>
|