ignore-above.asciidoc 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. [[ignore-above]]
  2. === `ignore_above`
  3. Strings longer than the `ignore_above` setting will not be processed by the
  4. <<analyzer,analyzer>> and will not be indexed. This is mainly useful for
  5. <<mapping-index,`not_analyzed`>> string fields, which are typically used for
  6. filtering, aggregations, and sorting. These are structured fields and it
  7. doesn't usually make sense to allow very long terms to be indexed in these
  8. fields.
  9. [source,js]
  10. --------------------------------------------------
  11. PUT my_index
  12. {
  13. "mappings": {
  14. "my_type": {
  15. "properties": {
  16. "message": {
  17. "type": "string",
  18. "index": "not_analyzed",
  19. "ignore_above": 20 <1>
  20. }
  21. }
  22. }
  23. }
  24. }
  25. PUT my_index/my_type/1 <2>
  26. {
  27. "message": "Syntax error"
  28. }
  29. PUT my_index/my_type/2 <3>
  30. {
  31. "message": "Syntax error with some long stacktrace"
  32. }
  33. GET _search <4>
  34. {
  35. "aggs": {
  36. "messages": {
  37. "terms": {
  38. "field": "message"
  39. }
  40. }
  41. }
  42. }
  43. --------------------------------------------------
  44. // AUTOSENSE
  45. <1> This field will ignore any string longer than 20 characters.
  46. <2> This document is indexed successfully.
  47. <3> This document will be indexed, but without indexing the `message` field.
  48. <4> Search returns both documents, but only the first is present in the terms aggregation.
  49. TIP: The `ignore_above` setting is allowed to have different settings for
  50. fields of the same name in the same index. Its value can be updated on
  51. existing fields using the <<indices-put-mapping,PUT mapping API>>.
  52. This option is also useful for protecting against Lucene's term byte-length
  53. limit of `32766`.
  54. NOTE: The value for `ignore_above` is the _character count_, but Lucene counts
  55. bytes. If you use UTF-8 text with many non-ASCII characters, you may want to
  56. set the limit to `32766 / 3 = 10922` since UTF-8 characters may occupy at most
  57. 3 bytes.