Skip to content

Commit 0f3eb18

Browse files
committed
Split commands into multiple pages
1 parent 44e31ac commit 0f3eb18

36 files changed

+1418
-1329
lines changed
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
## `DISSECT` [esql-dissect]
2+
3+
`DISSECT` enables you to [extract structured data out of a string](/reference/query-languages/esql/esql-process-data-with-dissect-grok.md).
4+
5+
**Syntax**
6+
7+
```esql
8+
DISSECT input "pattern" [APPEND_SEPARATOR="<separator>"]
9+
```
10+
11+
**Parameters**
12+
13+
`input`
14+
: The column that contains the string you want to structure. If the column has multiple values, `DISSECT` will process each value.
15+
16+
`pattern`
17+
: A [dissect pattern](/reference/query-languages/esql/esql-process-data-with-dissect-grok.md#esql-dissect-patterns). If a field name conflicts with an existing column, the existing column is dropped. If a field name is used more than once, only the rightmost duplicate creates a column.
18+
19+
`<separator>`
20+
: A string used as the separator between appended values, when using the [append modifier](/reference/query-languages/esql/esql-process-data-with-dissect-grok.md#esql-append-modifier).
21+
22+
**Description**
23+
24+
`DISSECT` enables you to [extract structured data out of a string](/reference/query-languages/esql/esql-process-data-with-dissect-grok.md). `DISSECT` matches the string against a delimiter-based pattern, and extracts the specified keys as columns.
25+
26+
Refer to [Process data with `DISSECT`](/reference/query-languages/esql/esql-process-data-with-dissect-grok.md#esql-process-data-with-dissect) for the syntax of dissect patterns.
27+
28+
**Examples**
29+
30+
The following example parses a string that contains a timestamp, some text, and an IP address:
31+
32+
```esql
33+
ROW a = "2023-01-23T12:15:00.000Z - some text - 127.0.0.1"
34+
| DISSECT a """%{date} - %{msg} - %{ip}"""
35+
| KEEP date, msg, ip
36+
```
37+
38+
| date:keyword | msg:keyword | ip:keyword |
39+
| --- | --- | --- |
40+
| 2023-01-23T12:15:00.000Z | some text | 127.0.0.1 |
41+
42+
By default, `DISSECT` outputs keyword string columns. To convert to another type, use [Type conversion functions](/reference/query-languages/esql/functions-operators/type-conversion-functions.md):
43+
44+
```esql
45+
ROW a = "2023-01-23T12:15:00.000Z - some text - 127.0.0.1"
46+
| DISSECT a """%{date} - %{msg} - %{ip}"""
47+
| KEEP date, msg, ip
48+
| EVAL date = TO_DATETIME(date)
49+
```
50+
51+
| msg:keyword | ip:keyword | date:date |
52+
| --- | --- | --- |
53+
| some text | 127.0.0.1 | 2023-01-23T12:15:00.000Z |
54+
55+
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
## `DROP` [esql-drop]
2+
3+
The `DROP` processing command removes one or more columns.
4+
5+
**Syntax**
6+
7+
```esql
8+
DROP columns
9+
```
10+
11+
**Parameters**
12+
13+
`columns`
14+
: A comma-separated list of columns to remove. Supports wildcards.
15+
16+
**Examples**
17+
18+
```esql
19+
FROM employees
20+
| DROP height
21+
```
22+
23+
Rather than specify each column by name, you can use wildcards to drop all columns with a name that matches a pattern:
24+
25+
```esql
26+
FROM employees
27+
| DROP height*
28+
```
29+
30+
Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
## `ENRICH` [esql-enrich]
2+
3+
`ENRICH` enables you to add data from existing indices as new columns using an enrich policy.
4+
5+
**Syntax**
6+
7+
```esql
8+
ENRICH policy [ON match_field] [WITH [new_name1 = ]field1, [new_name2 = ]field2, ...]
9+
```
10+
11+
**Parameters**
12+
13+
`policy`
14+
: The name of the enrich policy. You need to [create](/reference/query-languages/esql/esql-enrich-data.md#esql-set-up-enrich-policy) and [execute](/reference/query-languages/esql/esql-enrich-data.md#esql-execute-enrich-policy) the enrich policy first.
15+
16+
`mode`
17+
: The mode of the enrich command in cross cluster {{esql}}. See [enrich across clusters](docs-content://explore-analyze/query-filter/languages/esql-cross-clusters.md#ccq-enrich).
18+
19+
`match_field`
20+
: The match field. `ENRICH` uses its value to look for records in the enrich index. If not specified, the match will be performed on the column with the same name as the `match_field` defined in the [enrich policy](/reference/query-languages/esql/esql-enrich-data.md#esql-enrich-policy).
21+
22+
`fieldX`
23+
: The enrich fields from the enrich index that are added to the result as new columns. If a column with the same name as the enrich field already exists, the existing column will be replaced by the new column. If not specified, each of the enrich fields defined in the policy is added. A column with the same name as the enrich field will be dropped unless the enrich field is renamed.
24+
25+
`new_nameX`
26+
: Enables you to change the name of the column that’s added for each of the enrich fields. Defaults to the enrich field name. If a column has the same name as the new name, it will be discarded. If a name (new or original) occurs more than once, only the rightmost duplicate creates a new column.
27+
28+
**Description**
29+
30+
`ENRICH` enables you to add data from existing indices as new columns using an enrich policy. Refer to [Data enrichment](/reference/query-languages/esql/esql-enrich-data.md) for information about setting up a policy.
31+
32+
:::{image} /reference/query-languages/images/esql-enrich.png
33+
:alt: esql enrich
34+
:::
35+
36+
::::{tip}
37+
Before you can use `ENRICH`, you need to [create and execute an enrich policy](/reference/query-languages/esql/esql-enrich-data.md#esql-set-up-enrich-policy).
38+
::::
39+
40+
41+
**Examples**
42+
43+
The following example uses the `languages_policy` enrich policy to add a new column for each enrich field defined in the policy. The match is performed using the `match_field` defined in the [enrich policy](/reference/query-languages/esql/esql-enrich-data.md#esql-enrich-policy) and requires that the input table has a column with the same name (`language_code` in this example). `ENRICH` will look for records in the [enrich index](/reference/query-languages/esql/esql-enrich-data.md#esql-enrich-index) based on the match field value.
44+
45+
```esql
46+
ROW language_code = "1"
47+
| ENRICH languages_policy
48+
```
49+
50+
| language_code:keyword | language_name:keyword |
51+
| --- | --- |
52+
| 1 | English |
53+
54+
To use a column with a different name than the `match_field` defined in the policy as the match field, use `ON <column-name>`:
55+
56+
```esql
57+
ROW a = "1"
58+
| ENRICH languages_policy ON a
59+
```
60+
61+
| a:keyword | language_name:keyword |
62+
| --- | --- |
63+
| 1 | English |
64+
65+
By default, each of the enrich fields defined in the policy is added as a column. To explicitly select the enrich fields that are added, use `WITH <field1>, <field2>, ...`:
66+
67+
```esql
68+
ROW a = "1"
69+
| ENRICH languages_policy ON a WITH language_name
70+
```
71+
72+
| a:keyword | language_name:keyword |
73+
| --- | --- |
74+
| 1 | English |
75+
76+
You can rename the columns that are added using `WITH new_name=<field1>`:
77+
78+
```esql
79+
ROW a = "1"
80+
| ENRICH languages_policy ON a WITH name = language_name
81+
```
82+
83+
| a:keyword | name:keyword |
84+
| --- | --- |
85+
| 1 | English |
86+
87+
In case of name collisions, the newly created columns will override existing columns.
88+
89+
Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
## `EVAL` [esql-eval]
2+
3+
The `EVAL` processing command enables you to append new columns with calculated values.
4+
5+
**Syntax**
6+
7+
```esql
8+
EVAL [column1 =] value1[, ..., [columnN =] valueN]
9+
```
10+
11+
**Parameters**
12+
13+
`columnX`
14+
: The column name. If a column with the same name already exists, the existing column is dropped. If a column name is used more than once, only the rightmost duplicate creates a column.
15+
16+
`valueX`
17+
: The value for the column. Can be a literal, an expression, or a [function](/reference/query-languages/esql/esql-functions-operators.md#esql-functions). Can use columns defined left of this one.
18+
19+
**Description**
20+
21+
The `EVAL` processing command enables you to append new columns with calculated values. `EVAL` supports various functions for calculating values. Refer to [Functions](/reference/query-languages/esql/esql-functions-operators.md#esql-functions) for more information.
22+
23+
**Examples**
24+
25+
```esql
26+
FROM employees
27+
| SORT emp_no
28+
| KEEP first_name, last_name, height
29+
| EVAL height_feet = height * 3.281, height_cm = height * 100
30+
```
31+
32+
| first_name:keyword | last_name:keyword | height:double | height_feet:double | height_cm:double |
33+
| --- | --- | --- | --- | --- |
34+
| Georgi | Facello | 2.03 | 6.66043 | 202.99999999999997 |
35+
| Bezalel | Simmel | 2.08 | 6.82448 | 208.0 |
36+
| Parto | Bamford | 1.83 | 6.004230000000001 | 183.0 |
37+
38+
If the specified column already exists, the existing column will be dropped, and the new column will be appended to the table:
39+
40+
```esql
41+
FROM employees
42+
| SORT emp_no
43+
| KEEP first_name, last_name, height
44+
| EVAL height = height * 3.281
45+
```
46+
47+
| first_name:keyword | last_name:keyword | height:double |
48+
| --- | --- | --- |
49+
| Georgi | Facello | 6.66043 |
50+
| Bezalel | Simmel | 6.82448 |
51+
| Parto | Bamford | 6.004230000000001 |
52+
53+
Specifying the output column name is optional. If not specified, the new column name is equal to the expression. The following query adds a column named `height*3.281`:
54+
55+
```esql
56+
FROM employees
57+
| SORT emp_no
58+
| KEEP first_name, last_name, height
59+
| EVAL height * 3.281
60+
```
61+
62+
| first_name:keyword | last_name:keyword | height:double | height * 3.281:double |
63+
| --- | --- | --- | --- |
64+
| Georgi | Facello | 2.03 | 6.66043 |
65+
| Bezalel | Simmel | 2.08 | 6.82448 |
66+
| Parto | Bamford | 1.83 | 6.004230000000001 |
67+
68+
Because this name contains special characters, [it needs to be quoted](/reference/query-languages/esql/esql-syntax.md#esql-identifiers) with backticks (```) when using it in subsequent commands:
69+
70+
```esql
71+
FROM employees
72+
| EVAL height * 3.281
73+
| STATS avg_height_feet = AVG(`height * 3.281`)
74+
```
75+
76+
| avg_height_feet:double |
77+
| --- |
78+
| 5.801464200000001 |
79+
80+
Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
## `FROM` [esql-from]
2+
3+
The `FROM` source command returns a table with data from a data stream, index, or alias.
4+
5+
**Syntax**
6+
7+
```esql
8+
FROM index_pattern [METADATA fields]
9+
```
10+
11+
**Parameters**
12+
13+
`index_pattern`
14+
: A list of indices, data streams or aliases. Supports wildcards and date math.
15+
16+
`fields`
17+
: A comma-separated list of [metadata fields](/reference/query-languages/esql/esql-metadata-fields.md) to retrieve.
18+
19+
**Description**
20+
21+
The `FROM` source command returns a table with data from a data stream, index, or alias. Each row in the resulting table represents a document. Each column corresponds to a field, and can be accessed by the name of that field.
22+
23+
::::{note}
24+
By default, an {{esql}} query without an explicit [`LIMIT`](#esql-limit) uses an implicit limit of 1000. This applies to `FROM` too. A `FROM` command without `LIMIT`:
25+
26+
```esql
27+
FROM employees
28+
```
29+
30+
is executed as:
31+
32+
```esql
33+
FROM employees
34+
| LIMIT 1000
35+
```
36+
37+
::::
38+
39+
40+
**Examples**
41+
42+
```esql
43+
FROM employees
44+
```
45+
46+
You can use [date math](/reference/elasticsearch/rest-apis/api-conventions.md#api-date-math-index-names) to refer to indices, aliases and data streams. This can be useful for time series data, for example to access today’s index:
47+
48+
```esql
49+
FROM <logs-{now/d}>
50+
```
51+
52+
Use comma-separated lists or wildcards to [query multiple data streams, indices, or aliases](docs-content://explore-analyze/query-filter/languages/esql-multi-index.md):
53+
54+
```esql
55+
FROM employees-00001,other-employees-*
56+
```
57+
58+
Use the format `<remote_cluster_name>:<target>` to [query data streams and indices on remote clusters](docs-content://explore-analyze/query-filter/languages/esql-cross-clusters.md):
59+
60+
```esql
61+
FROM cluster_one:employees-00001,cluster_two:other-employees-*
62+
```
63+
64+
Use the optional `METADATA` directive to enable [metadata fields](/reference/query-languages/esql/esql-metadata-fields.md):
65+
66+
```esql
67+
FROM employees METADATA _id
68+
```
69+
70+
Use enclosing double quotes (`"`) or three enclosing double quotes (`"""`) to escape index names that contain special characters:
71+
72+
```esql
73+
FROM "this=that", """this[that"""
74+
```
75+
76+

0 commit comments

Comments
 (0)