Skip to content

Commit ddc8b95

Browse files
authored
ES|QL categorize docs (#117827)
* Move ES|QL categorize out of snapshot functions * Categorize docs * Add experimental + fix docs * Add experimental + fix docs
1 parent 49b707b commit ddc8b95

File tree

9 files changed

+64
-8
lines changed

9 files changed

+64
-8
lines changed

docs/reference/esql/functions/description/categorize.asciidoc

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

docs/reference/esql/functions/examples/categorize.asciidoc

Lines changed: 14 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

docs/reference/esql/functions/grouping-functions.asciidoc

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ The <<esql-stats-by>> command supports these grouping functions:
99

1010
// tag::group_list[]
1111
* <<esql-bucket>>
12+
* experimental:[] <<esql-categorize>>
1213
// end::group_list[]
1314

1415
include::layout/bucket.asciidoc[]
16+
include::layout/categorize.asciidoc[]

docs/reference/esql/functions/kibana/definition/categorize.json

Lines changed: 6 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

docs/reference/esql/functions/kibana/docs/categorize.md

Lines changed: 5 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

docs/reference/esql/functions/layout/categorize.asciidoc

Lines changed: 3 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

x-pack/plugin/esql/qa/testFixtures/src/main/resources/docs.csv-spec

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -676,3 +676,20 @@ Ahmedabad | 9 | 72
676676
Bangalore | 9 | 72
677677
// end::bitLength-result[]
678678
;
679+
680+
docsCategorize
681+
required_capability: categorize_v4
682+
// tag::docsCategorize[]
683+
FROM sample_data
684+
| STATS count=COUNT() BY category=CATEGORIZE(message)
685+
// end::docsCategorize[]
686+
| SORT category
687+
;
688+
689+
// tag::docsCategorize-result[]
690+
count:long | category:keyword
691+
3 | .*?Connected.+?to.*?
692+
3 | .*?Connection.+?error.*?
693+
1 | .*?Disconnected.*?
694+
// end::docsCategorize-result[]
695+
;

x-pack/plugin/esql/src/main/java/org/elasticsearch/xpack/esql/expression/function/EsqlFunctionRegistry.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -265,7 +265,9 @@ public Collection<FunctionDefinition> listFunctions(String pattern) {
265265
private static FunctionDefinition[][] functions() {
266266
return new FunctionDefinition[][] {
267267
// grouping functions
268-
new FunctionDefinition[] { def(Bucket.class, Bucket::new, "bucket", "bin"), },
268+
new FunctionDefinition[] {
269+
def(Bucket.class, Bucket::new, "bucket", "bin"),
270+
def(Categorize.class, Categorize::new, "categorize") },
269271
// aggregate functions
270272
// since they declare two public constructors - one with filter (for nested where) and one without
271273
// use casting to disambiguate between the two
@@ -411,7 +413,6 @@ private static FunctionDefinition[][] snapshotFunctions() {
411413
// The delay() function is for debug/snapshot environments only and should never be enabled in a non-snapshot build.
412414
// This is an experimental function and can be removed without notice.
413415
def(Delay.class, Delay::new, "delay"),
414-
def(Categorize.class, Categorize::new, "categorize"),
415416
def(Kql.class, Kql::new, "kql"),
416417
def(Rate.class, Rate::withUnresolvedTimestamp, "rate") } };
417418
}

x-pack/plugin/esql/src/main/java/org/elasticsearch/xpack/esql/expression/function/grouping/Categorize.java

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
import org.elasticsearch.xpack.esql.core.tree.NodeInfo;
1717
import org.elasticsearch.xpack.esql.core.tree.Source;
1818
import org.elasticsearch.xpack.esql.core.type.DataType;
19+
import org.elasticsearch.xpack.esql.expression.function.Example;
1920
import org.elasticsearch.xpack.esql.expression.function.FunctionInfo;
2021
import org.elasticsearch.xpack.esql.expression.function.Param;
2122
import org.elasticsearch.xpack.esql.io.stream.PlanStreamInput;
@@ -44,10 +45,21 @@ public class Categorize extends GroupingFunction implements Validatable {
4445

4546
private final Expression field;
4647

47-
@FunctionInfo(returnType = "keyword", description = "Categorizes text messages.")
48+
@FunctionInfo(
49+
returnType = "keyword",
50+
description = "Groups text messages into categories of similarly formatted text values.",
51+
examples = {
52+
@Example(
53+
file = "docs",
54+
tag = "docsCategorize",
55+
description = "This example categorizes server logs messages into categories and aggregates their counts. "
56+
) },
57+
preview = true
58+
)
4859
public Categorize(
4960
Source source,
5061
@Param(name = "field", type = { "text", "keyword" }, description = "Expression to categorize") Expression field
62+
5163
) {
5264
super(source, List.of(field));
5365
this.field = field;

0 commit comments

Comments
 (0)