ArangoDB v3.4 reached End of Life (EOL) and is no longer supported.

This documentation is outdated. Please see the most recent version here: Latest Docs

Getting started with ArangoSearch Views

The DDL configuration

DDL is a data definition language or data description language for defining data structures, especially database schemas.

All DDL operations on Views can be done via JavaScript or REST calls. The DDL syntax follows the well established ArangoDB guidelines and thus is very similar between the JavaScript interface for views and the HTTP interface for views.This article uses the JavaScript syntax.

Assume the following collections were initially defined in a database using the following commands:

c0 = db._create("ExampleCollection0");
c1 = db._create("ExampleCollection1");

c0.save({ i: 0, name: "full", text: "是一个 多模 型数 据库" });
c0.save({ i: 1, name: "half", text: "是一个 多模" });
c0.save({ i: 2, name: "other half", text: "型数 据库" });
c0.save({ i: 3, name: "quarter", text: "是一" });

c1.save({ i: 4, a: "foo", b: "bar" });
c1.save({ i: 5, a: "foo", b: "baz" });
c1.save({ i: 6, a: "bar", b: "foo" });
c1.save({ i: 7, a: "baz", b: "foo" });

Creating a View (with default parameters)

v0 = db._createView("ExampleView", "arangosearch", {});

Linking created View with a collection and adding indexing parameters

v0 = db._view("ExampleView");
v0.properties({
    links: {
      /* collection Link 0 with additional custom configuration: */
      'ExampleCollection0':
      {
        /* examine fields of all linked collections,
           using default configuration: */
        includeAllFields: true,
        fields:
        {
          /* a field to apply custom configuration
             that will index English text: */
          name:
          {
            analyzers: ["text_en"]
          },
          /* another field to apply custom configuration
             that will index Chinese text: */
          text:
          {
            analyzers: ["text_zh"]
          }
        }
      },
      /* collection Link 1 with custom configuration: */
      'ExampleCollection1':
      {
        /* examine all fields using default configuration: */
        includeAllFields: true,
        fields:
        {
          a:
          {
            /* a field to apply custom configuration
                that will index English text: */
            analyzers: ["text_en"]
          }
        }
      }
    }
  }
);

Query data using created View with linked collections

db._query(`FOR doc IN ExampleView
  SEARCH PHRASE(doc.text, '型数 据库', 'text_zh') OR STARTS_WITH(doc.b, 'ba')
  SORT TFIDF(doc) DESC
  RETURN doc`);

Examine query result

Result of the latter query will include all documents from both linked collections that include 多模 型数 phrase in Chinese at any part of text property or b property in English that starts with ba. Additionally, descendant sorting using TFIDF algorithm will be applied during a search:

[
  {
    "_key" : "120",
    "_id" : "ExampleCollection0/120",
    "_rev" : "_XPoMzCi--_",
    "i" : 0,
    "name" : "full",
    "text" : "是一个 多模 型数 据库"
  },
  {
    "_key" : "124",
    "_id" : "ExampleCollection0/124",
    "_rev" : "_XPoMzCq--_",
    "i" : 2,
    "name" : "other half",
    "text" : "型数 据库"
  },
  {
    "_key" : "128",
    "_id" : "ExampleCollection1/128",
    "_rev" : "_XPoMzCu--_",
    "a" : "foo",
    "b" : "bar",
    "i" : 4
  },
  {
    "_key" : "130",
    "_id" : "ExampleCollection1/130",
    "_rev" : "_XPoMzCy--_",
    "a" : "foo",
    "b" : "baz",
    "i" : 5
  }
]