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内部类demo

    内部类主要有三种:静态内部类,实例内部类,局部变量内部类 1.静态内部类,该类被static修饰,并且是成员变量,它只能访问外部类被static修饰的方法以及字段(这种说法只局限于不再内部类中创建外部 ...

  2. Python实现采集wordpress整站数据的爬虫

    最近爱上了python,就非常喜欢使用python来练手,在上次的基础上完善一下代码,实现采集wordpress程序的网站的整站数据的爬虫程序,本站也是采用的wordpress,我就拿吾八哥网(htt ...

  3. Python Nose框架编写测试用例方法

    1. 关于Nose nose项目是于2005年发布的,也就是 py.test改名后的一年.它是由 Jason Pellerin 编写的,支持与 py.test 相同的测试习惯做法,但是这个包更容易安装 ...

  4. Call From master/192.168.128.135 to master:8485 failed on connection exception: java.net.ConnectException: Connection refused

    hadoop集群搭建了ha,初次启动正常,最近几天启动时偶尔发现,namenode1节点启动后一段时间(大约10几秒-半分钟左右),namenode1上namenode进程停掉,查看日志: -- :: ...

  5. 版本控制之四:SVN客户端重新设置帐号和密码(转)

    在第一次使用TortoiseSVN从服务器CheckOut的时候,会要求输入用户名和密码,这时输入框下面有个选项是保存认证信息,如果选了这个选项,那么以后就不用每次都输入一遍用户名密码了. 不过,如果 ...

  6. CodeForces 11D(状压DP 求图中环的个数)

    Given a simple graph, output the number of simple cycles in it. A simple cycle is a cycle with no re ...

  7. Circle

    Circle   Memory Limit: 32768KB   64bit IO Format: %lld & %llu Status Description Your task is so ...

  8. PHP基础入门(二)【PHP函数基础】

    PHP基础入门(二)--函数基础 了解 PHP基础入门详解(一) 后,给大家分享一下PHP的函数基础. 这部分主要讲的就是: 函数的声明与使用.PHP中变量的作用域.静态变量.函数的参数传递.变量函数 ...

  9. linux环境手动编译安装Nginx实践过程 附异常解决

    1.下载nginx源码包并解压 可在http://nginx.org/en/download.html下载.tar.gz的源码包,如(nginx-1.4.7.tar.gz) 或者使用云盘下载   ht ...

  10. HTML学习笔记 基础标签及css引用案例 第一节 (原创)参考使用表

    <!DOCTYPE html><!--头文件 不是标签 也没有结束,这是声明该文件为HTML5--><html lang="en"><!- ...