id-field.asciidoc 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. [[mapping-id-field]]
  2. === `_id`
  3. Each document indexed is associated with an id and a type. The `_id`
  4. field can be used to index just the id, and possible also store it. By
  5. default it is not indexed and not stored (thus, not created).
  6. Note, even though the `_id` is not indexed, all the APIs still work
  7. (since they work with the `_uid` field), as well as fetching by ids
  8. using `term`, `terms` or `prefix` queries/filters (including the
  9. specific `ids` query/filter).
  10. The `_id` field can be enabled to be indexed, and possibly stored,
  11. using:
  12. [source,js]
  13. --------------------------------------------------
  14. {
  15. "tweet" : {
  16. "_id" : {"index": "not_analyzed", "store" : false }
  17. }
  18. }
  19. --------------------------------------------------
  20. The `_id` mapping can also be associated with a `path` that will be used
  21. to extract the id from a different location in the source document. For
  22. example, having the following mapping:
  23. [source,js]
  24. --------------------------------------------------
  25. {
  26. "tweet" : {
  27. "_id" : {
  28. "path" : "post_id"
  29. }
  30. }
  31. }
  32. --------------------------------------------------
  33. Will cause `1` to be used as the id for:
  34. [source,js]
  35. --------------------------------------------------
  36. {
  37. "message" : "You know, for Search",
  38. "post_id" : "1"
  39. }
  40. --------------------------------------------------
  41. This does require an additional lightweight parsing step while indexing,
  42. in order to extract the id to decide which shard the index operation
  43. will be executed on.