Working with Skiplist Indexes

If a suitable skip-list index exists, then /_api/simple/range and other operations will use this index to execute queries.

Create skip list

creates a skip-list

POST /_api/index#skiplist

Query Parameters

  • collection-name (required): The collection name.

A JSON object with these properties is required:

  • fields (string): an array of attribute paths.
  • unique: if true, then create a unique index.
  • type: must be equal to "skiplist".
  • sparse: if true, then create a sparse index.
  • deduplicate: if false, the deduplication of array values is turned off.

Creates a skip-list index for the collection collection-name, if it does not already exist. The call expects an object containing the index details.

In a sparse index all documents will be excluded from the index that do not contain at least one of the specified index attributes (i.e. fields) or that have a value of null in any of the specified index attributes. Such documents will not be indexed, and not be taken into account for uniqueness checks if the unique flag is set.

In a non-sparse index, these documents will be indexed (for non-present indexed attributes, a value of null will be used) and will be taken into account for uniqueness checks if the unique flag is set.

Note: unique indexes on non-shard keys are not supported in a cluster.

Example:

Creating a skiplist index

shell> curl -X POST --data-binary @- --dump - http://localhost:8529/_api/index?collection=products <<EOF
{ 
  "type" : "skiplist", 
  "unique" : false, 
  "fields" : [ 
    "a", 
    "b" 
  ] 
}
EOF

HTTP/1.1 201 Created
content-type: application/json; charset=utf-8
x-content-type-options: nosniff

{ 
  "deduplicate" : true, 
  "fields" : [ 
    "a", 
    "b" 
  ], 
  "id" : "products/11868", 
  "isNewlyCreated" : true, 
  "sparse" : false, 
  "type" : "skiplist", 
  "unique" : false, 
  "error" : false, 
  "code" : 201 
}

Example:

Creating a sparse skiplist index

shell> curl -X POST --data-binary @- --dump - http://localhost:8529/_api/index?collection=products <<EOF
{ 
  "type" : "skiplist", 
  "unique" : false, 
  "sparse" : true, 
  "fields" : [ 
    "a" 
  ] 
}
EOF

HTTP/1.1 201 Created
content-type: application/json; charset=utf-8
x-content-type-options: nosniff

{ 
  "deduplicate" : true, 
  "fields" : [ 
    "a" 
  ], 
  "id" : "products/11924", 
  "isNewlyCreated" : true, 
  "sparse" : true, 
  "type" : "skiplist", 
  "unique" : false, 
  "error" : false, 
  "code" : 201 
}

Return Codes

  • 200: If the index already exists, then a HTTP 200 is returned.
  • 201: If the index does not already exist and could be created, then a HTTP 201 is returned.
  • 400: If the collection already contains documents and you try to create a unique skip-list index in such a way that there are documents violating the uniqueness, then a HTTP 400 is returned.
  • 404: If the collection-name is unknown, then a HTTP 404 is returned.

Examples

Creating a skiplist index

shell> curl -X POST --data-binary @- --dump - http://localhost:8529/_api/index?collection=products <<EOF
{ 
  "type" : "skiplist", 
  "unique" : false, 
  "fields" : [ 
    "a", 
    "b" 
  ] 
}
EOF

HTTP/1.1 201 Created
content-type: application/json; charset=utf-8
x-content-type-options: nosniff

show response body

Creating a sparse skiplist index

shell> curl -X POST --data-binary @- --dump - http://localhost:8529/_api/index?collection=products <<EOF
{ 
  "type" : "skiplist", 
  "unique" : false, 
  "sparse" : true, 
  "fields" : [ 
    "a" 
  ] 
}
EOF

HTTP/1.1 201 Created
content-type: application/json; charset=utf-8
x-content-type-options: nosniff

show response body