首页 > 解决方案 > 无法对字段 elasticsearch SQL 执行 COUNT 和 GROUP BY 操作

问题描述

我正在使用Elasticsearch SQL从canvas[Kibana]的 elasticsearch索引中获取数据以进行可视化。

这是我的ESSQL查询:

SELECT COUNT(status), status FROM "indexName" GROUP BY status

注意:字段状态文本类型

当我尝试执行此查询时,发生以下错误:

[essql] > Unexpected error from Elasticsearch:
[verification_exception] Found 1 problem(s) line 1:57: Field [status]
of data type [text] cannot be used for grouping;
No keyword/multi-field defined exact matches for [status]; define one
or use MATCH/QUERY instead

提前致谢。

标签: sqlelasticsearchkibana

解决方案


我认为这是因为您不允许对文本字段进行计数或执行聚合。错误描述中也提到了相同的内容,您得到“[verification_exception] Found 1 problem(s) line 1:57: Field [status] of data type [text] cannot be used for grouping;”

AFAIK 弹性搜索将文本字段的内容标记为倒排索引。因此,像“a room full of brooms”这样的文本将被索引为“a”、“room”、“full”、“of”、“brooms”。

这也取决于所使用的分析仪的类型。 https://www.elastic.co/guide/en/elasticsearch/reference/current/analysis-analyzers.html


推荐阅读