一 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}})

如上例,我们手动调整索引e2size参数最大默认值到十万,这时,一次查询结果只要不超过10万就都会一次返回。

注意,这个设置对于索引essize参数是永久生效的。

Elasticsearch 常见错误的更多相关文章

  1. Elasticsearch常见错误与配置简介

    一.常见错误 1.1 root用户启动elasticsearch报错 Elasticsearch为了安全考虑,不让使用root启动,解决方法新建一个用户,用此用户进行相关的操作.如果你用root启动, ...

  2. elasticsearch常见错误及解决方案

    1.OpenJDK 64-Bit Server VM warning: If the number of processors is expected to increase from one, th ...

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

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

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

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

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

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

  6. ES安装&常见错误

    ES常见错误 案例一 [2018-06-20T02:35:47,152][INFO ][o.e.b.BootstrapChecks ] [SUcoFrg] bound or publishing to ...

  7. 初识JAVA(二)(送给Java和安卓初学者)----常见错误

    博主接着上篇的来讲哦,以后的更新中,博主会出一些练习题,有兴趣的可以做做然后吧代码粘贴到下面,大家可以一起研究学习,一起进步,本篇文章主要讲的是: 一.常见错误 二.连接上篇一起的训练 无论是什么方向 ...

  8. 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 ...

  9. coreseek常见错误原因及解决方法

    coreseek常见错误原因及解决方法 Coreseek 中文全文检索引擎 Coreseek 是一款中文全文检索/搜索软件,以GPLv2许可协议开源发布,基于Sphinx研发并独立发布,专攻中文搜索和 ...

随机推荐

  1. django 两种创建模型实例的方法

    1. 添加一个classmethod from django.db import models class Book(models.Model): title = models.CharField(m ...

  2. 旧版flexbox局部填坑

    本来昨晚要写一篇react的小笔记,恰好同学小聚的时候附近有个ios维修,把我的4s拿去修好,早上用我还是ios5.1系统的4s打开自己的页面,发现flexbox布局的部分是乱的,眼前一黑. what ...

  3. React:form

    表单控件: input 文档在介绍控件之前,先提到了react组件自身的一个特点:状态由state掌控,改变组件状态只能用setState方法. 而在html的表单里,input.radio.chec ...

  4. 破坏之王DDoS攻击与防范深度剖析【学习笔记】

    一.DDoS初步印象 1.什么是分布式拒绝服务攻击? 1)首先它是一种拒绝服务攻击 我们可以这么认为,凡是导致合法用户不能访问服务的行为,就是拒绝服务攻击. 注:早期的拒绝服务主要基于系统和应用程序的 ...

  5. Hills And Valleys 杭电多校第五场

    题意:长度为n的序列,有一次翻转区间的机会,问最长不减序列 题解:如果没有翻转区间的机会,有两个做法. 一是dp[i]表示以i结尾的最长序列 dp[i]=max(dp[i],dp[j]+1)  (j& ...

  6. 设计模式:Filter+Servlet+反射

    传统设计 分类管理需要:增加,删除,编辑,修改,查询5个服务端功能. 一个路径对应一个Servlet的思路,就需要设计5个Servlet类,并且在web.xml中配置5个路径. CategoryAdd ...

  7. Crontab定时备份网站脚本及mysql数据库

    1)shell脚本 #!/bin/bash #你要修改的地方从这里开始 MYSQL_USER="root" #mysql用户名 MYSQL_PASS="123456&qu ...

  8. wordpress中文章发布时间不显示?用get_the_date代替the_date

    今天发现,在主题中部分地方使用the_date函数来显示文章发布的时间时,竟然发生不显示时间的情况,再仔细看了一下这些文章,有些都是经过几次修改和保存的,可能是由于the_date只是显示文章第一次发 ...

  9. tomcat依赖--linux

    https://tomcat.apache.org/download-90.cgi 下载 3,解压到usr/locat/tomcat 创建usr/local/tomcat Mkdir /usr/loc ...

  10. Docker容器启动时初始化Mysql数据库

    1. 前言 Docker在开发中使用的越来越多了,最近搞了一个Spring Boot应用,为了方便部署将Mysql也放在Docker中运行.那么怎么初始化 SQL脚本以及数据呢? 我这里有两个传统方案 ...