- Elasticsearch Guide: other versions:
- What is Elasticsearch?
- What’s new in 8.14
- Quickstart
- Set up Elasticsearch
- Installing Elasticsearch
- Configuring Elasticsearch
- Important Elasticsearch configuration
- Secure settings
- Auditing settings
- Circuit breaker settings
- Cluster-level shard allocation and routing settings
- Miscellaneous cluster settings
- Cross-cluster replication settings
- Discovery and cluster formation settings
- Field data cache settings
- Health Diagnostic settings
- Index lifecycle management settings
- Data stream lifecycle settings
- Index management settings
- Index recovery settings
- Indexing buffer settings
- License settings
- Local gateway settings
- Logging
- Machine learning settings
- Monitoring settings
- Nodes
- Networking
- Node query cache settings
- Search settings
- Security settings
- Shard allocation, relocation, and recovery
- Shard request cache settings
- Snapshot and restore settings
- Transforms settings
- Thread pools
- Watcher settings
- Advanced configuration
- Important system configuration
- Bootstrap Checks
- Heap size check
- File descriptor check
- Memory lock check
- Maximum number of threads check
- Max file size check
- Maximum size virtual memory check
- Maximum map count check
- Client JVM check
- Use serial collector check
- System call filter check
- OnError and OnOutOfMemoryError checks
- Early-access check
- All permission check
- Discovery configuration check
- Bootstrap Checks for X-Pack
- Starting Elasticsearch
- Stopping Elasticsearch
- Discovery and cluster formation
- Add and remove nodes in your cluster
- Full-cluster restart and rolling restart
- Remote clusters
- Plugins
- Upgrade Elasticsearch
- Index modules
- Mapping
- Dynamic mapping
- Explicit mapping
- Runtime fields
- Field data types
- Aggregate metric
- Alias
- Arrays
- Binary
- Boolean
- Completion
- Date
- Date nanoseconds
- Dense vector
- Flattened
- Geopoint
- Geoshape
- Histogram
- IP
- Join
- Keyword
- Nested
- Numeric
- Object
- Percolator
- Point
- Range
- Rank feature
- Rank features
- Search-as-you-type
- Semantic text
- Shape
- Sparse vector
- Text
- Token count
- Unsigned long
- Version
- Metadata fields
- Mapping parameters
- Mapping limit settings
- Removal of mapping types
- Text analysis
- Overview
- Concepts
- Configure text analysis
- Built-in analyzer reference
- Tokenizer reference
- Token filter reference
- Apostrophe
- ASCII folding
- CJK bigram
- CJK width
- Classic
- Common grams
- Conditional
- Decimal digit
- Delimited payload
- Dictionary decompounder
- Edge n-gram
- Elision
- Fingerprint
- Flatten graph
- Hunspell
- Hyphenation decompounder
- Keep types
- Keep words
- Keyword marker
- Keyword repeat
- KStem
- Length
- Limit token count
- Lowercase
- MinHash
- Multiplexer
- N-gram
- Normalization
- Pattern capture
- Pattern replace
- Phonetic
- Porter stem
- Predicate script
- Remove duplicates
- Reverse
- Shingle
- Snowball
- Stemmer
- Stemmer override
- Stop
- Synonym
- Synonym graph
- Trim
- Truncate
- Unique
- Uppercase
- Word delimiter
- Word delimiter graph
- Character filters reference
- Normalizers
- Index templates
- Data streams
- Ingest pipelines
- Example: Parse logs
- Enrich your data
- Processor reference
- Append
- Attachment
- Bytes
- Circle
- Community ID
- Convert
- CSV
- Date
- Date index name
- Dissect
- Dot expander
- Drop
- Enrich
- Fail
- Fingerprint
- Foreach
- Geo-grid
- GeoIP
- Grok
- Gsub
- HTML strip
- Inference
- Join
- JSON
- KV
- Lowercase
- Network direction
- Pipeline
- Redact
- Registered domain
- Remove
- Rename
- Reroute
- Script
- Set
- Set security user
- Sort
- Split
- Trim
- Uppercase
- URL decode
- URI parts
- User agent
- Ingest pipelines in Search
- Aliases
- Search your data
- Query DSL
- Aggregations
- Bucket aggregations
- Adjacency matrix
- Auto-interval date histogram
- Categorize text
- Children
- Composite
- Date histogram
- Date range
- Diversified sampler
- Filter
- Filters
- Frequent item sets
- Geo-distance
- Geohash grid
- Geohex grid
- Geotile grid
- Global
- Histogram
- IP prefix
- IP range
- Missing
- Multi Terms
- Nested
- Parent
- Random sampler
- Range
- Rare terms
- Reverse nested
- Sampler
- Significant terms
- Significant text
- Terms
- Time series
- Variable width histogram
- Subtleties of bucketing range fields
- Metrics aggregations
- Pipeline aggregations
- Average bucket
- Bucket script
- Bucket count K-S test
- Bucket correlation
- Bucket selector
- Bucket sort
- Change point
- Cumulative cardinality
- Cumulative sum
- Derivative
- Extended stats bucket
- Inference bucket
- Max bucket
- Min bucket
- Moving function
- Moving percentiles
- Normalize
- Percentiles bucket
- Serial differencing
- Stats bucket
- Sum bucket
- Bucket aggregations
- Geospatial analysis
- EQL
- ES|QL
- SQL
- Overview
- Getting Started with SQL
- Conventions and Terminology
- Security
- SQL REST API
- SQL Translate API
- SQL CLI
- SQL JDBC
- SQL ODBC
- SQL Client Applications
- SQL Language
- Functions and Operators
- Comparison Operators
- Logical Operators
- Math Operators
- Cast Operators
- LIKE and RLIKE Operators
- Aggregate Functions
- Grouping Functions
- Date/Time and Interval Functions and Operators
- Full-Text Search Functions
- Mathematical Functions
- String Functions
- Type Conversion Functions
- Geo Functions
- Conditional Functions And Expressions
- System Functions
- Reserved keywords
- SQL Limitations
- Scripting
- Data management
- ILM: Manage the index lifecycle
- Tutorial: Customize built-in policies
- Tutorial: Automate rollover
- Index management in Kibana
- Overview
- Concepts
- Index lifecycle actions
- Configure a lifecycle policy
- Migrate index allocation filters to node roles
- Troubleshooting index lifecycle management errors
- Start and stop index lifecycle management
- Manage existing indices
- Skip rollover
- Restore a managed data stream or index
- Data tiers
- Autoscaling
- Monitor a cluster
- Roll up or transform your data
- Set up a cluster for high availability
- Snapshot and restore
- Secure the Elastic Stack
- Elasticsearch security principles
- Start the Elastic Stack with security enabled automatically
- Manually configure security
- Updating node security certificates
- User authentication
- Built-in users
- Service accounts
- Internal users
- Token-based authentication services
- User profiles
- Realms
- Realm chains
- Security domains
- Active Directory user authentication
- File-based user authentication
- LDAP user authentication
- Native user authentication
- OpenID Connect authentication
- PKI user authentication
- SAML authentication
- Kerberos authentication
- JWT authentication
- Integrating with other authentication systems
- Enabling anonymous access
- Looking up users without authentication
- Controlling the user cache
- Configuring SAML single-sign-on on the Elastic Stack
- Configuring single sign-on to the Elastic Stack using OpenID Connect
- User authorization
- Built-in roles
- Defining roles
- Role restriction
- Security privileges
- Document level security
- Field level security
- Granting privileges for data streams and aliases
- Mapping users and groups to roles
- Setting up field and document level security
- Submitting requests on behalf of other users
- Configuring authorization delegation
- Customizing roles and authorization
- Enable audit logging
- Restricting connections with IP filtering
- Securing clients and integrations
- Operator privileges
- Troubleshooting
- Some settings are not returned via the nodes settings API
- Authorization exceptions
- Users command fails due to extra arguments
- Users are frequently locked out of Active Directory
- Certificate verification fails for curl on Mac
- SSLHandshakeException causes connections to fail
- Common SSL/TLS exceptions
- Common Kerberos exceptions
- Common SAML issues
- Internal Server Error in Kibana
- Setup-passwords command fails due to connection failure
- Failures due to relocation of the configuration files
- Limitations
- Watcher
- Command line tools
- elasticsearch-certgen
- elasticsearch-certutil
- elasticsearch-create-enrollment-token
- elasticsearch-croneval
- elasticsearch-keystore
- elasticsearch-node
- elasticsearch-reconfigure-node
- elasticsearch-reset-password
- elasticsearch-saml-metadata
- elasticsearch-service-tokens
- elasticsearch-setup-passwords
- elasticsearch-shard
- elasticsearch-syskeygen
- elasticsearch-users
- How to
- Troubleshooting
- Fix common cluster issues
- Diagnose unassigned shards
- Add a missing tier to the system
- Allow Elasticsearch to allocate the data in the system
- Allow Elasticsearch to allocate the index
- Indices mix index allocation filters with data tiers node roles to move through data tiers
- Not enough nodes to allocate all shard replicas
- Total number of shards for an index on a single node exceeded
- Total number of shards per node has been reached
- Troubleshooting corruption
- Fix data nodes out of disk
- Fix master nodes out of disk
- Fix other role nodes out of disk
- Start index lifecycle management
- Start Snapshot Lifecycle Management
- Restore from snapshot
- Troubleshooting broken repositories
- Addressing repeated snapshot policy failures
- Troubleshooting an unstable cluster
- Troubleshooting discovery
- Troubleshooting monitoring
- Troubleshooting transforms
- Troubleshooting Watcher
- Troubleshooting searches
- Troubleshooting shards capacity health issues
- Troubleshooting an unbalanced cluster
- Capture diagnostics
- REST APIs
- API conventions
- Common options
- REST API compatibility
- Autoscaling APIs
- Behavioral Analytics APIs
- Compact and aligned text (CAT) APIs
- cat aliases
- cat allocation
- cat anomaly detectors
- cat component templates
- cat count
- cat data frame analytics
- cat datafeeds
- cat fielddata
- cat health
- cat indices
- cat master
- cat nodeattrs
- cat nodes
- cat pending tasks
- cat plugins
- cat recovery
- cat repositories
- cat segments
- cat shards
- cat snapshots
- cat task management
- cat templates
- cat thread pool
- cat trained model
- cat transforms
- Cluster APIs
- Cluster allocation explain
- Cluster get settings
- Cluster health
- Health
- Cluster reroute
- Cluster state
- Cluster stats
- Cluster update settings
- Nodes feature usage
- Nodes hot threads
- Nodes info
- Prevalidate node removal
- Nodes reload secure settings
- Nodes stats
- Cluster Info
- Pending cluster tasks
- Remote cluster info
- Task management
- Voting configuration exclusions
- Create or update desired nodes
- Get desired nodes
- Delete desired nodes
- Get desired balance
- Reset desired balance
- Cross-cluster replication APIs
- Connector APIs
- Create connector
- Delete connector
- Get connector
- List connectors
- Update connector API key id
- Update connector configuration
- Update connector index name
- Update connector filtering
- Update connector name and description
- Update connector pipeline
- Update connector scheduling
- Update connector service type
- Create connector sync job
- Cancel connector sync job
- Delete connector sync job
- Get connector sync job
- List connector sync jobs
- Check in a connector
- Update connector error
- Update connector last sync stats
- Update connector status
- Check in connector sync job
- Set connector sync job error
- Set connector sync job stats
- Data stream APIs
- Document APIs
- Enrich APIs
- EQL APIs
- ES|QL APIs
- Features APIs
- Fleet APIs
- Graph explore API
- Index APIs
- Alias exists
- Aliases
- Analyze
- Analyze index disk usage
- Clear cache
- Clone index
- Close index
- Create index
- Create or update alias
- Create or update component template
- Create or update index template
- Create or update index template (legacy)
- Delete component template
- Delete dangling index
- Delete alias
- Delete index
- Delete index template
- Delete index template (legacy)
- Exists
- Field usage stats
- Flush
- Force merge
- Get alias
- Get component template
- Get field mapping
- Get index
- Get index settings
- Get index template
- Get index template (legacy)
- Get mapping
- Import dangling index
- Index recovery
- Index segments
- Index shard stores
- Index stats
- Index template exists (legacy)
- List dangling indices
- Open index
- Refresh
- Resolve index
- Resolve cluster
- Rollover
- Shrink index
- Simulate index
- Simulate template
- Split index
- Unfreeze index
- Update index settings
- Update mapping
- Index lifecycle management APIs
- Create or update lifecycle policy
- Get policy
- Delete policy
- Move to step
- Remove policy
- Retry policy
- Get index lifecycle management status
- Explain lifecycle
- Start index lifecycle management
- Stop index lifecycle management
- Migrate indices, ILM policies, and legacy, composable and component templates to data tiers routing
- Inference APIs
- Info API
- Ingest APIs
- Licensing APIs
- Logstash APIs
- Machine learning APIs
- Machine learning anomaly detection APIs
- Add events to calendar
- Add jobs to calendar
- Close jobs
- Create jobs
- Create calendars
- Create datafeeds
- Create filters
- Delete calendars
- Delete datafeeds
- Delete events from calendar
- Delete filters
- Delete forecasts
- Delete jobs
- Delete jobs from calendar
- Delete model snapshots
- Delete expired data
- Estimate model memory
- Flush jobs
- Forecast jobs
- Get buckets
- Get calendars
- Get categories
- Get datafeeds
- Get datafeed statistics
- Get influencers
- Get jobs
- Get job statistics
- Get model snapshots
- Get model snapshot upgrade statistics
- Get overall buckets
- Get scheduled events
- Get filters
- Get records
- Open jobs
- Post data to jobs
- Preview datafeeds
- Reset jobs
- Revert model snapshots
- Start datafeeds
- Stop datafeeds
- Update datafeeds
- Update filters
- Update jobs
- Update model snapshots
- Upgrade model snapshots
- Machine learning data frame analytics APIs
- Create data frame analytics jobs
- Delete data frame analytics jobs
- Evaluate data frame analytics
- Explain data frame analytics
- Get data frame analytics jobs
- Get data frame analytics jobs stats
- Preview data frame analytics
- Start data frame analytics jobs
- Stop data frame analytics jobs
- Update data frame analytics jobs
- Machine learning trained model APIs
- Clear trained model deployment cache
- Create or update trained model aliases
- Create part of a trained model
- Create trained models
- Create trained model vocabulary
- Delete trained model aliases
- Delete trained models
- Get trained models
- Get trained models stats
- Infer trained model
- Start trained model deployment
- Stop trained model deployment
- Update trained model deployment
- Migration APIs
- Node lifecycle APIs
- Query rules APIs
- Reload search analyzers API
- Repositories metering APIs
- Rollup APIs
- Root API
- Script APIs
- Search APIs
- Search Application APIs
- Searchable snapshots APIs
- Security APIs
- Authenticate
- Change passwords
- Clear cache
- Clear roles cache
- Clear privileges cache
- Clear API key cache
- Clear service account token caches
- Create API keys
- Create or update application privileges
- Create or update role mappings
- Create or update roles
- Create or update users
- Create service account tokens
- Delegate PKI authentication
- Delete application privileges
- Delete role mappings
- Delete roles
- Delete service account token
- Delete users
- Disable users
- Enable users
- Enroll Kibana
- Enroll node
- Get API key information
- Get application privileges
- Get builtin privileges
- Get role mappings
- Get roles
- Get service accounts
- Get service account credentials
- Get Security settings
- Get token
- Get user privileges
- Get users
- Grant API keys
- Has privileges
- Invalidate API key
- Invalidate token
- OpenID Connect prepare authentication
- OpenID Connect authenticate
- OpenID Connect logout
- Query API key information
- Query User
- Update API key
- Update Security settings
- Bulk update API keys
- SAML prepare authentication
- SAML authenticate
- SAML logout
- SAML invalidate
- SAML complete logout
- SAML service provider metadata
- SSL certificate
- Activate user profile
- Disable user profile
- Enable user profile
- Get user profiles
- Suggest user profile
- Update user profile data
- Has privileges user profile
- Create Cross-Cluster API key
- Update Cross-Cluster API key
- Snapshot and restore APIs
- Snapshot lifecycle management APIs
- SQL APIs
- Synonyms APIs
- Text structure APIs
- Transform APIs
- Usage API
- Watcher APIs
- Definitions
- Migration guide
- Release notes
- Elasticsearch version 8.14.3
- Elasticsearch version 8.14.2
- Elasticsearch version 8.14.1
- Elasticsearch version 8.14.0
- Elasticsearch version 8.13.4
- Elasticsearch version 8.13.3
- Elasticsearch version 8.13.2
- Elasticsearch version 8.13.1
- Elasticsearch version 8.13.0
- Elasticsearch version 8.12.2
- Elasticsearch version 8.12.1
- Elasticsearch version 8.12.0
- Elasticsearch version 8.11.4
- Elasticsearch version 8.11.3
- Elasticsearch version 8.11.2
- Elasticsearch version 8.11.1
- Elasticsearch version 8.11.0
- Elasticsearch version 8.10.4
- Elasticsearch version 8.10.3
- Elasticsearch version 8.10.2
- Elasticsearch version 8.10.1
- Elasticsearch version 8.10.0
- Elasticsearch version 8.9.2
- Elasticsearch version 8.9.1
- Elasticsearch version 8.9.0
- Elasticsearch version 8.8.2
- Elasticsearch version 8.8.1
- Elasticsearch version 8.8.0
- Elasticsearch version 8.7.1
- Elasticsearch version 8.7.0
- Elasticsearch version 8.6.2
- Elasticsearch version 8.6.1
- Elasticsearch version 8.6.0
- Elasticsearch version 8.5.3
- Elasticsearch version 8.5.2
- Elasticsearch version 8.5.1
- Elasticsearch version 8.5.0
- Elasticsearch version 8.4.3
- Elasticsearch version 8.4.2
- Elasticsearch version 8.4.1
- Elasticsearch version 8.4.0
- Elasticsearch version 8.3.3
- Elasticsearch version 8.3.2
- Elasticsearch version 8.3.1
- Elasticsearch version 8.3.0
- Elasticsearch version 8.2.3
- Elasticsearch version 8.2.2
- Elasticsearch version 8.2.1
- Elasticsearch version 8.2.0
- Elasticsearch version 8.1.3
- Elasticsearch version 8.1.2
- Elasticsearch version 8.1.1
- Elasticsearch version 8.1.0
- Elasticsearch version 8.0.1
- Elasticsearch version 8.0.0
- Elasticsearch version 8.0.0-rc2
- Elasticsearch version 8.0.0-rc1
- Elasticsearch version 8.0.0-beta1
- Elasticsearch version 8.0.0-alpha2
- Elasticsearch version 8.0.0-alpha1
- Dependencies and versions
ES|QL commands
editES|QL commands
editSource commands
editAn ES|QL source command produces a table, typically with data from Elasticsearch. An ES|QL query must start with a source command.
ES|QL supports these source commands:
Processing commands
editES|QL processing commands change an input table by adding, removing, or changing rows and columns.
ES|QL supports these processing commands:
-
DISSECT
-
DROP
-
ENRICH
-
EVAL
-
GROK
-
KEEP
-
LIMIT
-
[preview]
This functionality is in technical preview and may be changed or removed in a future release. Elastic will work to fix any issues, but features in technical preview are not subject to the support SLA of official GA features.
MV_EXPAND
-
RENAME
-
SORT
-
STATS ... BY
-
WHERE
FROM
editSyntax
FROM index_pattern [METADATA fields]
Parameters
-
index_pattern
- A list of indices, data streams or aliases. Supports wildcards and date math.
-
fields
- A comma-separated list of metadata fields to retrieve.
Description
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.
By default, an ES|QL query without an explicit LIMIT
uses an implicit
limit of 1000. This applies to FROM
too. A FROM
command without LIMIT
:
FROM employees
is executed as:
FROM employees | LIMIT 1000
Examples
FROM employees
You can use date math to refer to indices, aliases and data streams. This can be useful for time series data, for example to access today’s index:
FROM <logs-{now/d}>
Use comma-separated lists or wildcards to query multiple data streams, indices, or aliases:
FROM employees-00001,other-employees-*
Use the format <remote_cluster_name>:<target>
to query data streams and indices
on remote clusters:
FROM cluster_one:employees-00001,cluster_two:other-employees-*
See using ES|QL across clusters.
Use the optional METADATA
directive to enable metadata fields:
FROM employees METADATA _id
ROW
editSyntax
ROW column1 = value1[, ..., columnN = valueN]
Parameters
-
columnX
- The column name.
-
valueX
- The value for the column. Can be a literal, an expression, or a function.
Description
The ROW
source command produces a row with one or more columns with values
that you specify. This can be useful for testing.
Examples
ROW a = 1, b = "two", c = null
a:integer | b:keyword | c:null |
---|---|---|
1 |
"two" |
null |
Use square brackets to create multi-value columns:
ROW a = [2, 1]
ROW
supports the use of functions:
ROW a = ROUND(1.23, 0)
SHOW
editSyntax
SHOW item
Parameters
-
item
-
Can only be
INFO
.
Description
The SHOW
source command returns information about the deployment and
its capabilities:
-
Use
SHOW INFO
to return the deployment’s version, build date and hash.
Examples
SHOW INFO
version | date | hash |
---|---|---|
8.13.0 |
2024-02-23T10:04:18.123117961Z |
04ba8c8db2507501c88f215e475de7b0798cb3b3 |
DISSECT
editSyntax
DISSECT input "pattern" [APPEND_SEPARATOR="<separator>"]
Parameters
-
input
-
The column that contains the string you want to structure. If the column has
multiple values,
DISSECT
will process each value. -
pattern
- A dissect pattern.
-
<separator>
- A string used as the separator between appended values, when using the append modifier.
Description
DISSECT
enables you to extract
structured data out of a string. DISSECT
matches the string against a
delimiter-based pattern, and extracts the specified keys as columns.
Refer to Process data with DISSECT
for the syntax of dissect patterns.
Examples
The following example parses a string that contains a timestamp, some text, and an IP address:
ROW a = "2023-01-23T12:15:00.000Z - some text - 127.0.0.1" | DISSECT a "%{date} - %{msg} - %{ip}" | KEEP date, msg, ip
date:keyword | msg:keyword | ip:keyword |
---|---|---|
2023-01-23T12:15:00.000Z |
some text |
127.0.0.1 |
By default, DISSECT
outputs keyword string columns. To convert to another
type, use Type conversion functions:
ROW a = "2023-01-23T12:15:00.000Z - some text - 127.0.0.1" | DISSECT a "%{date} - %{msg} - %{ip}" | KEEP date, msg, ip | EVAL date = TO_DATETIME(date)
msg:keyword | ip:keyword | date:date |
---|---|---|
some text |
127.0.0.1 |
2023-01-23T12:15:00.000Z |
DROP
editSyntax
DROP columns
Parameters
-
columns
- A comma-separated list of columns to remove. Supports wildcards.
Description
The DROP
processing command removes one or more columns.
Examples
FROM employees | DROP height
Rather than specify each column by name, you can use wildcards to drop all columns with a name that matches a pattern:
FROM employees | DROP height*
ENRICH
editSyntax
ENRICH policy [ON match_field] [WITH [new_name1 = ]field1, [new_name2 = ]field2, ...]
Parameters
-
policy
- The name of the enrich policy. You need to create and execute the enrich policy first.
-
mode
- The mode of the enrich command in cross cluster ES|QL. See enrich across clusters.
-
match_field
-
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 thematch_field
defined in the enrich policy. -
fieldX
- 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
-
new_nameX
- Enables you to change the name of the column that’s added for each of the enrich fields. Defaults to the enrich field name.
Description
ENRICH
enables you to add data from existing indices as new columns using an
enrich policy. Refer to Data enrichment for information about setting up a
policy.

Before you can use ENRICH
, you need to create
and execute an enrich policy.
Examples
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 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 based on the match field value.
ROW language_code = "1" | ENRICH languages_policy
language_code:keyword | language_name:keyword |
---|---|
1 |
English |
To use a column with a different name than the match_field
defined in the
policy as the match field, use ON <column-name>
:
ROW a = "1" | ENRICH languages_policy ON a
a:keyword | language_name:keyword |
---|---|
1 |
English |
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>, ...
:
ROW a = "1" | ENRICH languages_policy ON a WITH language_name
a:keyword | language_name:keyword |
---|---|
1 |
English |
You can rename the columns that are added using WITH new_name=<field1>
:
ROW a = "1" | ENRICH languages_policy ON a WITH name = language_name
a:keyword | name:keyword |
---|---|
1 |
English |
In case of name collisions, the newly created columns will override existing columns.
EVAL
editSyntax
EVAL [column1 =] value1[, ..., [columnN =] valueN]
Parameters
-
columnX
- The column name.
-
valueX
- The value for the column. Can be a literal, an expression, or a function.
Description
The EVAL
processing command enables you to append new columns with calculated
values. EVAL
supports various functions for calculating values. Refer to
Functions for more information.
Examples
FROM employees | SORT emp_no | KEEP first_name, last_name, height | EVAL height_feet = height * 3.281, height_cm = height * 100
first_name:keyword | last_name:keyword | height:double | height_feet:double | height_cm:double |
---|---|---|---|---|
Georgi |
Facello |
2.03 |
6.66043 |
202.99999999999997 |
Bezalel |
Simmel |
2.08 |
6.82448 |
208.0 |
Parto |
Bamford |
1.83 |
6.004230000000001 |
183.0 |
If the specified column already exists, the existing column will be dropped, and the new column will be appended to the table:
FROM employees | SORT emp_no | KEEP first_name, last_name, height | EVAL height = height * 3.281
first_name:keyword | last_name:keyword | height:double |
---|---|---|
Georgi |
Facello |
6.66043 |
Bezalel |
Simmel |
6.82448 |
Parto |
Bamford |
6.004230000000001 |
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
:
FROM employees | SORT emp_no | KEEP first_name, last_name, height | EVAL height * 3.281
first_name:keyword | last_name:keyword | height:double | height * 3.281:double |
---|---|---|---|
Georgi |
Facello |
2.03 |
6.66043 |
Bezalel |
Simmel |
2.08 |
6.82448 |
Parto |
Bamford |
1.83 |
6.004230000000001 |
Because this name contains special characters, it needs to be
quoted with backticks (`
) when using it in subsequent commands:
FROM employees | EVAL height * 3.281 | STATS avg_height_feet = AVG(`height * 3.281`)
avg_height_feet:double |
---|
5.801464200000001 |
GROK
editSyntax
GROK input "pattern"
Parameters
-
input
-
The column that contains the string you want to structure. If the column has
multiple values,
GROK
will process each value. -
pattern
- A grok pattern.
Description
GROK
enables you to extract
structured data out of a string. GROK
matches the string against patterns,
based on regular expressions, and extracts the specified patterns as columns.
Refer to Process data with GROK
for the syntax of grok patterns.
Examples
The following example parses a string that contains a timestamp, an IP address, an email address, and a number:
ROW a = "2023-01-23T12:15:00.000Z 127.0.0.1 some.email@foo.com 42" | GROK a "%{TIMESTAMP_ISO8601:date} %{IP:ip} %{EMAILADDRESS:email} %{NUMBER:num}" | KEEP date, ip, email, num
date:keyword | ip:keyword | email:keyword | num:keyword |
---|---|---|---|
2023-01-23T12:15:00.000Z |
127.0.0.1 |
42 |
By default, GROK
outputs keyword string columns. int
and float
types can
be converted by appending :type
to the semantics in the pattern. For example
{NUMBER:num:int}
:
ROW a = "2023-01-23T12:15:00.000Z 127.0.0.1 some.email@foo.com 42" | GROK a "%{TIMESTAMP_ISO8601:date} %{IP:ip} %{EMAILADDRESS:email} %{NUMBER:num:int}" | KEEP date, ip, email, num
date:keyword | ip:keyword | email:keyword | num:integer |
---|---|---|---|
2023-01-23T12:15:00.000Z |
127.0.0.1 |
42 |
For other type conversions, use Type conversion functions:
ROW a = "2023-01-23T12:15:00.000Z 127.0.0.1 some.email@foo.com 42" | GROK a "%{TIMESTAMP_ISO8601:date} %{IP:ip} %{EMAILADDRESS:email} %{NUMBER:num:int}" | KEEP date, ip, email, num | EVAL date = TO_DATETIME(date)
ip:keyword | email:keyword | num:integer | date:date |
---|---|---|---|
127.0.0.1 |
42 |
2023-01-23T12:15:00.000Z |
KEEP
editSyntax
KEEP columns
Parameters
-
columns
- A comma-separated list of columns to keep. Supports wildcards.
Description
The KEEP
processing command enables you to specify what columns are returned
and the order in which they are returned.
Precedence rules are applied when a field name matches multiple expressions. Fields are added in the order they appear. If one field matches multiple expressions, the following precedence rules apply (from highest to lowest priority):
- Complete field name (no wildcards)
-
Partial wildcard expressions (for example:
fieldNam*
) -
Wildcard only (
*
)
If a field matches two expressions with the same precedence, the right-most expression wins.
Refer to the examples for illustrations of these precedence rules.
Examples
The columns are returned in the specified order:
FROM employees | KEEP emp_no, first_name, last_name, height
emp_no:integer | first_name:keyword | last_name:keyword | height:double |
---|---|---|---|
10001 |
Georgi |
Facello |
2.03 |
10002 |
Bezalel |
Simmel |
2.08 |
10003 |
Parto |
Bamford |
1.83 |
10004 |
Chirstian |
Koblick |
1.78 |
10005 |
Kyoichi |
Maliniak |
2.05 |
Rather than specify each column by name, you can use wildcards to return all columns with a name that matches a pattern:
FROM employees | KEEP h*
height:double | height.float:double | height.half_float:double | height.scaled_float:double | hire_date:date |
---|
The asterisk wildcard (*
) by itself translates to all columns that do not
match the other arguments.
This query will first return all columns with a name
that starts with h
, followed by all other columns:
FROM employees | KEEP h*, *
height:double | height.float:double | height.half_float:double | height.scaled_float:double | hire_date:date | avg_worked_seconds:long | birth_date:date | emp_no:integer | first_name:keyword | gender:keyword | is_rehired:boolean | job_positions:keyword | languages:integer | languages.byte:integer | languages.long:long | languages.short:integer | last_name:keyword | salary:integer | salary_change:double | salary_change.int:integer | salary_change.keyword:keyword | salary_change.long:long | still_hired:boolean |
---|
The following examples show how precedence rules work when a field name matches multiple expressions.
Complete field name has precedence over wildcard expressions:
FROM employees | KEEP first_name, last_name, first_name*
first_name:keyword | last_name:keyword |
---|
Wildcard expressions have the same priority, but last one wins (despite being less specific):
FROM employees | KEEP first_name*, last_name, first_na*
last_name:keyword | first_name:keyword |
---|
A simple wildcard expression *
has the lowest precedence.
Output order is determined by the other arguments:
FROM employees | KEEP *, first_name
avg_worked_seconds:long | birth_date:date | emp_no:integer | gender:keyword | height:double | height.float:double | height.half_float:double | height.scaled_float:double | hire_date:date | is_rehired:boolean | job_positions:keyword | languages:integer | languages.byte:integer | languages.long:long | languages.short:integer | last_name:keyword | salary:integer | salary_change:double | salary_change.int:integer | salary_change.keyword:keyword | salary_change.long:long | still_hired:boolean | first_name:keyword |
---|
LIMIT
editSyntax
LIMIT max_number_of_rows
Parameters
-
max_number_of_rows
- The maximum number of rows to return.
Description
The LIMIT
processing command enables you to limit the number of rows that are
returned.
Queries do not return more than 10,000 rows, regardless of the LIMIT
command’s
value.
This limit only applies to the number of rows that are retrieved by the query. Queries and aggregations run on the full data set.
To overcome this limitation:
-
Reduce the result set size by modifying the query to only return relevant
data. Use
WHERE
to select a smaller subset of the data. -
Shift any post-query processing to the query itself. You can use the ES|QL
STATS ... BY
command to aggregate data in the query.
The default and maximum limits can be changed using these dynamic cluster settings:
-
esql.query.result_truncation_default_size
-
esql.query.result_truncation_max_size
Example
FROM employees | SORT emp_no ASC | LIMIT 5
MV_EXPAND
editThis functionality is in technical preview and may be changed or removed in a future release. Elastic will work to fix any issues, but features in technical preview are not subject to the support SLA of official GA features.
Syntax
MV_EXPAND column
Parameters
-
column
- The multivalued column to expand.
Description
The MV_EXPAND
processing command expands multivalued columns into one row per
value, duplicating other columns.
Example
ROW a=[1,2,3], b="b", j=["a","b"] | MV_EXPAND a
a:integer | b:keyword | j:keyword |
---|---|---|
1 |
b |
["a", "b"] |
2 |
b |
["a", "b"] |
3 |
b |
["a", "b"] |
RENAME
editSyntax
RENAME old_name1 AS new_name1[, ..., old_nameN AS new_nameN]
Parameters
-
old_nameX
- The name of a column you want to rename.
-
new_nameX
- The new name of the column.
Description
The RENAME
processing command renames one or more columns. If a column with
the new name already exists, it will be replaced by the new column.
Examples
FROM employees | KEEP first_name, last_name, still_hired | RENAME still_hired AS employed
Multiple columns can be renamed with a single RENAME
command:
FROM employees | KEEP first_name, last_name | RENAME first_name AS fn, last_name AS ln
SORT
editSyntax
SORT column1 [ASC/DESC][NULLS FIRST/NULLS LAST][, ..., columnN [ASC/DESC][NULLS FIRST/NULLS LAST]]
Parameters
-
columnX
- The column to sort on.
Description
The SORT
processing command sorts a table on one or more columns.
The default sort order is ascending. Use ASC
or DESC
to specify an explicit
sort order.
Two rows with the same sort key are considered equal. You can provide additional sort expressions to act as tie breakers.
Sorting on multivalued columns uses the lowest value when sorting ascending and the highest value when sorting descending.
By default, null
values are treated as being larger than any other value. With
an ascending sort order, null
values are sorted last, and with a descending
sort order, null
values are sorted first. You can change that by providing
NULLS FIRST
or NULLS LAST
.
Examples
FROM employees | KEEP first_name, last_name, height | SORT height
Explicitly sorting in ascending order with ASC
:
FROM employees | KEEP first_name, last_name, height | SORT height DESC
Providing additional sort expressions to act as tie breakers:
FROM employees | KEEP first_name, last_name, height | SORT height DESC, first_name ASC
Sorting null
values first using NULLS FIRST
:
FROM employees | KEEP first_name, last_name, height | SORT first_name ASC NULLS FIRST
STATS ... BY
editThe STATS ... BY
processing command groups rows according to a common value
and calculates one or more aggregated values over the grouped rows.
Syntax
STATS [column1 =] expression1[, ..., [columnN =] expressionN] [BY grouping_expression1[, ..., grouping_expressionN]]
Parameters
-
columnX
-
The name by which the aggregated value is returned. If omitted, the name is
equal to the corresponding expression (
expressionX
). -
expressionX
- An expression that computes an aggregated value.
-
grouping_expressionX
- An expression that outputs the values to group by.
Individual null
values are skipped when computing aggregations.
Description
The STATS ... BY
processing command groups rows according to a common value
and calculate one or more aggregated values over the grouped rows. If BY
is
omitted, the output table contains exactly one row with the aggregations applied
over the entire dataset.
The following aggregation functions are supported:
-
AVG
-
COUNT
-
COUNT_DISTINCT
-
MAX
-
MEDIAN
-
MEDIAN_ABSOLUTE_DEVIATION
-
MIN
-
PERCENTILE
-
[preview]
This functionality is in technical preview and may be changed or removed in a future release. Elastic will work to fix any issues, but features in technical preview are not subject to the support SLA of official GA features.
ST_CENTROID_AGG
-
SUM
-
VALUES
The following grouping functions are supported:
STATS
without any groups is much much faster than adding a group.
Grouping on a single expression is currently much more optimized than grouping
on many expressions. In some tests we have seen grouping on a single keyword
column to be five times faster than grouping on two keyword
columns. Do
not try to work around this by combining the two columns together with
something like CONCAT
and then grouping - that is not going to be
faster.
Examples
Calculating a statistic and grouping by the values of another column:
FROM employees | STATS count = COUNT(emp_no) BY languages | SORT languages
count:long | languages:integer |
---|---|
15 |
1 |
19 |
2 |
17 |
3 |
18 |
4 |
21 |
5 |
10 |
null |
Omitting BY
returns one row with the aggregations applied over the entire
dataset:
FROM employees | STATS avg_lang = AVG(languages)
avg_lang:double |
---|
3.1222222222222222 |
It’s possible to calculate multiple values:
FROM employees | STATS avg_lang = AVG(languages), max_lang = MAX(languages)
avg_lang:double | max_lang:integer |
---|---|
3.1222222222222222 |
5 |
It’s also possible to group by multiple values (only supported for long and keyword family fields):
FROM employees | EVAL hired = DATE_FORMAT("YYYY", hire_date) | STATS avg_salary = AVG(salary) BY hired, languages.long | EVAL avg_salary = ROUND(avg_salary) | SORT hired, languages.long
Both the aggregating functions and the grouping expressions accept other
functions. This is useful for using STATS...BY
on multivalue columns.
For example, to calculate the average salary change, you can use MV_AVG
to
first average the multiple values per employee, and use the result with the
AVG
function:
FROM employees | STATS avg_salary_change = ROUND(AVG(MV_AVG(salary_change)), 10)
avg_salary_change:double |
---|
1.3904535865 |
An example of grouping by an expression is grouping employees on the first letter of their last name:
FROM employees | STATS my_count = COUNT() BY LEFT(last_name, 1) | SORT `LEFT(last_name, 1)`
my_count:long | LEFT(last_name, 1):keyword |
---|---|
2 |
A |
11 |
B |
5 |
C |
5 |
D |
2 |
E |
4 |
F |
4 |
G |
6 |
H |
2 |
J |
3 |
K |
5 |
L |
12 |
M |
4 |
N |
1 |
O |
7 |
P |
5 |
R |
13 |
S |
4 |
T |
2 |
W |
3 |
Z |
Specifying the output column name is optional. If not specified, the new column
name is equal to the expression. The following query returns a column named
AVG(salary)
:
FROM employees | STATS AVG(salary)
AVG(salary):double |
---|
48248.55 |
Because this name contains special characters, it needs to be
quoted with backticks (`
) when using it in subsequent commands:
FROM employees | STATS AVG(salary) | EVAL avg_salary_rounded = ROUND(`AVG(salary)`)
AVG(salary):double | avg_salary_rounded:double |
---|---|
48248.55 |
48249.0 |
WHERE
editSyntax
WHERE expression
Parameters
-
expression
- A boolean expression.
Description
The WHERE
processing command produces a table that contains all the rows from
the input table for which the provided condition evaluates to true
.
Examples
FROM employees | KEEP first_name, last_name, still_hired | WHERE still_hired == true
Which, if still_hired
is a boolean field, can be simplified to:
FROM employees | KEEP first_name, last_name, still_hired | WHERE still_hired
Use date math to retrieve data from a specific time range. For example, to retrieve the last hour of logs:
FROM sample_data | WHERE @timestamp > NOW() - 1 hour
WHERE
supports various functions. For example the
LENGTH
function:
FROM employees | KEEP first_name, last_name, height | WHERE LENGTH(first_name) < 4
For a complete list of all functions, refer to Functions overview.
For NULL comparison, use the IS NULL
and IS NOT NULL
predicates:
FROM employees | WHERE birth_date IS NULL | KEEP first_name, last_name | SORT first_name | LIMIT 3
first_name:keyword | last_name:keyword |
---|---|
Basil |
Tramer |
Florian |
Syrotiuk |
Lucien |
Rosenbaum |
FROM employees | WHERE is_rehired IS NOT NULL | STATS COUNT(emp_no)
COUNT(emp_no):long |
---|
84 |
Use LIKE
to filter data based on string patterns using wildcards. LIKE
usually acts on a field placed on the left-hand side of the operator, but it can
also act on a constant (literal) expression. The right-hand side of the operator
represents the pattern.
The following wildcard characters are supported:
-
*
matches zero or more characters. -
?
matches one character.
FROM employees | WHERE first_name LIKE "?b*" | KEEP first_name, last_name
first_name:keyword | last_name:keyword |
---|---|
Ebbe |
Callaway |
Eberhardt |
Terkki |
Use RLIKE
to filter data based on string patterns using using
regular expressions. RLIKE
usually acts on a field placed on
the left-hand side of the operator, but it can also act on a constant (literal)
expression. The right-hand side of the operator represents the pattern.
FROM employees | WHERE first_name RLIKE ".leja.*" | KEEP first_name, last_name
first_name:keyword | last_name:keyword |
---|---|
Alejandro |
McAlpine |
The IN
operator allows testing whether a field or expression equals
an element in a list of literals, fields or expressions:
ROW a = 1, b = 4, c = 3 | WHERE c-a IN (3, b / 2, a)
a:integer | b:integer | c:integer |
---|---|---|
1 |
4 |
3 |
For a complete list of all operators, refer to Operators.
On this page