---
title: Indexing Metadata Information
description: Couchbase Server allows indexing on selected metadata fields, for
  example the expiration and CAS properties.
pubDate: 2026-08-17T09:53:44.266Z
antora:
  editUrl: https://github.com/couchbaselabs/docs-devex/edit/release/7.6/modules/n1ql/pages/n1ql-language-reference/indexing-meta-info.adoc
  xref: xref:7.6@server:n1ql:n1ql-language-reference/indexing-meta-info.adoc[]
---

[Consult the llms.txt file for a full list of contents](/llms.txt)
[View original HTML](/server/7.6/n1ql/n1ql-language-reference/indexing-meta-info.html)

# Indexing Metadata Information

Couchbase Server allows indexing on selected metadata fields, for example the expiration and CAS properties. This improves performance of queries involving predicates on the metadata fields, such as expired documents or recently modified documents.

## [](#overview)Overview

The [META()](metafun.md#meta) function enables you to return the metadata for a keyspace or document. To index a selected metadata field, you must use a [nested expression](nestedops.md#field-selection) containing the `META()` function and the required property, for example `META().id`.

The property name must be separated from the `META()` function by a dot (`.`) and only the following metadata properties can be indexed. If you attempt to build an index on a metadata field that's not indexable, an error is returned.

cas

Value representing the current state of an item which changes every time the item is modified. For details, refer to [Concurrent Document Mutations](../../../../java-sdk/current/howtos/concurrent-document-mutations.md).

expiration

Value representing a document's expiration date. A value of 0 (zero) means no expiration date. For details, refer to [KV Operations](../../../../java-sdk/current/howtos/kv-operations.md#document-expiration).

id

Value representing a document's unique ID number.

The `META()` function does not require a keyspace parameter when creating an index, since it implicitly uses the keyspace being indexed.

## [](#examples)Examples

To try the examples in this section, set the query context to the `inventory` scope in the travel sample dataset. For more information, see [Query Context](../n1ql-intro/queriesandresults.md#query-context).

Example 1\. Find two documents that have no expiration date

Index

```sqlpp
CREATE INDEX idx_airline_expire ON airline (META().expiration);
```

Query

```sqlpp
SELECT META().id, META().expiration
FROM airline
WHERE META().expiration = 0
ORDER BY META().id
LIMIT 2;
```

Results

```json
[
  {
    "expiration": 0,
    "id": "airline_10"
  },
  {
    "expiration": 0,
    "id": "airline_10123"
  }
]
```

Example 2\. Find all documents whose meta ID tag starts with a letter higher than g

Index

```sqlpp
CREATE INDEX idx_hotel_id ON hotel (META().id);
```

Query

```sqlpp
SELECT name, META().id
FROM hotel
WHERE META().id > "g"
LIMIT 2;
```

Results

```json
[
  {
    "id": "hotel_10025",
    "name": "Medway Youth Hostel"
  },
  {
    "id": "hotel_10026",
    "name": "The Balmoral Guesthouse"
  }
]
```

Example 3\. Find the two most recently modified hotel documents

Index

```sqlpp
CREATE INDEX idx_hotel_cas ON hotel (META().cas);
```

Query

```sqlpp
SELECT name, META().cas
FROM hotel
ORDER BY META().cas DESC
LIMIT 2;
```

Results

```json
[
  {
    "cas": 1612962459766947800,
    "name": "The George Hotel"
  },
  {
    "cas": 1612962459645378600,
    "name": "Texas Spring"
  }
]
```