Movatterモバイル変換


[0]ホーム

URL:


Loading

ES|QL string functions

ES|QL supports these string functions:

Syntax

Embedded

Parameters

string

String expression. Ifnull, the function returnsnull.

Description

Returns the bit length of a string.

Note

All strings are in UTF-8, so a single character can use multiple bytes.

Supported types

stringresult
keywordinteger
textinteger

Example

FROM airports| WHERE country == "India"| KEEP city| EVAL fn_length = LENGTH(city), fn_bit_length = BIT_LENGTH(city)
city:keywordfn_length:integerfn_bit_length:integer
Agwār548
Ahmedabad972
Bangalore972

BYTE_LENGTH

Syntax

Embedded
×Embedded

Parameters

string

String expression. Ifnull, the function returnsnull.

Description

Returns the byte length of a string.

Note

All strings are in UTF-8, so a single character can use multiple bytes.

Supported types

stringresult
keywordinteger
textinteger

Example

FROM airports| WHERE country == "India"| KEEP city| EVAL fn_length = LENGTH(city), fn_byte_length = BYTE_LENGTH(city)
city:keywordfn_length:integerfn_byte_length:integer
Agwār56
Ahmedabad99
Bangalore99

CONCAT

Syntax

Embedded
×Embedded

Parameters

string1
Strings to concatenate.
string2

Strings to concatenate.

Description

Concatenates two or more strings.

Supported types

string1string2result
keywordkeywordkeyword
keywordtextkeyword
textkeywordkeyword
texttextkeyword

Example

FROM employees| KEEP first_name, last_name| EVAL fullname = CONCAT(first_name, " ", last_name)
first_name:keywordlast_name:keywordfullname:keyword
AlejandroMcAlpineAlejandro McAlpine
AmabileGomatamAmabile Gomatam
AnnekePreusigAnneke Preusig

ENDS_WITH

Syntax

Embedded
×Embedded

Parameters

str
String expression. Ifnull, the function returnsnull.
suffix

String expression. Ifnull, the function returnsnull.

Description

Returns a boolean that indicates whether a keyword string ends with another string.

Supported types

strsuffixresult
keywordkeywordboolean
keywordtextboolean
textkeywordboolean
texttextboolean

Example

FROM employees| KEEP last_name| EVAL ln_E = ENDS_WITH(last_name, "d")
last_name:keywordln_E:boolean
Awdehfalse
Azumafalse
Baekfalse
Bamfordtrue
Bernatskyfalse

FROM_BASE64

Syntax

Embedded
×Embedded

Parameters

string

A base64 string.

Description

Decode a base64 string.

Supported types

stringresult
keywordkeyword
textkeyword

Example

ROW a = "ZWxhc3RpYw=="| EVAL d = FROM_BASE64(a)
a:keywordd:keyword
ZWxhc3RpYw==elastic

HASH

Syntax

Embedded
×Embedded

Parameters

algorithm
Hash algorithm to use.
input

Input to hash.

Description

Computes the hash of the input using various algorithms such as MD5, SHA, SHA-224, SHA-256, SHA-384, SHA-512.

Supported types

algorithminputresult
keywordkeywordkeyword
keywordtextkeyword
textkeywordkeyword
texttextkeyword

Example

FROM sample_data| WHERE message != "Connection error"| EVAL md5 = hash("md5", message), sha256 = hash("sha256", message)| KEEP message, md5, sha256
message:keywordmd5:keywordsha256:keyword
Connected to 10.1.0.1abd7d1ce2bb636842a29246b3512dcae6d8372129ad78770f7185554dd39864749a62690216460752d6c075fa38ad85c
Connected to 10.1.0.28f8f1cb60832d153f5b9ec6dc828b93fb0db24720f15857091b3c99f4c4833586d0ea3229911b8777efb8d917cf27e9a
Connected to 10.1.0.3912b6dc13503165a15de43304bb77c7875b0480188db8acc4d5cc666a51227eb2bc5b989cd8ca912609f33e0846eff57
Disconnectedef70e46fd3bbc21e3e1f0b6815e750c004dfac3671b494ad53fcd152f7a14511bfb35747278aad8ce254a0d6e4ba4718

LEFT

Syntax

Embedded
×Embedded

Parameters

string
The string from which to return a substring.
length

The number of characters to return.

Description

Returns the substring that extractslength chars fromstring starting from the left.

Supported types

stringlengthresult
keywordintegerkeyword
textintegerkeyword

Example

FROM employees| KEEP last_name| EVAL left = LEFT(last_name, 3)
last_name:keywordleft:keyword
AwdehAwd
AzumaAzu
BaekBae
BamfordBam
BernatskyBer

LENGTH

Syntax

Embedded
×Embedded

Parameters

string

String expression. Ifnull, the function returnsnull.

Description

Returns the character length of a string.

Note

All strings are in UTF-8, so a single character can use multiple bytes.

Supported types

stringresult
keywordinteger
textinteger

Example

FROM airports| WHERE country == "India"| KEEP city| EVAL fn_length = LENGTH(city)
city:keywordfn_length:integer
Agwār5
Ahmedabad9
Bangalore9

LOCATE

Syntax

Embedded

Parameters

string
An input string
substring
A substring to locate in the input string
start

The start index

Description

Returns an integer that indicates the position of a keyword substring within another string. Returns0 if the substring cannot be found. Note that string positions start from1.

Supported types

stringsubstringstartresult
keywordkeywordintegerinteger
keywordkeywordinteger
keywordtextintegerinteger
keywordtextinteger
textkeywordintegerinteger
textkeywordinteger
texttextintegerinteger
texttextinteger

Example

ROW a = "hello"| EVAL a_ll = LOCATE(a, "ll")
a:keyworda_ll:integer
hello3

Syntax

Embedded

Parameters

string

String expression. Ifnull, the function returnsnull.

Description

Removes leading whitespaces from a string.

Supported types

stringresult
keywordkeyword
textkeyword

Example

ROW message = "   some text  ",  color = " red "| EVAL message = LTRIM(message)| EVAL color = LTRIM(color)| EVAL message = CONCAT("'", message, "'")| EVAL color = CONCAT("'", color, "'")
message:keywordcolor:keyword
'some text ''red '

Syntax

Embedded

Parameters

input

Input to hash.

Description

Computes the MD5 hash of the input.

Supported types

inputresult
keywordkeyword
textkeyword

Example

FROM sample_data| WHERE message != "Connection error"| EVAL md5 = md5(message)| KEEP message, md5
message:keywordmd5:keyword
Connected to 10.1.0.1abd7d1ce2bb636842a29246b3512dcae
Connected to 10.1.0.28f8f1cb60832d153f5b9ec6dc828b93f
Connected to 10.1.0.3912b6dc13503165a15de43304bb77c78
Disconnectedef70e46fd3bbc21e3e1f0b6815e750c0

Syntax

Embedded

Parameters

string
String expression.
number

Number times to repeat.

Description

Returns a string constructed by concatenatingstring with itself the specifiednumber of times.

Supported types

stringnumberresult
keywordintegerkeyword
textintegerkeyword

Example

ROW a = "Hello!"| EVAL triple_a = REPEAT(a, 3)
a:keywordtriple_a:keyword
Hello!Hello!Hello!Hello!

Syntax

Embedded

Parameters

string
String expression.
regex
Regular expression.
newString

Replacement string.

Description

The function substitutes in the stringstr any match of the regular expressionregex with the replacement stringnewStr.

Supported types

stringregexnewStringresult
keywordkeywordkeywordkeyword
keywordkeywordtextkeyword
keywordtextkeywordkeyword
keywordtexttextkeyword
textkeywordkeywordkeyword
textkeywordtextkeyword
texttextkeywordkeyword
texttexttextkeyword

Example

This example replaces any occurrence of the word "World" with the word "Universe":

ROW str = "Hello World"| EVAL str = REPLACE(str, "World", "Universe")| KEEP str
str:keyword
Hello Universe

Syntax

Embedded

Parameters

str

String expression. Ifnull, the function returnsnull.

Description

Returns a new string representing the input string in reverse order.

Supported types

strresult
keywordkeyword
textkeyword

Examples

ROW message = "Some Text" | EVAL message_reversed = REVERSE(message);
message:keywordmessage_reversed:keyword
Some TexttxeT emoS

REVERSE works with unicode, too! It keeps unicode grapheme clusters together during reversal.

ROW bending_arts = "💧🪨🔥💨" | EVAL bending_arts_reversed = REVERSE(bending_arts);
bending_arts:keywordbending_arts_reversed:keyword
💧🪨🔥💨💨🔥🪨💧

Syntax

Embedded

Parameters

string
The string from which to returns a substring.
length

The number of characters to return.

Description

Return the substring that extractslength chars fromstr starting from the right.

Supported types

stringlengthresult
keywordintegerkeyword
textintegerkeyword

Example

FROM employees| KEEP last_name| EVAL right = RIGHT(last_name, 3)
last_name:keywordright:keyword
Awdehdeh
Azumauma
Baekaek
Bamfordord
Bernatskysky

Syntax

Embedded

Parameters

string

String expression. Ifnull, the function returnsnull.

Description

Removes trailing whitespaces from a string.

Supported types

stringresult
keywordkeyword
textkeyword

Example

ROW message = "   some text  ",  color = " red "| EVAL message = RTRIM(message)| EVAL color = RTRIM(color)| EVAL message = CONCAT("'", message, "'")| EVAL color = CONCAT("'", color, "'")
message:keywordcolor:keyword
' some text'' red'

Syntax

Embedded

Parameters

input

Input to hash.

Description

Computes the SHA1 hash of the input.

Supported types

inputresult
keywordkeyword
textkeyword

Example

FROM sample_data| WHERE message != "Connection error"| EVAL sha1 = sha1(message)| KEEP message, sha1
message:keywordsha1:keyword
Connected to 10.1.0.142b85531a79088036a17759db7d2de292b92f57f
Connected to 10.1.0.2d30db445da2e9237c9718d0c7e4fb7cbbe9c2cb4
Connected to 10.1.0.32733848d943809f0b10cad3e980763e88afb9853
Disconnected771e05f27b99fd59f638f41a7a4e977b1d4691fe

Syntax

Embedded

Parameters

input

Input to hash.

Description

Computes the SHA256 hash of the input.

Supported types

inputresult
keywordkeyword
textkeyword

Example

FROM sample_data| WHERE message != "Connection error"| EVAL sha256 = sha256(message)| KEEP message, sha256
message:keywordsha256:keyword
Connected to 10.1.0.16d8372129ad78770f7185554dd39864749a62690216460752d6c075fa38ad85c
Connected to 10.1.0.2b0db24720f15857091b3c99f4c4833586d0ea3229911b8777efb8d917cf27e9a
Connected to 10.1.0.375b0480188db8acc4d5cc666a51227eb2bc5b989cd8ca912609f33e0846eff57
Disconnected04dfac3671b494ad53fcd152f7a14511bfb35747278aad8ce254a0d6e4ba4718

Syntax

Embedded

Parameters

number

Number of spaces in result.

Description

Returns a string made ofnumber spaces.

Supported types

numberresult
integerkeyword

Example

ROW message = CONCAT("Hello", SPACE(1), "World!");
message:keyword
Hello World!

Syntax

Embedded

Parameters

string
String expression. Ifnull, the function returnsnull.
delim

Delimiter. Only single byte delimiters are currently supported.

Description

Split a single valued string into multiple strings.

Supported types

stringdelimresult
keywordkeywordkeyword
keywordtextkeyword
textkeywordkeyword
texttextkeyword

Example

ROW words="foo;bar;baz;qux;quux;corge"| EVAL word = SPLIT(words, ";")
words:keywordword:keyword
foo;bar;baz;qux;quux;corge[foo,bar,baz,qux,quux,corge]

Syntax

Embedded

Parameters

str
String expression. Ifnull, the function returnsnull.
prefix

String expression. Ifnull, the function returnsnull.

Description

Returns a boolean that indicates whether a keyword string starts with another string.

Supported types

strprefixresult
keywordkeywordboolean
keywordtextboolean
textkeywordboolean
texttextboolean

Example

FROM employees| KEEP last_name| EVAL ln_S = STARTS_WITH(last_name, "B")
last_name:keywordln_S:boolean
Awdehfalse
Azumafalse
Baektrue
Bamfordtrue
Bernatskytrue

Syntax

Embedded

Parameters

string
String expression. Ifnull, the function returnsnull.
start
Start position.
length

Length of the substring from the start position. Optional; if omitted, all positions afterstart are returned.

Description

Returns a substring of a string, specified by a start position and an optional length.

Supported types

stringstartlengthresult
keywordintegerintegerkeyword
textintegerintegerkeyword

Examples

This example returns the first three characters of every last name:

FROM employees| KEEP last_name| EVAL ln_sub = SUBSTRING(last_name, 1, 3)
last_name:keywordln_sub:keyword
AwdehAwd
AzumaAzu
BaekBae
BamfordBam
BernatskyBer

A negative start position is interpreted as being relative to the end of the string.This example returns the last three characters of every last name:

FROM employees| KEEP last_name| EVAL ln_sub = SUBSTRING(last_name, -3, 3)
last_name:keywordln_sub:keyword
Awdehdeh
Azumauma
Baekaek
Bamfordord
Bernatskysky

If length is omitted, substring returns the remainder of the string.This example returns all characters except for the first:

FROM employees| KEEP last_name| EVAL ln_sub = SUBSTRING(last_name, 2)
last_name:keywordln_sub:keyword
Awdehwdeh
Azumazuma
Baekaek
Bamfordamford
Bernatskyernatsky

Syntax

Embedded

Parameters

string

A string.

Description

Encode a string to a base64 string.

Supported types

stringresult
keywordkeyword
textkeyword

Example

ROW a = "elastic"| EVAL e = TO_BASE64(a)
a:keyworde:keyword
elasticZWxhc3RpYw==

Syntax

Embedded

Parameters

str

String expression. Ifnull, the function returnsnull. The input can be a single-valued column or expression, or a multi-valued column or expressionStackPlanned.

Description

Returns a new string representing the input string converted to lower case.

Supported types

strresult
keywordkeyword
textkeyword

Examples

ROW message = "Some Text"| EVAL message_lower = TO_LOWER(message)
message:keywordmessage_lower:keyword
Some Textsome text

StackPlanned

ROW v = TO_LOWER(["Some", "Text"])
v:keyword
["some", "text"]

Syntax

Embedded

Parameters

str

String expression. Ifnull, the function returnsnull. The input can be a single-valued column or expression, or a multi-valued column or expressionStackPlanned.

Description

Returns a new string representing the input string converted to upper case.

Supported types

strresult
keywordkeyword
textkeyword

Example

ROW message = "Some Text"| EVAL message_upper = TO_UPPER(message)
message:keywordmessage_upper:keyword
Some TextSOME TEXT

Syntax

Embedded

Parameters

string

String expression. Ifnull, the function returnsnull.

Description

Removes leading and trailing whitespaces from a string.

Supported types

stringresult
keywordkeyword
textkeyword

Example

ROW message = "   some text  ",  color = " red "| EVAL message = TRIM(message)| EVAL color = TRIM(color)
message:scolor:s
some textred
Elastic logo

© 2025 Elasticsearch B.V. All Rights Reserved.

Elasticsearch is a trademark of Elasticsearch B.V., registered in the U.S. and in other countries. Apache, Apache Lucene, Apache Hadoop, Hadoop, HDFS and the yellow elephant logo are trademarks of the Apache Software Foundation in the United States and/or other countries.

Welcome to the docs for thelatest Elastic product versions, including Elastic Stack 9.0 and Elastic Cloud Serverless.To view previous versions, go toelastic.co/guide.


[8]ページ先頭

©2009-2025 Movatter.jp