ES进行如下聚合操作时,会报如题所示错误:

 ➜  Downloads curl -XPOST 'localhost:9200/bank/_search?pretty' -d '
{
"size": 0,
"aggs": {
"group_by_state": {
"terms": {
"field": "state"
}
}
}
}'

提示报错如下:

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

  根据官方文档显示,出现该错误是因为5.x之后,Elasticsearch对排序、聚合所依据的字段用单独的数据结构(fielddata)缓存到内存里了,但是在text字段上默认是禁用的,如果有需要单独开启,这样做的目的是为了节省内存空间。——官方文档地址:https://www.elastic.co/guide/en/elasticsearch/reference/current/fielddata.html

开启方法:

 ➜  Downloads curl -XPUT 'http://localhost:9200/bank/_mapping/account' -d '
{
"properties": {
"state": {
"type": "text",
"fielddata": true
}
}
}
'
# bank是index、account是类型、state是你需要设置的text字段

出现如下提示,说明设置成功:

 {"acknowledged":true}

至此,聚合问题解决:

 ➜  Downloads curl -XPOST 'localhost:9200/bank/_search?pretty' -d '
{
"size": 0,
"aggs": {
"group_by_state": {
"terms": {
"field": "state"
}
}
}
}'
{
"took" : 60,
"timed_out" : false,
"_shards" : {
"total" : 5,
"successful" : 5,
"failed" : 0
},
"hits" : {
"total" : 1000,
"max_score" : 0.0,
"hits" : [ ]
},
"aggregations" : {
"group_by_state" : {
"doc_count_error_upper_bound" : 20,
"sum_other_doc_count" : 770,
"buckets" : [
{
"key" : "id",
"doc_count" : 27
},
{
"key" : "tx",
"doc_count" : 27
},
{
"key" : "al",
"doc_count" : 25
},
{
"key" : "md",
"doc_count" : 25
},
{
"key" : "tn",
"doc_count" : 23
},
{
"key" : "ma",
"doc_count" : 21
},
{
"key" : "nc",
"doc_count" : 21
},
{
"key" : "nd",
"doc_count" : 21
},
{
"key" : "me",
"doc_count" : 20
},
{
"key" : "mo",
"doc_count" : 20
}
]
}
}
}

Fielddata is disabled on text fields by default. Set fielddata=true on [gender] in order to load fielddata in memory by uninverting the inverted index. Note that this can however use significant memor的更多相关文章

  1. (转载)es进行聚合操作时提示Fielddata is disabled on text fields by default

    原文地址:http://blog.csdn.net/u011403655/article/details/71107415 根据es官网的文档执行 GET /megacorp/employee/_se ...

  2. (转)es进行聚合操作时提示Fielddata is disabled on text fields by default

    根据es官网的文档执行 GET /megacorp/employee/_search { "aggs": { "all_interests": { " ...

  3. Kibana创建索引成功,但一直不显示出来(Fielddata is disabled on text fields by default. Set fielddata=true........)

    现象 把EFK整个集群搭建完成后,通过Kibana操作界面创建索引(如图1),我创建了lile-zabbix*的索引,显示是创建成功了,但是只要我在重新刷新一次,已经创建的索引就“消失了”.后通过查看 ...

  4. Elasticsearch 报错: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.

    Elasticsearch 报错: Fielddata is disabled on text fields by default. Set `fielddata=true` on [`your_fi ...

  5. Elasticsearch 6.2.3版本 string 类型字段 排序 报错 Fielddata is disabled on text fields by default

    背景说明 最近在做一个 Elasticsearch 的分页查询,并且对查询结果按照特定字段进行排序的功能. 但是执行结果却报错,报错信息如下: { "error": { " ...

  6. Elasticsearch 6.2.3版本 执行聚合报错 Fielddata is disabled on text fields by default

    背景说明 执行<Elasticsearch 权威指南>的示例,在执行聚合查询的时候,报错 Fielddata is disabled on text fields by default. ...

  7. elasticsearch报Fielddata is disabled on text fields by default

    我刚玩elk没几天,今天启动kibana之后执行查询看见elasticsearch报了一个错误 Caused by: java.lang.IllegalArgumentException: Field ...

  8. Kibana error " Fielddata is disabled on text fields by default. Set fielddata=true on [publisher] ..."

    Reason of this error:Fielddata can consume a lot of heap space, especially when loading high cardina ...

  9. Fielddata is disabled on text fields by default Set fielddata=true on [service.address]

    2个字段的: PUT metricbeat-7.3.0/_mapping { "properties": { "service": { "proper ...

随机推荐

  1. java自动化测试-http请求结合抓包工具实际应用

    继上文我编写了java的get请求与post请求之后,我现在开始写一下实际操作 很多人有疑问,接口测试的代码是哪里来的,怎么来的呢?看得见吗?我来做一个简单的演示 我们这里简单介绍一下抓包工具,对于一 ...

  2. [置顶] win10 uwp 参考

    态度随意申请专栏,没想到通过 看了我的博客,都是在别的大神博客看到,然后修改他们的 我看到的大神博客 东邪独孤 http://www.cnblogs.com/tcjiaan/ 老周,买了他的<W ...

  3. Linux-Nand Flash驱动(分析MTD层并制作NAND驱动)

    1.本节使用的nand flash型号为K9F2G08U0M,它的命令如下: 1.1我们以上图的read id(读ID)为例,它的时序图如下: 首先需要使能CE片选 1)使能CLE 2)发送0X90命 ...

  4. 通过xrdp服务实现windows远程桌面连接树莓派

    如题:通过xrdp服务实现windows远程桌面连接树莓派 受同学影响,最近接触到了树莓派,又加上自己技痒想试一下这个小东西究竟能做什么,所以开始了树莓派学习之旅. 正题开始-xrdp实现window ...

  5. sphinx安装

    相关命令及步骤    创建主索引:        /usr/local/coreseek/bin/indexer -c /usr/local/coreseek/etc/csft.conf --all  ...

  6. javascript 之数据类型

    写在前面 国庆整理资料时,发现刚开始入门前端时学习JS 的资料,打算以一个基础入门博客记录下来,有不写不对的多多指教: 先推荐些书籍给需要的童鞋 <JavaScript 高级程序设计.pdf&g ...

  7. 【NOIP2016提高组】 Day1 T3 换教室

    题目链接:https://www.luogu.org/problemnew/show/P1850 此题正解为dp. 我们先用floyd处理出任意两个教室之间的距离,用dis[i][j]表示. 用f[i ...

  8. Maven优雅的添加第三方Jar包

    在利用Maven构建项目的时候会出现某些Jar包无法下载到本地的Repository中,鉴于这种情况比较普遍存在,特归纳以下解决问题办法:以 ojdbc14-10.2.0.4.0.jar为例[其它Ja ...

  9. .NET程序集引用COM组件MSScriptControl所遇到的问题

    问题描述:为了在C#中执行js脚本,在一个目标平台编译为Any Cpu的.NET程序集中引用了MSScriptControl组件,在winform程序中,调用这个程序集中的执行js的方法,没有任何问题 ...

  10. Python学习笔记(五)--Python数据类型-数字及字符串

    Python数据类型:123和'123'一样吗?>>> 123=='123'False>>> type(123)<type 'int'>>> ...