id-field.asciidoc 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. [[mapping-id-field]]
  2. === `_id` field
  3. Each document has an `_id` that uniquely identifies it, which is indexed
  4. so that documents can be looked up either with the <<docs-get,GET API>> or the
  5. <<query-dsl-ids-query,`ids` query>>. The `_id` can either be assigned at
  6. indexing time, or a unique `_id` can be generated by {es}. This field is not
  7. configurable in the mappings.
  8. The value of the `_id` field is accessible in queries such as `term`,
  9. `terms`, `match`, and `query_string`.
  10. [source,console]
  11. --------------------------
  12. # Example documents
  13. PUT my-index-000001/_doc/1
  14. {
  15. "text": "Document with ID 1"
  16. }
  17. PUT my-index-000001/_doc/2?refresh=true
  18. {
  19. "text": "Document with ID 2"
  20. }
  21. GET my-index-000001/_search
  22. {
  23. "query": {
  24. "terms": {
  25. "_id": [ "1", "2" ] <1>
  26. }
  27. }
  28. }
  29. --------------------------
  30. <1> Querying on the `_id` field (also see the <<query-dsl-ids-query,`ids` query>>)
  31. The `_id` field is restricted from use in aggregations, sorting, and scripting.
  32. In case sorting or aggregating on the `_id` field is required, it is advised to
  33. duplicate the content of the `_id` field into another field that has
  34. `doc_values` enabled.
  35. [NOTE]
  36. ==================================================
  37. `_id` is limited to 512 bytes in size and larger values will be rejected.
  38. ==================================================