Elasticsearch 常见错误
一 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
}
现在再查看该索引就正常了,也可以正常的插入数据和查询了。
二 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类型了不是这样的。 - 如果嫌弃上面的解决办法麻烦,那就选择手动创建映射关系。首先指定好各字段对应什么类型。后续才不至于出错。
三 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}})
如上例,我们手动调整索引e2的size参数最大默认值到十万,这时,一次查询结果只要不超过10万就都会一次返回。
注意,这个设置对于索引es的size参数是永久生效的。
Elasticsearch 常见错误的更多相关文章
- Elasticsearch常见错误与配置简介
一.常见错误 1.1 root用户启动elasticsearch报错 Elasticsearch为了安全考虑,不让使用root启动,解决方法新建一个用户,用此用户进行相关的操作.如果你用root启动, ...
- elasticsearch常见错误及解决方案
1.OpenJDK 64-Bit Server VM warning: If the number of processors is expected to increase from one, th ...
- Elasticsearch 集群和索引健康状态及常见错误说明
之前在IDC机房线上环境部署了一套ELK日志集中分析系统, 这里简单总结下ELK中Elasticsearch健康状态相关问题, Elasticsearch的索引状态和集群状态传达着不同的意思. 一. ...
- Elasticsearch学习之ElasticSearch 5.0.0 安装部署常见错误或问题
ElasticSearch 5.0.0 安装部署常见错误或问题 问题一: [--06T16::,][WARN ][o.e.b.JNANatives ] unable to install syscal ...
- 修复 Elasticsearch 集群的常见错误和问题
文章转载自:https://mp.weixin.qq.com/s/8nWV5b8bJyTLqSv62JdcAw 第一篇:Elasticsearch 磁盘使用率超过警戒水位线 从磁盘常见错误说下去 当客 ...
- ES安装&常见错误
ES常见错误 案例一 [2018-06-20T02:35:47,152][INFO ][o.e.b.BootstrapChecks ] [SUcoFrg] bound or publishing to ...
- 初识JAVA(二)(送给Java和安卓初学者)----常见错误
博主接着上篇的来讲哦,以后的更新中,博主会出一些练习题,有兴趣的可以做做然后吧代码粘贴到下面,大家可以一起研究学习,一起进步,本篇文章主要讲的是: 一.常见错误 二.连接上篇一起的训练 无论是什么方向 ...
- ubuntu 常见错误--Could not get lock /var/lib/dpkg/lock
ubuntu 常见错误--Could not get lock /var/lib/dpkg/lock 通过终端安装程序sudo apt-get install xxx时出错:E: Could not ...
- coreseek常见错误原因及解决方法
coreseek常见错误原因及解决方法 Coreseek 中文全文检索引擎 Coreseek 是一款中文全文检索/搜索软件,以GPLv2许可协议开源发布,基于Sphinx研发并独立发布,专攻中文搜索和 ...
随机推荐
- 数据库常见考题查询SQL
1.列出各个部门中工资高于本部门的平均工资的员工数和部门号,并按部门号排序 执行查询: select count(*), a.deptid from employee a groub by depti ...
- mysql运维入门1:基础及备份还原
存储引擎 myisam 表强调的是性能 执行速度比innodb类型更快 不提供事务支持 如果执行大量的select操作,是首选 支持表锁,不支持行锁 innodb 提供事务支持.外键等高级数据库功能 ...
- SpringCloud异常处理统一封装我来做-使用篇
SpringCloud异常处理统一封装我来做-使用篇 简介 重复功能我来写.在 SpringBoot 项目里都有全局异常处理以及返回包装等,返回前端是带上succ.code.msg.data等字段.单 ...
- 单词数(hdu2072)
这道题用到了(STL初步)集合:Set 的知识点.同时,也用到了stringstream 的知识点,还用到了getline(cin,line)的知识点. #include<iostream> ...
- WordPress安全 - 隐藏保护wp-login.php后台登陆入口
我们在基本的设置账户用户名和密码安全基础上,最好把这个登录入口限制访问或者隐藏,之前也有看到一些教程说安装插件,比如安装Stealth Login Page插件可以设置登录页面后的参数,与我要设置的非 ...
- CF1340B Nastya and Scoreboard(暴搜剪枝/dp)
Question 一个n个数码位的分数板,每一个数码位都是一个七段数码管,现在给出每个数码位的显示情况,问再点亮k段数码管的话能显示的最大的数是多少,如果不能构成一串数字,就输出-1 Solution ...
- element-ui上传组件,通过自定义请求上传文件
记录使用element-ui上传组件,通过自定义请求上传文件需要注意的地方. <el-upload ref="uploadMutiple" :auto-upload=&quo ...
- [JavaWeb基础] 030.dom4j读取xml的4种方法
通常我们在项目开发的过程中经常要操作到xml文件,在JAVA这边,我们会很自然的联想到Dom4J这个apache的开源插件,那么我们使用Dom4J如何来读取xml文件呢?下面我们来看看以下4种方法 1 ...
- [安卓安全] 01.安卓本地数据存储:Shared Preferences安全风险浅析
*:first-child { margin-top: 0 !important; } body > *:last-child { margin-bottom: 0 !important; } ...
- This的关键字的使用
this: 1.可以用来修饰属性 方法 构造器 2.this理解为当前对象或当前正在创建的对象. 3.可以在构造器中通过this()形参的方式显示的调用本类中其他重载的指定的构造器 要求: 在构造器 ...