Views

Views can index documents of multiple collections and enable sophisticated information retrieval possibilities, like full-text search with ranking by relevance

Views allows you to perform complex searches at high performance. They are accelerated by inverted indexes that are updated near real-time.

A View is conceptually a transformation function over documents from zero or more collections. The transformation depends on the View type and the View configuration.

Views are powered by ArangoDB’s built-in search engine. See ArangoSearch for details.

View types

Available View types:

You need to specify the type when you create the View. The type cannot be changed later.

View names

You can give each View a name to identify and access it. The name needs to be unique within a database, but not globally for the entire ArangoDB instance.

The namespace for Views is shared with collections. There cannot exist a View and a collection with the same name in the same database.

The View name needs to be a string that adheres to the following constraints:

  • The names must only consist of the letters A to Z (both in lower and upper case), the digits 0 to 9, and underscore (_) and dash (-) characters. This also means that any non-ASCII names are not allowed.

  • View names must start with a letter.

  • The maximum allowed length of a name is 256 bytes.

  • View names are case-sensitive.

You can rename Views (except in cluster deployments). This changes the View name, but not the View identifier.

View identifiers

A View identifier lets you refer to a View in a database, similar to the name. It is a string value and is unique within a database. Unlike View names, ArangoDB assigns View IDs automatically and you have no control over them.

ArangoDB internally uses View IDs to look up Views. However, you should use the View name to access a View instead of its identifier.

ArangoDB uses 64-bit unsigned integer values to maintain View IDs internally. When returning View IDs to clients, ArangoDB returns them as strings to ensure the identifiers are not clipped or rounded by clients that do not support big integers. Clients should treat the View IDs returned by ArangoDB as opaque strings when they store or use them locally.

Views API

The following descriptions cover the JavaScript interface for Views that you can use to handle Views from the arangosh command-line tool, as well as in server-side JavaScript code like Foxx microservices. For other languages see the corresponding language API.

The following examples show the basic usage of the View API. For more details, see:

Create a View

Create a View with default properties:

arangosh> view = db._createView("myView", "arangosearch", {});
Show execution results
Hide execution results
[ArangoView 84811, "myView" (type arangosearch)]

Get a View

Get the View called myView by its name:

arangosh> view = db._view("myView");
Show execution results
Hide execution results
[ArangoView 84811, "myView" (type arangosearch)]

Get the View properties

arangosh> view.properties();
Show execution results
Hide execution results
{ 
  "writebufferSizeMax" : 33554432, 
  "writebufferIdle" : 64, 
  "consolidationIntervalMsec" : 1000, 
  "consolidationPolicy" : { 
    "type" : "tier", 
    "segmentsBytesFloor" : 2097152, 
    "segmentsBytesMax" : 5368709120, 
    "segmentsMax" : 10, 
    "segmentsMin" : 1, 
    "minScore" : 0 
  }, 
  "writebufferActive" : 0, 
  "commitIntervalMsec" : 1000, 
  "links" : { 
  }, 
  "storedValues" : [ ], 
  "cleanupIntervalStep" : 2, 
  "primarySort" : [ ], 
  "primarySortCompression" : "lz4" 
}

Set a View property

arangosh> view.properties({cleanupIntervalStep: 12});
Show execution results
Hide execution results
{ 
  "cleanupIntervalStep" : 12, 
  "commitIntervalMsec" : 1000, 
  "consolidationIntervalMsec" : 1000, 
  "consolidationPolicy" : { 
    "type" : "tier", 
    "segmentsBytesFloor" : 2097152, 
    "segmentsBytesMax" : 5368709120, 
    "segmentsMax" : 10, 
    "segmentsMin" : 1, 
    "minScore" : 0 
  }, 
  "primarySort" : [ ], 
  "primarySortCompression" : "lz4", 
  "storedValues" : [ ], 
  "writebufferActive" : 0, 
  "writebufferIdle" : 64, 
  "writebufferSizeMax" : 33554432, 
  "links" : { 
  } 
}

Link a collection to a View:

arangosh> view.properties({links: {colA: {includeAllFields: true}}});
Show execution results
Hide execution results
{ 
  "cleanupIntervalStep" : 12, 
  "commitIntervalMsec" : 1000, 
  "consolidationIntervalMsec" : 1000, 
  "consolidationPolicy" : { 
    "type" : "tier", 
    "segmentsBytesFloor" : 2097152, 
    "segmentsBytesMax" : 5368709120, 
    "segmentsMax" : 10, 
    "segmentsMin" : 1, 
    "minScore" : 0 
  }, 
  "primarySort" : [ ], 
  "primarySortCompression" : "lz4", 
  "storedValues" : [ ], 
  "writebufferActive" : 0, 
  "writebufferIdle" : 64, 
  "writebufferSizeMax" : 33554432, 
  "links" : { 
    "colA" : { 
      "analyzers" : [ 
        "identity" 
      ], 
      "fields" : { 
      }, 
      "includeAllFields" : true, 
      "storeValues" : "none", 
      "trackListPositions" : false 
    } 
  } 
}

Add another link to the View:

arangosh> view.properties({links: {colB: {fields: {text: {}}}}});
Show execution results
Hide execution results
{ 
  "cleanupIntervalStep" : 12, 
  "commitIntervalMsec" : 1000, 
  "consolidationIntervalMsec" : 1000, 
  "consolidationPolicy" : { 
    "type" : "tier", 
    "segmentsBytesFloor" : 2097152, 
    "segmentsBytesMax" : 5368709120, 
    "segmentsMax" : 10, 
    "segmentsMin" : 1, 
    "minScore" : 0 
  }, 
  "primarySort" : [ ], 
  "primarySortCompression" : "lz4", 
  "storedValues" : [ ], 
  "writebufferActive" : 0, 
  "writebufferIdle" : 64, 
  "writebufferSizeMax" : 33554432, 
  "links" : { 
    "colA" : { 
      "analyzers" : [ 
        "identity" 
      ], 
      "fields" : { 
      }, 
      "includeAllFields" : true, 
      "storeValues" : "none", 
      "trackListPositions" : false 
    }, 
    "colB" : { 
      "analyzers" : [ 
        "identity" 
      ], 
      "fields" : { 
        "text" : { 
        } 
      }, 
      "includeAllFields" : false, 
      "storeValues" : "none", 
      "trackListPositions" : false 
    } 
  } 
}

Remove the first link again:

arangosh> view.properties({links: {colA: null}});
Show execution results
Hide execution results
{ 
  "cleanupIntervalStep" : 12, 
  "commitIntervalMsec" : 1000, 
  "consolidationIntervalMsec" : 1000, 
  "consolidationPolicy" : { 
    "type" : "tier", 
    "segmentsBytesFloor" : 2097152, 
    "segmentsBytesMax" : 5368709120, 
    "segmentsMax" : 10, 
    "segmentsMin" : 1, 
    "minScore" : 0 
  }, 
  "primarySort" : [ ], 
  "primarySortCompression" : "lz4", 
  "storedValues" : [ ], 
  "writebufferActive" : 0, 
  "writebufferIdle" : 64, 
  "writebufferSizeMax" : 33554432, 
  "links" : { 
    "colB" : { 
      "analyzers" : [ 
        "identity" 
      ], 
      "fields" : { 
        "text" : { 
        } 
      }, 
      "includeAllFields" : false, 
      "storeValues" : "none", 
      "trackListPositions" : false 
    } 
  } 
}

Drop a View

arangosh> db._dropView("myView");
Show execution results
Hide execution results