# ignore\_above（忽略超越限制的字段）

字符串长度超过**ignore\_above**设置的不会被索引和存储.

```
curl -XPUT 'localhost:9200/my_index?pretty' -H 'Content-Type: application/json' -d'
{
  "mappings": {
    "my_type": {
      "properties": {
        "message": {
          "type": "keyword",
          "ignore_above": 20  # 1
        }
      }
    }
  }
}
'
curl -XPUT 'localhost:9200/my_index/my_type/1?pretty' -H 'Content-Type:  application/json' -d' # 2
{
  "message": "Syntax error"
}
'
curl -XPUT 'localhost:9200/my_index/my_type/2?pretty' -H 'Content-Type:  application/json' -d' # 3
{
  "message": "Syntax error with some long stacktrace"
}
'
curl -XGET 'localhost:9200/_search?pretty' -H 'Content-Type: application/json' -d' # 4
{
  "aggs": {
    "messages": {
      "terms": {
        "field": "message"
      }
    }
  }
}
```

| 1 | 字段会忽略超过20个字符的字符串.                       |
| - | --------------------------------------- |
| 2 | 这个**document**成功被索引.                    |
| 3 | 这个**document**会被索引,但是不会索引**message**字段. |
| 4 | 搜索返回两个文档,但只有第一个存在于**terms**（词条）聚合中.     |

> tip
>
> **ignore\_above**设置允许在相同索引的相同名称的字段有不同的配置,可以使用[PUT mapping API](https://www.elastic.co/guide/en/elasticsearch/reference/5.3/indices-put-mapping.html)在现有字段上更新其值。

此选项对于防止Lucene term（词条）长度超过32766是有用的.\
**ignore\_above** 的值是字符数，但 **Lucene** 计数的是字节。所以如果你使用具有许多非ASCII字符的UTF-8文本，则可能需要将限制设置为 **32766/3 = 10922**，因为UTF-8字符可能占用至多3个字节。
