id-field.asciidoc 1.2 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>>.
  6. The value of the `_id` field is accessible in certain queries (`term`,
  7. `terms`, `match`, `query_string`, `simple_query_string`).
  8. [source,console]
  9. --------------------------
  10. # Example documents
  11. PUT my_index/_doc/1
  12. {
  13. "text": "Document with ID 1"
  14. }
  15. PUT my_index/_doc/2?refresh=true
  16. {
  17. "text": "Document with ID 2"
  18. }
  19. GET my_index/_search
  20. {
  21. "query": {
  22. "terms": {
  23. "_id": [ "1", "2" ] <1>
  24. }
  25. }
  26. }
  27. --------------------------
  28. <1> Querying on the `_id` field (also see the <<query-dsl-ids-query,`ids` query>>)
  29. The value of the `_id` field is also accessible in aggregations or for sorting,
  30. but doing so is discouraged as it requires to load a lot of data in memory. In
  31. case sorting or aggregating on the `_id` field is required, it is advised to
  32. duplicate the content of the `_id` field in another field that has `doc_values`
  33. enabled.
  34. [NOTE]
  35. ==================================================
  36. `_id` is limited to 512 bytes in size and larger values will be rejected.
  37. ==================================================