store.asciidoc 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. [[mapping-store]]
  2. === `store`
  3. By default, field values are <<mapping-index,indexed>> to make them searchable,
  4. but they are not _stored_. This means that the field can be queried, but the
  5. original field value cannot be retrieved.
  6. Usually this doesn't matter. The field value is already part of the
  7. <<mapping-source-field,`_source` field>>, which is stored by default. If you
  8. only want to retrieve the value of a single field or of a few fields, instead
  9. of the whole `_source`, then this can be achieved with
  10. <<search-request-source-filtering,source filtering>>.
  11. In certain situations it can make sense to `store` a field. For instance, if
  12. you have a document with a `title`, a `date`, and a very large `content`
  13. field, you may want to retrieve just the `title` and the `date` without having
  14. to extract those fields from a large `_source` field:
  15. [source,js]
  16. --------------------------------------------------
  17. PUT my_index
  18. {
  19. "mappings": {
  20. "properties": {
  21. "title": {
  22. "type": "text",
  23. "store": true <1>
  24. },
  25. "date": {
  26. "type": "date",
  27. "store": true <1>
  28. },
  29. "content": {
  30. "type": "text"
  31. }
  32. }
  33. }
  34. }
  35. PUT my_index/_doc/1
  36. {
  37. "title": "Some short title",
  38. "date": "2015-01-01",
  39. "content": "A very long content field..."
  40. }
  41. GET my_index/_search
  42. {
  43. "stored_fields": [ "title", "date" ] <2>
  44. }
  45. --------------------------------------------------
  46. // CONSOLE
  47. <1> The `title` and `date` fields are stored.
  48. <2> This request will retrieve the values of the `title` and `date` fields.
  49. [NOTE]
  50. .Stored fields returned as arrays
  51. ======================================
  52. For consistency, stored fields are always returned as an _array_ because there
  53. is no way of knowing if the original field value was a single value, multiple
  54. values, or an empty array.
  55. If you need the original value, you should retrieve it from the `_source`
  56. field instead.
  57. ======================================
  58. Another situation where it can make sense to make a field stored is for those
  59. that don't appear in the `_source` field (such as <<copy-to,`copy_to` fields>>).