mapping.asciidoc 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264
  1. [[breaking_50_mapping_changes]]
  2. === Mapping changes
  3. ==== `string` fields replaced by `text`/`keyword` fields
  4. The `string` field datatype has been replaced by the `text` field for full
  5. text analyzed content, and the `keyword` field for not-analyzed exact string
  6. values. For backwards compatibility purposes, during the 5.x series:
  7. * `string` fields on pre-5.0 indices will function as before.
  8. * New `string` fields can be added to pre-5.0 indices as before.
  9. * `text` and `keyword` fields can also be added to pre-5.0 indices.
  10. * When adding a `string` field to a new index, the field mapping will be
  11. rewritten as a `text` or `keyword` field if possible, otherwise
  12. an exception will be thrown. Certain configurations that were possible
  13. with `string` fields are no longer possible with `text`/`keyword` fields
  14. such as enabling `term_vectors` on a not-analyzed `keyword` field.
  15. ==== Default string mappings
  16. String mappings now have the following default mappings:
  17. [source,js]
  18. ---------------
  19. {
  20. "type": "text",
  21. "fields": {
  22. "keyword": {
  23. "type": "keyword",
  24. "ignore_above": 256
  25. }
  26. }
  27. }
  28. ---------------
  29. This allows to perform full-text search on the original field name and to sort
  30. and run aggregations on the sub keyword field.
  31. ==== Numeric fields
  32. Numeric fields are now indexed with a completely different data-structure, called
  33. BKD tree, that is expected to require less disk space and be faster for range
  34. queries than the previous way that numerics were indexed.
  35. Term queries will return constant scores now, while they used to return higher
  36. scores for rare terms due to the contribution of the document frequency, which
  37. this new BKD structure does not record. If scoring is needed, then it is advised
  38. to map the numeric fields as <<keyword,`keyword`s>> too.
  39. Note that this <<keyword,`keyword`>> mapping do not need to replace the numeric
  40. mapping. For instance if you need both sorting and scoring on your numeric field,
  41. you could map it both as a number and a `keyword` using <<multi-fields>>:
  42. [source,js]
  43. --------------------------------------------------
  44. PUT my_index
  45. {
  46. "mappings": {
  47. "my_type": {
  48. "properties": {
  49. "my_number": {
  50. "type": "long",
  51. "fields": {
  52. "keyword": {
  53. "type": "keyword"
  54. }
  55. }
  56. }
  57. }
  58. }
  59. }
  60. }
  61. --------------------------------------------------
  62. // CONSOLE
  63. Also the `precision_step` parameter is now irrelevant and will be rejected on
  64. indices that are created on or after 5.0.
  65. ==== `_timestamp` and `_ttl`
  66. The `_timestamp` and `_ttl` fields were deprecated and are now removed. As a
  67. replacement for `_timestamp`, you should populate a regular date field with the
  68. current timestamp on application side. For `_ttl`, you should either use
  69. time-based indices when applicable, or cron a delete-by-query with a range
  70. query on a timestamp field
  71. ==== `index` property
  72. On all field datatypes (except for the deprecated `string` field), the `index`
  73. property now only accepts `true`/`false` instead of `not_analyzed`/`no`. The
  74. `string` field still accepts `analyzed`/`not_analyzed`/`no`.
  75. ==== Doc values on unindexed fields
  76. Previously, setting a field to `index:no` would also disable doc-values. Now,
  77. doc-values are always enabled on numeric and boolean fields unless
  78. `doc_values` is set to `false`.
  79. ==== Floating points use `float` instead of `double`
  80. When dynamically mapping a field containing a floating point number, the field
  81. now defaults to using `float` instead of `double`. The reasoning is that
  82. floats should be more than enough for most cases but would decrease storage
  83. requirements significantly.
  84. ==== `norms`
  85. `norms` now take a boolean instead of an object. This boolean is the replacement
  86. for `norms.enabled`. There is no replacement for `norms.loading` since eager
  87. loading of norms is not useful anymore now that norms are disk-based.
  88. ==== `fielddata.format`
  89. Setting `fielddata.format: doc_values` in the mappings used to implicitly
  90. enable doc-values on a field. This no longer works: the only way to enable or
  91. disable doc-values is by using the `doc_values` property of mappings.
  92. ==== `fielddata.filter.regex`
  93. Regex filters are not supported anymore and will be dropped on upgrade.
  94. ==== Source-transform removed
  95. The source `transform` feature has been removed. Instead, use an ingest pipeline
  96. ==== `_parent` field no longer indexed
  97. The join between parent and child documents no longer relies on indexed fields
  98. and therefore from 5.0.0 onwards the `_parent` field is no longer indexed. In
  99. order to find documents that refer to a specific parent id, the new
  100. `parent_id` query can be used. The GET response and hits inside the search
  101. response still include the parent id under the `_parent` key.
  102. ==== Source `format` option
  103. The `_source` mapping no longer supports the `format` option. It will still be
  104. accepted for indices created before the upgrade to 5.0 for backwards
  105. compatibility, but it will have no effect. Indices created on or after 5.0
  106. will reject this option.
  107. ==== Object notation
  108. Core types no longer support the object notation, which was used to provide
  109. per document boosts as follows:
  110. [source,js]
  111. ---------------
  112. {
  113. "value": "field_value",
  114. "boost": 42
  115. }
  116. ---------------
  117. ==== Boost accuracy for queries on `_all`
  118. Per-field boosts on the `_all` are now compressed into a single byte instead
  119. of the 4 bytes used previously. While this will make the index much more
  120. space-efficient, it also means that index time boosts will be less accurately
  121. encoded.
  122. ==== `_ttl` and `_timestamp` cannot be created
  123. You can no longer create indexes with `_ttl` or `_timestamp` enabled. Indexes
  124. with them enabled created before 5.0 will continue to work.
  125. You should replace `_timestamp` in new indexes by adding a field to your source
  126. either in the application producing the data or with an ingest pipline like
  127. this one:
  128. [source,js]
  129. ---------------
  130. PUT _ingest/pipeline/timestamp
  131. {
  132. "description" : "Adds a timestamp field at the current time",
  133. "processors" : [ {
  134. "set" : {
  135. "field": "timestamp",
  136. "value": "{{_ingest.timestamp}}"
  137. }
  138. } ]
  139. }
  140. PUT newindex/type/1?pipeline=timestamp
  141. {
  142. "example": "data"
  143. }
  144. GET newindex/type/1
  145. ---------------
  146. // CONSOLE
  147. Which produces
  148. [source,js]
  149. ---------------
  150. {
  151. "_source": {
  152. "example": "data",
  153. "timestamp": "2016-06-21T18:48:55.560+0000"
  154. },
  155. ...
  156. }
  157. ---------------
  158. // TESTRESPONSE[s/\.\.\./"found": true, "_id": "1", "_index": "newindex", "_type": "type", "_version": 1/]
  159. // TESTRESPONSE[s/"2016-06-21T18:48:55.560\+0000"/"$body._source.timestamp"/]
  160. If you have an old index created with 2.x that has `_timestamp` enabled then
  161. you can migrate it to a new index with the a `timestamp` field in the source
  162. with reindex:
  163. [source,js]
  164. ---------------
  165. POST _reindex
  166. {
  167. "source": {
  168. "index": "oldindex"
  169. },
  170. "dest": {
  171. "index": "newindex"
  172. },
  173. "script": {
  174. "lang": "painless",
  175. "inline": "ctx._source.timestamp = ctx._timestamp; ctx._timestamp = null"
  176. }
  177. }
  178. ---------------
  179. // CONSOLE
  180. // TEST[s/^/PUT oldindex\nGET _cluster\/health?wait_for_status=yellow\n/]
  181. You can replace `_ttl` with time based index names (preferred) or by adding a
  182. cron job which runs a delete-by-query on a timestamp field in the source
  183. document. If you had documents like this:
  184. [source,js]
  185. ---------------
  186. POST index/type/_bulk
  187. {"index":{"_id":1}}
  188. {"example": "data", "timestamp": "2016-06-21T18:48:55.560+0000" }
  189. {"index":{"_id":2}}
  190. {"example": "data", "timestamp": "2016-04-21T18:48:55.560+0000" }
  191. ---------------
  192. // CONSOLE
  193. Then you could delete all of the documents from before June 1st with:
  194. [source,js]
  195. ---------------
  196. POST index/type/_delete_by_query
  197. {
  198. "query": {
  199. "range" : {
  200. "timestamp" : {
  201. "lt" : "2016-05-01"
  202. }
  203. }
  204. }
  205. }
  206. ---------------
  207. // CONSOLE
  208. // TEST[continued]
  209. IMPORTANT: Keep in mind that deleting documents from an index is very expensive
  210. compared to deleting whole indexes. That is why time based indexes are
  211. recommended over this sort of thing and why `_ttl` was deprecated in the first
  212. place.