ignore_above

Strings longer than the ignore_above setting will not be indexed or stored. For arrays of strings, ignore_above will be applied for each array element separately and string elements longer than ignore_above will not be indexed or stored.

All strings/array elements will still be present in the _source field, if the latter is enabled which is the default in Elasticsearch.

  1. PUT my-index-000001
  2. {
  3. "mappings": {
  4. "properties": {
  5. "message": {
  6. "type": "keyword",
  7. "ignore_above": 20
  8. }
  9. }
  10. }
  11. }
  12. PUT my-index-000001/_doc/1
  13. {
  14. "message": "Syntax error"
  15. }
  16. PUT my-index-000001/_doc/2
  17. {
  18. "message": "Syntax error with some long stacktrace"
  19. }
  20. GET my-index-000001/_search
  21. {
  22. "aggs": {
  23. "messages": {
  24. "terms": {
  25. "field": "message"
  26. }
  27. }
  28. }
  29. }

This field will ignore any string longer than 20 characters.

This document is indexed successfully.

This document will be indexed, but without indexing the message field.

Search returns both documents, but only the first is present in the terms aggregation.

The ignore_above setting can be updated on existing fields using the PUT mapping API.

This option is also useful for protecting against Lucene’s term byte-length limit of 32766.

The value for ignore_above is the character count, but Lucene counts bytes. If you use UTF-8 text with many non-ASCII characters, you may want to set the limit to 32766 / 4 = 8191 since UTF-8 characters may occupy at most 4 bytes.