
Elasticsearch7.x聚合查询发生异常
发布日期:2021-05-08 20:14:30
浏览次数:20
分类:原创文章
本文共 2722 字,大约阅读时间需要 9 分钟。
es 聚合查询,根据tags字段进行聚合查询
GET /ecommerce/product/_search{ "aggs":{ "group_by_tags" :{ "terms": { "field": "tags" } } }}
发生异常
Text fields are not optimised for operations that require per-document field data like aggregations and sorting, so these operations are disabled by default. Please use a keyword field instead. Alternatively, set fielddata=true on [tags] in order to load field data by uninverting the inverted index. Note that this can use significant memory.
完整错误信息:
{ "error" : { "root_cause" : [ { "type" : "illegal_argument_exception", "reason" : "Text fields are not optimised for operations that require per-document field data like aggregations and sorting, so these operations are disabled by default. Please use a keyword field instead. Alternatively, set fielddata=true on [tags] in order to load field data by uninverting the inverted index. Note that this can use significant memory." } ], "type" : "search_phase_execution_exception", "reason" : "all shards failed", "phase" : "query", "grouped" : true, "failed_shards" : [ { "shard" : 0, "index" : "ecommerce", "node" : "jxkP5bULTYaYdJ0k9GWdPw", "reason" : { "type" : "illegal_argument_exception", "reason" : "Text fields are not optimised for operations that require per-document field data like aggregations and sorting, so these operations are disabled by default. Please use a keyword field instead. Alternatively, set fielddata=true on [tags] in order to load field data by uninverting the inverted index. Note that this can use significant memory." } } ], "caused_by" : { "type" : "illegal_argument_exception", "reason" : "Text fields are not optimised for operations that require per-document field data like aggregations and sorting, so these operations are disabled by default. Please use a keyword field instead. Alternatively, set fielddata=true on [tags] in order to load field data by uninverting the inverted index. Note that this can use significant memory.", "caused_by" : { "type" : "illegal_argument_exception", "reason" : "Text fields are not optimised for operations that require per-document field data like aggregations and sorting, so these operations are disabled by default. Please use a keyword field instead. Alternatively, set fielddata=true on [tags] in order to load field data by uninverting the inverted index. Note that this can use significant memory." } } }, "status" : 400}
解决办法: 更新索引mapping,将需要聚合的字段fielddata设置为true
#修改索引的mappingPUT /ecommerce/_mapping{ "properties" : { "tags" : { "type":"text", "fielddata": true } }}
发表评论
最新留言
路过按个爪印,很不错,赞一个!
[***.219.124.196]2025年04月14日 08时11分36秒
关于作者

喝酒易醉,品茶养心,人生如梦,品茶悟道,何以解忧?唯有杜康!
-- 愿君每日到此一游!
推荐文章
项目中常用的审计类型概述
2019-03-05
(九)实现页面底部购物车的样式
2019-03-05
python-day3 for语句完整使用
2019-03-05
基于LabVIEW的入门指南
2019-03-05
weblogic之cve-2015-4852
2019-03-05
Java注释
2019-03-05
C++ 函数重载
2019-03-05
使用mybatis-generator生成底层
2019-03-05
Mybatis【5】-- Mybatis多种增删改查那些你会了么?
2019-03-05
计算输入的一句英文语句中单词数
2019-03-05
lvs+keepalive构建高可用集群
2019-03-05
6 个 Linux 运维典型问题
2019-03-05
取消vim打开文件全是黄色方法
2019-03-05
一个系统部署多个tomcat实例
2019-03-05
HP服务器设置iLO
2019-03-05
从头实现一个WPF条形图
2019-03-05
使用QT实现一个简单的登陆对话框(纯代码实现C++)
2019-03-05
QT :warning LNK4042: 对象被多次指定;已忽略多余的指定
2019-03-05
GLFW 源码 下载-编译-使用/GLAD配置
2019-03-05