Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[8.x] ES|QL categorize docs (#117827) #117838

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 14 additions & 0 deletions docs/reference/esql/functions/examples/categorize.asciidoc

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions docs/reference/esql/functions/grouping-functions.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ The <<esql-stats-by>> command supports these grouping functions:

// tag::group_list[]
* <<esql-bucket>>
* experimental:[] <<esql-categorize>>
// end::group_list[]

include::layout/bucket.asciidoc[]
include::layout/categorize.asciidoc[]

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 5 additions & 1 deletion docs/reference/esql/functions/kibana/docs/categorize.md

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions docs/reference/esql/functions/layout/categorize.asciidoc

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -676,3 +676,20 @@ Ahmedabad | 9 | 72
Bangalore | 9 | 72
// end::bitLength-result[]
;

docsCategorize
required_capability: categorize_v4
// tag::docsCategorize[]
FROM sample_data
| STATS count=COUNT() BY category=CATEGORIZE(message)
// end::docsCategorize[]
| SORT category
;

// tag::docsCategorize-result[]
count:long | category:keyword
3 | .*?Connected.+?to.*?
3 | .*?Connection.+?error.*?
1 | .*?Disconnected.*?
// end::docsCategorize-result[]
;
Original file line number Diff line number Diff line change
Expand Up @@ -265,7 +265,9 @@ public Collection<FunctionDefinition> listFunctions(String pattern) {
private static FunctionDefinition[][] functions() {
return new FunctionDefinition[][] {
// grouping functions
new FunctionDefinition[] { def(Bucket.class, Bucket::new, "bucket", "bin"), },
new FunctionDefinition[] {
def(Bucket.class, Bucket::new, "bucket", "bin"),
def(Categorize.class, Categorize::new, "categorize") },
// aggregate functions
// since they declare two public constructors - one with filter (for nested where) and one without
// use casting to disambiguate between the two
Expand Down Expand Up @@ -411,7 +413,6 @@ private static FunctionDefinition[][] snapshotFunctions() {
// The delay() function is for debug/snapshot environments only and should never be enabled in a non-snapshot build.
// This is an experimental function and can be removed without notice.
def(Delay.class, Delay::new, "delay"),
def(Categorize.class, Categorize::new, "categorize"),
def(Kql.class, Kql::new, "kql"),
def(Rate.class, Rate::withUnresolvedTimestamp, "rate") } };
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import org.elasticsearch.xpack.esql.core.tree.NodeInfo;
import org.elasticsearch.xpack.esql.core.tree.Source;
import org.elasticsearch.xpack.esql.core.type.DataType;
import org.elasticsearch.xpack.esql.expression.function.Example;
import org.elasticsearch.xpack.esql.expression.function.FunctionInfo;
import org.elasticsearch.xpack.esql.expression.function.Param;
import org.elasticsearch.xpack.esql.io.stream.PlanStreamInput;
Expand Down Expand Up @@ -44,10 +45,21 @@ public class Categorize extends GroupingFunction implements Validatable {

private final Expression field;

@FunctionInfo(returnType = "keyword", description = "Categorizes text messages.")
@FunctionInfo(
returnType = "keyword",
description = "Groups text messages into categories of similarly formatted text values.",
examples = {
@Example(
file = "docs",
tag = "docsCategorize",
description = "This example categorizes server logs messages into categories and aggregates their counts. "
) },
preview = true
)
public Categorize(
Source source,
@Param(name = "field", type = { "text", "keyword" }, description = "Expression to categorize") Expression field

) {
super(source, List.of(field));
this.field = field;
Expand Down