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    }  }}
上一篇:Linux上的 jdk1.8 安装配置
下一篇:Elasticsearch下载慢?分享百度云下载-ELK

发表评论

最新留言

路过按个爪印,很不错,赞一个!
[***.219.124.196]2025年04月14日 08时11分36秒