Elasticsearch实战:常见错误及详细解决方案

1.read_only_allow_delete":"true"

当我们在向某个索引添加一条数据的时候,可能(极少情况)会碰到下面的报错:

{
"error": {
"root_cause": [
{
"type": "cluster_block_exception",
"reason": "blocked by: [FORBIDDEN/12/index read-only / allow delete (api)];"
}
],
"type": "cluster_block_exception",
"reason": "blocked by: [FORBIDDEN/12/index read-only / allow delete (api)];"
},
"status": 403
}

上述报错是说索引现在的状态是只读模式(read-only),如果查看该索引此时的状态:

GET z1/_settings
#结果如下
{
"z1" : {
"settings" : {
"index" : {
"number_of_shards" : "5",
"blocks" : {
"read_only_allow_delete" : "true"
},
"provided_name" : "z1",
"creation_date" : "1556204559161",
"number_of_replicas" : "1",
"uuid" : "3PEevS9xSm-r3tw54p0o9w",
"version" : {
"created" : "6050499"
}
}
}
}
}

可以看到"read_only_allow_delete" : "true",说明此时无法插入数据,当然,我们也可以模拟出来这个错误:

PUT z1
{
"mappings": {
"doc": {
"properties": {
"title": {
"type":"text"
}
}
}
},
"settings": {
"index.blocks.read_only_allow_delete": true
}
} PUT z1/doc/1
{
"title": "es真难学"
}

现在我们如果执行插入数据,就会报开始的错误。那么怎么解决呢?

  • 清理磁盘,使占用率低于 85%。
  • 手动调整该项,具体参考官网

这里介绍一种,我们将该字段重新设置为:

PUT z1/_settings
{
"index.blocks.read_only_allow_delete": null
}

现在再查看该索引就正常了,也可以正常的插入数据和查询了。

2. illegal_argument_exception

有时候,在聚合中,我们会发现如下报错:

{
"error": {
"root_cause": [
{
"type": "illegal_argument_exception",
"reason": "Fielddata is disabled on text fields by default. Set fielddata=true on [age] in order to load fielddata in memory by uninverting the inverted index. Note that this can however use significant memory. Alternatively use a keyword field instead."
}
],
"type": "search_phase_execution_exception",
"reason": "all shards failed",
"phase": "query",
"grouped": true,
"failed_shards": [
{
"shard": 0,
"index": "z2",
"node": "NRwiP9PLRFCTJA7w3H9eqA",
"reason": {
"type": "illegal_argument_exception",
"reason": "Fielddata is disabled on text fields by default. Set fielddata=true on [age] in order to load fielddata in memory by uninverting the inverted index. Note that this can however use significant memory. Alternatively use a keyword field instead."
}
}
],
"caused_by": {
"type": "illegal_argument_exception",
"reason": "Fielddata is disabled on text fields by default. Set fielddata=true on [age] in order to load fielddata in memory by uninverting the inverted index. Note that this can however use significant memory. Alternatively use a keyword field instead.",
"caused_by": {
"type": "illegal_argument_exception",
"reason": "Fielddata is disabled on text fields by default. Set fielddata=true on [age] in order to load fielddata in memory by uninverting the inverted index. Note that this can however use significant memory. Alternatively use a keyword field instead."
}
}
},
"status": 400
}

这是怎么回事呢?是因为,聚合查询时,指定字段不能是text类型。比如下列示例:

PUT z2/doc/1
{
"age":"18"
}
PUT z2/doc/2
{
"age":20
} GET z2/doc/_search
{
"query": {
"match_all": {}
},
"aggs": {
"my_sum": {
"sum": {
"field": "age"
}
}
}
}

当我们向elasticsearch中,添加一条数据时(此时,如果索引存在则直接新增或者更新文档,不存在则先创建索引),首先检查该age字段的映射类型。如上示例中,我们添加第一篇文档时(z1索引不存在),elasticsearch会自动的创建索引,然后为age字段创建映射关系(es 就猜此时age字段的值是什么类型,如果发现是text类型,那么存储该字段的映射类型就是text),此时age字段的值是text类型,所以,第二条插入数据,age的值也是text类型,而不是我们看到的long类型。我们可以查看一下该索引的mappings信息:

GET z2/_mapping
#mapping信息如下
{
"z2" : {
"mappings" : {
"doc" : {
"properties" : {
"age" : {
"type" : "text",
"fields" : {
"keyword" : {
"type" : "keyword",
"ignore_above" : 256
}
}
}
}
}
}
}
}

上述返回结果发现,age类型是text。而该类型又不支持聚合,所以,就会报错了。解决办法就是:

  • 如果选择动态创建一篇文档,映射关系取决于你添加的第一条文档的各字段都对应什么类型。而不是我们看到的那样,第一次是text,第二次不加引号,就是long类型了不是这样的。
  • 如果嫌弃上面的解决办法麻烦,那就选择手动创建映射关系。首先指定好各字段对应什么类型。后续才不至于出错。

3.Result window is too large

很多时候,我们在查询文档时,一次查询结果很可能会有很多,而 elasticsearch 一次返回多少条结果,由size参数决定:

GET e2/doc/_search
{
"size": 100000,
"query": {
"match_all": {}
}
}

而默认是最多范围一万条,那么当我们的请求超过一万条时(比如有十万条),就会报:

Result window is too large, from + size must be less than or equal to: [10000] but was [100000]. See the scroll api for a more efficient way to request large data sets. This limit can be set by changing the [index.max_result_window] index level setting.

意思是一次请求返回的结果太大,可以另行参考 scroll API或者设置index.max_result_window参数手动调整size的最大默认值:

#kibana中设置
PUT e2/_settings
{
"index": {
"max_result_window": "100000"
}
}
#Python中设置
from elasticsearch import Elasticsearch
es = Elasticsearch()
es.indices.put_settings(index='e2', body={"index": {"max_result_window": 100000}})

如上例,我们手动调整索引e2size参数最大默认值到十万,这时,一次查询结果只要不超过 10 万就都会一次返回。 注意,这个设置对于索引essize参数是永久生效的。

4.持续更新中

更多优质内容请关注公号:汀丶人工智能;会提供一些相关的资源和优质文章,免费获取阅读。

Elasticsearch实战:常见错误及详细解决方案的更多相关文章

  1. iOS开发过程中常见错误问题及解决方案

    错误原因:ld: x duplicate symbol for architecture x86_64 clang: error: linker command failed with exit co ...

  2. elasticsearch启动常见错误

    问题出现环境,OS版本:CentOS-7-x86_64-Minimal-1708:ES版本:elasticsearch-6.2.2. 1.max file descriptors [4096] for ...

  3. ELK学习笔记之Elasticsearch启动常见错误

    问题出现的环境: OS版本:CentOS-7-x86_64-Minimal-1708 ES版本:elasticsearch-6.2.2 1. max file descriptors [4096] f ...

  4. 大数据技术之_08_Hive学习_05_Hive实战之谷粒影音(ETL+TopN)+常见错误及解决方案

    第10章 Hive实战之谷粒影音10.1 需求描述10.2 项目10.2.1 数据结构10.2.2 ETL原始数据10.3 准备工作10.3.1 创建表10.3.2 导入ETL后的数据到原始表10.3 ...

  5. ElasticSearch实战系列十一: ElasticSearch错误问题解决方案

    前言 本文主要介绍ElasticSearch在使用过程中出现的各种问题解决思路和办法. ElasticSearch环境安装问题 1,max virtual memory areas vm.max_ma ...

  6. Elasticsearch 集群和索引健康状态及常见错误说明

    之前在IDC机房线上环境部署了一套ELK日志集中分析系统, 这里简单总结下ELK中Elasticsearch健康状态相关问题, Elasticsearch的索引状态和集群状态传达着不同的意思. 一.  ...

  7. 修复 Elasticsearch 集群的常见错误和问题

    文章转载自:https://mp.weixin.qq.com/s/8nWV5b8bJyTLqSv62JdcAw 第一篇:Elasticsearch 磁盘使用率超过警戒水位线 从磁盘常见错误说下去 当客 ...

  8. Elasticsearch学习之ElasticSearch 5.0.0 安装部署常见错误或问题

    ElasticSearch 5.0.0 安装部署常见错误或问题 问题一: [--06T16::,][WARN ][o.e.b.JNANatives ] unable to install syscal ...

  9. 常见ORACLE错误,及解决方案(遇则即时更新)

    1.当登陆时提示“ORA-03113:通信通道的文件结束”时:        解决方案:                     需在X:\oraclexe\app\oracle\product\10 ...

  10. web报告工具FineReport在使用方法和解决方案常见错误遇到(一)

    FineReport在使用方法和解决方案常见错误遇到(一) 这里写的开胃菜.我希望我们能理清自己的问题和解决办法干出来的,Mark一点点.有利于所有. 失败搜索出,如果有一个文件,看看你的度娘那里.看 ...

随机推荐

  1. SQL Server 还原 备份集中的数据库备份与现有的 'XXX' 数据库不同

    1. 介质集有 2 个介质簇,但只提供了 1 个.必须提供所有成员. 因为在备份时有两个路径,所以备份文件会放在两个文件里面,所以在还原的时候只要把两个都添加了就可以还原了. 2. 备份集中的数据库备 ...

  2. Selenium八大元素定位(元素定位,元素等待)

    Selenium WebDriver查找页面元素及元素操作 元素常用方法定位方法 通过id定位元素:find_element_by_id('id_value') 通过name定位元素:find_ele ...

  3. 【辅助工具】SVN使用

    1.在对应路径下右键SVN checkout 2.输入对应的网址.用户名.密码 3.提交右键选择SVN commit.覆盖选择SVN update 4.编辑的时候右键TortoiseSVN-get l ...

  4. Codeforces Round #665 (Div. 2) A - D题题解

    成功拼手速提前过了AC两题,估计因为这个原因排名挺高的,B题晚上做的时候没绕出来,wa4发... 1401A - Distance and Axis 如果 \(n\) 小 于 \(k\) ,则必须将\ ...

  5. Vue3使用vue-video-player组件

    1.安装依赖(亲测5.0.1版本可用,最新版本会找不到'vue-video-player/src/custom-theme.css'这个样式) yarn add  vue-video-player@5 ...

  6. P1077-DP【黄】

    昨天好几道题没做出来很郁闷,结果今天上来半小时不到就直接做出一道黄DP题了,不错,又有写题的冲动了. 这道题我一直被那个"因为方案数可能很多,请输出方案数对 1000007取模的结果.&qu ...

  7. C#约瑟夫环问题算法

    /// <summary> /// 约瑟夫环问题算法 /// </summary> /// <param name="total">总人数< ...

  8. 深入理解Kafka核心设计及原理(一):初识Kafka

    转载请注明出处: 1.1 kafka简介 Kafka 起初是由 Linkedin 公司采用 Scala 语言开发的一个多分区.多副本且基于 ZooKeeper协调的分布式消息系统,现己被捐献给 Apa ...

  9. 例2.8 已知带头结点单链表L,设计算法实现:以表中第一元素作为标准,将表中所有值小于第一个元素的结点均放在第一结点之前,所有值大于第一元素的结点均放在第一元素结点之后。

    1.题目 例2.8已知带头结点单链表L,设计算法实现:以表中第一元素作为标准,将表中所有值小于第一个元素的结点均放在第一结点之前,所有值大于第一元素的结点均放在第一元素结点之后. 2.算法分析 3.代 ...

  10. 第二章 VB.NET 绘图基础

    GDI+( Graphics Device Interface Plus)是 Windows操作系统用来执行绘画及其他相关图形操作的一套子系统,是由. Net Framework中的System.Dr ...