Type to search.

_id field

Serverless

Elastic Cloud Serverless projects are autoscaled environments, fully managed by Elastic and available on Elastic Cloud.

Availability

  • Generally available

    This functionality is generally available and ready for production usage.

Serverless interfaces and procedures might differ from classic Elastic Stack deployments.

Stack

The Elastic Stack includes Elastic's core products such as Elasticsearch, Kibana, Logstash, and Beats.

Availability

  • Generally available

    This functionality is generally available and ready for production usage.

Unless stated otherwise on the page, this functionality is available when your Elastic Stack is deployed on Elastic Cloud Hosted, Elastic Cloud Enterprise, Elastic Cloud on Kubernetes, and self-managed environments.

This documentation corresponds to the latest patch available for each minor version. If you're not using the latest patch, check the release notes for changes.

Each document has an _id that uniquely identifies it, which is indexed so that documents can be looked up either with the GET API or the ids query. The _id can either be assigned at indexing time, or a unique _id can be generated by Elasticsearch. The _id field has limited configurability in the mappings; see Parameters for _id fields.

The value of the _id field is accessible in queries such as term, terms, match, and query_string.

JSON

# Example documents
PUT my-index-000001/_doc/1
{
  "text": "Document with ID 1"
}
PUT my-index-000001/_doc/2?refresh=true
{
  "text": "Document with ID 2"
}
GET my-index-000001/_search
{
  "query": {
    "terms": {
      "_id": [ "1", "2" ]
    }
  }
}
  1. Querying on the _id field (also see the ids query)

The _id field is restricted from use in aggregations, sorting, and scripting. In case sorting or aggregating on the _id field is required, it is advised to duplicate the content of the _id field into another field that has doc_values enabled.

Note

_id is limited to 512 bytes in size and larger values will be rejected.

Serverless Preview

Elastic Cloud Serverless projects are autoscaled environments, fully managed by Elastic and available on Elastic Cloud.

Availability

  • Preview

    This functionality is in technical preview and is ready for evaluation. Use with caution in production; it is not recommended for mission-critical workloads. Elastic will work to fix any issues, but features in technical preview are not subject to the support SLA of official GA features. Specific Support terms apply.

Serverless interfaces and procedures might differ from classic Elastic Stack deployments.

Stack Preview 9.5+

The Elastic Stack includes Elastic's core products such as Elasticsearch, Kibana, Logstash, and Beats.

Availability

  • Preview since 9.5

    This functionality is in technical preview and is ready for evaluation. Use with caution in production; it is not recommended for mission-critical workloads. Elastic will work to fix any issues, but features in technical preview are not subject to the support SLA of official GA features. Specific Support terms apply.

Unless stated otherwise on the page, this functionality is available when your Elastic Stack is deployed on Elastic Cloud Hosted, Elastic Cloud Enterprise, Elastic Cloud on Kubernetes, and self-managed environments.

This documentation corresponds to the latest patch available for each minor version. If you're not using the latest patch, check the release notes for changes.

The _id field accepts the following mapping parameter:

mode

Controls how the _id value is stored and retrieved. Accepted values are:

  • document — The _id is stored as a stored field and indexed. This is the standard behaviour. This is default for document based index modes.
  • columnar — The _id is stored as binary doc values and indexed, but not as a stored field. This reduces per-document overhead when the index uses a columnar storage layout (for example, the logsdb_columnar index mode) where doc values are already being read for most fields. This is the default for columnar based index modes.
JSON
PUT my-columnar-index
{
  "mappings": {
    "_id": {
      "mode": "columnar"
    }
  }
}