store.asciidoc 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  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. <<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,console]
  16. --------------------------------------------------
  17. PUT my-index-000001
  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-000001/_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-000001/_search
  42. {
  43. "stored_fields": [ "title", "date" ] <2>
  44. }
  45. --------------------------------------------------
  46. <1> The `title` and `date` fields are stored.
  47. <2> This request will retrieve the values of the `title` and `date` fields.
  48. [NOTE]
  49. .Stored fields returned as arrays
  50. ======================================
  51. For consistency, stored fields are always returned as an _array_ because there
  52. is no way of knowing if the original field value was a single value, multiple
  53. values, or an empty array.
  54. If you need the original value, you should retrieve it from the `_source`
  55. field instead.
  56. ======================================