id-field.asciidoc 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  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,js]
  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. // CONSOLE
  29. <1> Querying on the `_id` field (also see the <<query-dsl-ids-query,`ids` query>>)
  30. The value of the `_id` field is also accessible in aggregations or for sorting,
  31. but doing so is discouraged as it requires to load a lot of data in memory. In
  32. case sorting or aggregating on the `_id` field is required, it is advised to
  33. duplicate the content of the `_id` field in another field that has `doc_values`
  34. enabled.