id-field.asciidoc 933 B

1234567891011121314151617181920212223242526272829303132333435363738
  1. [[mapping-id-field]]
  2. === `_id` field
  3. Each document indexed is associated with a <<mapping-type-field,`_type`>> (see
  4. <<mapping-type>>) and an <<mapping-id-field,`_id`>>. The `_id` field is not
  5. indexed as its value can be derived automatically from the
  6. <<mapping-uid-field,`_uid`>> field.
  7. The value of the `_id` field is accessible in certain queries (`term`,
  8. `terms`, `match`, `query_string`, `simple_query_string`), but
  9. _not_ in aggregations, scripts or when sorting, where the <<mapping-uid-field,`_uid`>>
  10. field should be used instead:
  11. [source,js]
  12. --------------------------
  13. # Example documents
  14. PUT my_index/my_type/1
  15. {
  16. "text": "Document with ID 1"
  17. }
  18. PUT my_index/my_type/2
  19. {
  20. "text": "Document with ID 2"
  21. }
  22. GET my_index/_search
  23. {
  24. "query": {
  25. "terms": {
  26. "_id": [ "1", "2" ] <1>
  27. }
  28. }
  29. }
  30. --------------------------
  31. // CONSOLE
  32. <1> Querying on the `_id` field (also see the <<query-dsl-ids-query,`ids` query>>)