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研发并独立发布,专攻中文搜索和 ...
随机推荐
- kafka如何防止key相同的消息并发消费
最开始,我认为只用把消费者设置为单线程消费,就可以避免并发问题. 因为同一个key,分区一定相同,那么就只会被同一个消费者消费,消费者又是单线程,这样就避免了并发问题 后面发现,上述的方式没有办法处理 ...
- vue组件试错
[Vue warn]: Property or method "child1" is not defined on the instance but referenced duri ...
- POJ1321棋盘问题(DFS)
Description 在一个给定形状的棋盘(形状可能是不规则的)上面摆放棋子,棋子没有区别.要求摆放时任意的两个棋子不能放在棋盘中的同一行或者同一列,请编程求解对于给定形状和大小的棋盘,摆放k个棋子 ...
- 爬虫之图片懒加载技术、selenium工具与PhantomJS无头浏览器
图片懒加载技术 selenium爬虫简单使用 2.1 selenium简介 2.2 selenium安装 2.3 selenium简单使用 2.3.1 selenium使用案例 2.3.2 selen ...
- docker基本维护命令
docker search centos ##查服务器上面的镜像:docker images ##查本地的镜像.docker pull centos ##拉镜像. docker run centos ...
- JQuery动态创建表单并提交
// 捕捉链接的点击事件 $('#btn').click(function(){ // 取得要提交的参数 var my_val = $.trim($('#ipt').val()); // 取得要提交页 ...
- mysql基本操作汇总
1.数据库操作 (1)创建数据库 CREATE DATABASE <数据库名>; 例子: CREATE DATABASE IF NOT EXISTS RUNOOB DEFAULT CHAR ...
- Docker部署nginx,tomcat,es,可视化
nginx [root@iz2zeaet7s13lfkc8r3e2kz /]# docker pull nginx #下载 Using default tag: latest latest: Pull ...
- PIC16F887的LCD
RS RA5 RW RA4 RD RA3 将引脚设置为输出的时候要对ANS5 ANS4 ANS3 设置为0
- [Wireshark]_003_电子邮件抓包分析
电子邮件是我们的生活工作中经常使用的一种服务,用来联系世界各地的朋友,客户.下面我们就用Wireshark对电子邮件进行抓包. 准备工作: 邮件客户端一款(Outlook,Foxmail,KooMai ...