ignore_above(忽略超越限制的字段)

原文链接 : https://www.elastic.co/guide/en/elasticsearch/reference/5.3/ignore-above.html

译文链接 : http://www.apache.wiki/pages/createpage-entervariables.action?templateId=4816898&spaceKey=Elasticsearch&title=&newSpaceKey=Elasticsearch&fromPageId=9405287

贡献者 : @您的名字,ApacheCNApache中文网

字符串长度超过 ignore_above 设置的不会被索引和存储.

  1. curl -XPUT 'localhost:9200/my_index?pretty' -H 'Content-Type: application/json' -d'
  2. {
  3. "mappings": {
  4. "my_type": {
  5. "properties": {
  6. "message": {
  7. "type": "keyword",
  8. "ignore_above": 20 # 1
  9. }
  10. }
  11. }
  12. }
  13. }
  14. '
  15. curl -XPUT 'localhost:9200/my_index/my_type/1?pretty' -H 'Content-Type: application/json' -d' # 2
  16. {
  17. "message": "Syntax error"
  18. }
  19. '
  20. curl -XPUT 'localhost:9200/my_index/my_type/2?pretty' -H 'Content-Type: application/json' -d' # 3
  21. {
  22. "message": "Syntax error with some long stacktrace"
  23. }
  24. '
  25. curl -XGET 'localhost:9200/_search?pretty' -H 'Content-Type: application/json' -d' # 4
  26. {
  27. "aggs": {
  28. "messages": {
  29. "terms": {
  30. "field": "message"
  31. }
  32. }
  33. }
  34. }

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

tip

ignore_above 设置允许在相同索引的相同名称的字段有不同的配置,可以使用 PUT mapping API 在现有字段上更新其值。

此选项对于防止Lucene term(词条)长度超过32766是有用的.

ignore_above 的值是字符数,但 Lucene 计数的是字节。所以如果你使用具有许多非ASCII字符的UTF-8文本,则可能需要将限制设置为 32766/3 = 10922,因为UTF-8字符可能占用至多3个字节。