2013-08-29 07:24:34 +08:00
|
|
|
[[mapping-id-field]]
|
2015-07-20 07:24:29 +08:00
|
|
|
=== `_id` field
|
2013-08-29 07:24:34 +08:00
|
|
|
|
2017-07-05 22:09:31 +08:00
|
|
|
Each document has an `_id` that uniquely identifies it, which is indexed
|
|
|
|
so that documents can be looked up either with the <<docs-get,GET API>> or the
|
2020-11-21 05:53:23 +08:00
|
|
|
<<query-dsl-ids-query,`ids` query>>. The `_id` can either be assigned at
|
|
|
|
indexing time, or a unique `_id` can be generated by {es}. This field is not
|
|
|
|
configurable in the mappings.
|
2017-07-05 22:09:31 +08:00
|
|
|
|
2020-11-21 05:53:23 +08:00
|
|
|
The value of the `_id` field is accessible in queries such as `term`,
|
|
|
|
`terms`, `match`, and `query_string`.
|
2015-07-20 07:24:29 +08:00
|
|
|
|
2019-09-06 22:55:16 +08:00
|
|
|
[source,console]
|
2015-07-20 07:24:29 +08:00
|
|
|
--------------------------
|
|
|
|
# Example documents
|
2020-07-28 02:46:39 +08:00
|
|
|
PUT my-index-000001/_doc/1
|
2015-07-20 07:24:29 +08:00
|
|
|
{
|
|
|
|
"text": "Document with ID 1"
|
|
|
|
}
|
|
|
|
|
2020-07-28 02:46:39 +08:00
|
|
|
PUT my-index-000001/_doc/2?refresh=true
|
2015-07-20 07:24:29 +08:00
|
|
|
{
|
|
|
|
"text": "Document with ID 2"
|
|
|
|
}
|
|
|
|
|
2020-07-28 02:46:39 +08:00
|
|
|
GET my-index-000001/_search
|
2015-07-20 07:24:29 +08:00
|
|
|
{
|
|
|
|
"query": {
|
|
|
|
"terms": {
|
|
|
|
"_id": [ "1", "2" ] <1>
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
--------------------------
|
|
|
|
|
|
|
|
<1> Querying on the `_id` field (also see the <<query-dsl-ids-query,`ids` query>>)
|
2017-05-09 22:33:52 +08:00
|
|
|
|
2020-11-21 05:53:23 +08:00
|
|
|
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.
|
2019-07-15 21:39:20 +08:00
|
|
|
|
|
|
|
[NOTE]
|
|
|
|
==================================================
|
|
|
|
`_id` is limited to 512 bytes in size and larger values will be rejected.
|
|
|
|
==================================================
|