异常
{ "error": { "root_cause": [{ "type": "circuit_breaking_exception", "reason": "[parent] Data too large, data for [] would be [7201130054/6.7gb], which is larger than the limit of [7103712460/6.6gb], real usage: [7201129672/6.7gb], new bytes reserved: [382/382b], usages [request=0/0b, fielddata=19998/19.5kb, in_flight_requests=21400104/20.4mb, model_inference=0/0b, accounting=10053032/9.5mb]", "bytes_wanted": 7201130054, "bytes_limit": 7103712460, "durability": "TRANSIENT" }], "type": "circuit_breaking_exception", "reason": "[parent] Data too large, data for [] would be [7201130054/6.7gb], which is larger than the limit of [7103712460/6.6gb], real usage: [7201129672/6.7gb], new bytes reserved: [382/382b], usages [request=0/0b, fielddata=19998/19.5kb, in_flight_requests=21400104/20.4mb, model_inference=0/0b, accounting=10053032/9.5mb]", "bytes_wanted": 7201130054, "bytes_limit": 7103712460, "durability": "TRANSIENT" }, "status": 429 }
原因
相信这个原因大家都查到了,那么看文末的详细解析。
field data的缓存不够用
解决
设置 fielddata
缓存占用 JVM
内存的 40%
或更小
curl -XPUT "localhost:9200/_cluster/settings" -H 'Content-Type: application/json' -d '{ "persistent" : { "indices.breaker.fielddata.limit" : "40%" } }'
返回:
{ "acknowledged": true, "persistent": { "indices": { "breaker": { "fielddata": { "limit": "40%" } } } }, "transient": {} }
elasticsearch fielddata理解
在es中,text类型的字段使用一种叫做fielddata的查询时内存数据结构。当字段被排序,聚合或者通过脚本访问时这种数据结构会被创建。它是通过从磁盘读取每个段的整个反向索引来构建的,然后存存储在java的堆内存中。
fileddata默认是不开启的。Fielddata可能会消耗大量的堆空间,尤其是在加载高基数文本字段时。一旦fielddata已加载到堆中,它将在该段的生命周期内保留。此外,加载fielddata是一个昂贵的过程,可能会导致用户遇到延迟命中。这就是默认情况下禁用fielddata的原因。如果尝试对文本字段进行排序,聚合或脚本访问,将看到以下异常:
“Fielddata is disabled on text fields by default. Set fielddata=true on [your_field_name] in order to load fielddata in memory by uninverting the inverted index. Note that this can however use significant memory.”
在启用fielddata之前,请考虑使用文本字段进行聚合,排序或脚本的原因。这样做通常没有意义。text字段在索引例如New York这样的词会被分词,会被拆成new,york。在此字段上面来一个terms的聚合会返回一个new的bucket和一个york的bucket,当你想只返回一个New York的bucket的时候就会出现问题。在kibana中执行如下的命令即可:
PUT my_index { "mappings": { "_doc": { "properties": { "my_field": { "type": "text", "fields": { "keyword": { "type": "keyword" } } } } } } }
然后使用my_field字段进行搜索。使用my_field.keyword字段进行聚合,排序或脚本。
可以使用PUT映射API在现有文本字段上启用fielddata,如下所示:
PUT my_index/_mapping/_doc { "properties": { "my_field": { "type": "text", "fielddata": true } } }
为my_field指定的映射应包含该字段的现有映射以及fielddata参数。