解决当keyword类型超过256字节的报错:max_bytes_length_exceeded_exception: bytes can be at most 32766 in length;

概要描述


向Search中Put/Post数据的时候,产生如下报错:

{
    "error":{
        "root_cause":[
            {
                "type":"illegal_argument_exception",
                "reason":"Document contains at least one immense term in field="aaa" (whose UTF8 encoding is longer than the max length 32766), all of which were skipped. Please correct the analyzer to not produce such terms. The prefix of the first immense term is: '...', original message: bytes can be at most 32766 in length; got 32767"
            }
        ],
        "caused_by":{
            "type":"max_bytes_length_exceeded_exception",
            "reason":"max_bytes_length_exceeded_exception: bytes can be at most 32766 in length; got 32767"
        }
    },
    "status":400
}

经查明,原因是某个字段的值太长,而Search每个keyword类型的field默认能接受的长度为32766个字节,当超过32766个字节时,会抛异常

详细说明


为解决这个问题,有如下解决方案:

使用ignore_above

用于设置超过设定字符后,不被索引或者存储,无法通过term精确匹配检索返回结果,主要针对keyword类型,而text类型对长度没有限制。

这些字段通常用来进行过滤、聚合和排序。而且这些字段都是结构化的,所以一般不会允许在这些字段中索引过长的项。

需要修改mappings

curl -XPUT localhost:9200/${index_name} -d '
{
  "mappings": {
    "${index_type}": {
      "properties": {
        "message": {
          "type": "keyword",
          "index": "not_analyzed",
          "ignore_above": 256
        }
      }
    }
  }
}'

mappings修改后可以索引256字节前的数据,256字节后的数据可以正常插入,但是无法被索引,即使用term检索,无法匹配到256字节后的词 因为256字节后的数据没有被索引

  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 6
    评论
评论 6
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值