You're viewing version 2.4 of the OpenSearch documentation. This version is no longer maintained. For the latest version, see the current documentation . For information about OpenSearch version maintenance, see Release Schedule and Maintenance Policy .
 Functions  You must enable fielddata in the document mapping for most string functions to work properly.
 The specification shows the return type of the function with a generic type T as the argument. For example, abs(number T) -> T means that the function abs accepts a numerical argument of type T, which could be any subtype of the number type, and it returns the actual type of T as the return type.
 The SQL plugin supports the following common functions shared across the SQL and PPL languages.
 Mathematical     Function  Specification  Example        abs  abs(number T) -> TSELECT abs(0.5) FROM my-index LIMIT 1   add  add(number T, number) -> TSELECT add(1, 5) FROM my-index LIMIT 1   cbrt  cbrt(number T) -> TSELECT cbrt(0.5) FROM my-index LIMIT 1   ceil  ceil(number T) -> TSELECT ceil(0.5) FROM my-index LIMIT 1   conv  conv(string T, int a, int b) -> TSELECT CONV('12', 10, 16), CONV('2C', 16, 10), CONV(12, 10, 2), CONV(1111, 2, 10) FROM my-index LIMIT 1   crc32  crc32(string T) -> TSELECT crc32('MySQL') FROM my-index LIMIT 1   divide  divide(number T, number) -> TSELECT divide(1, 0.5) FROM my-index LIMIT 1   e  e() -> doubleSELECT e() FROM my-index LIMIT 1   exp  exp(number T) -> TSELECT exp(0.5) FROM my-index LIMIT 1   expm1  expm1(number T) -> TSELECT expm1(0.5) FROM my-index LIMIT 1   floor  floor(number T) -> TSELECT floor(0.5) AS Rounded_Down FROM my-index LIMIT 1   ln  ln(number T) -> doubleSELECT ln(10) FROM my-index LIMIT 1   log  log(number T) -> double or log(number T, number) -> doubleSELECT log(10) FROM my-index LIMIT 1   log2  log2(number T) -> doubleSELECT log2(10) FROM my-index LIMIT 1   log10  log10(number T) -> doubleSELECT log10(10) FROM my-index LIMIT 1   mod  mod(number T, number) -> TSELECT modulus(2, 3) FROM my-index LIMIT 1   multiply  multiply(number T, number) -> numberSELECT multiply(2, 3) FROM my-index LIMIT 1   pi  pi() -> doubleSELECT pi() FROM my-index LIMIT 1   pow  pow(number T) -> T or pow(number T, number) -> TSELECT pow(2, 3) FROM my-index LIMIT 1   power  power(number T) -> T or power(number T, number) -> TSELECT power(2, 3) FROM my-index LIMIT 1   rand  rand() -> number or rand(number T) -> TSELECT rand(0.5) FROM my-index LIMIT 1   rint  rint(number T) -> TSELECT rint(1.5) FROM my-index LIMIT 1   round  round(number T) -> TSELECT round(1.5) FROM my-index LIMIT 1   sign  sign(number T) -> TSELECT sign(1.5) FROM my-index LIMIT 1   signum  signum(number T) -> TSELECT signum(0.5) FROM my-index LIMIT 1   sqrt  sqrt(number T) -> TSELECT sqrt(0.5) FROM my-index LIMIT 1   strcmp  strcmp(string T, string T) -> TSELECT strcmp('hello', 'hello') FROM my-index LIMIT 1   subtract  subtract(number T, number) -> TSELECT subtract(3, 2) FROM my-index LIMIT 1   truncate  truncate(number T, number T) -> TSELECT truncate(56.78, 1) FROM my-index LIMIT 1   /  number [op] number -> numberSELECT 1 / 100 FROM my-index LIMIT 1   %  number [op] number -> numberSELECT 1 % 100 FROM my-index LIMIT 1    
Trigonometric     Function  Specification  Example        acos  acos(number T) -> doubleSELECT acos(0.5) FROM my-index LIMIT 1   asin  asin(number T) -> doubleSELECT asin(0.5) FROM my-index LIMIT 1   atan  atan(number T) -> doubleSELECT atan(0.5) FROM my-index LIMIT 1   atan2  atan2(number T, number) -> doubleSELECT atan2(1, 0.5) FROM my-index LIMIT 1   cos  cos(number T) -> doubleSELECT cos(0.5) FROM my-index LIMIT 1   cosh  cosh(number T) -> doubleSELECT cosh(0.5) FROM my-index LIMIT 1   cot  cot(number T) -> doubleSELECT cot(0.5) FROM my-index LIMIT 1   degrees  degrees(number T) -> doubleSELECT degrees(0.5) FROM my-index LIMIT 1   radians  radians(number T) -> doubleSELECT radians(0.5) FROM my-index LIMIT 1   sin  sin(number T) -> doubleSELECT sin(0.5) FROM my-index LIMIT 1   sinh  sinh(number T) -> doubleSELECT sinh(0.5) FROM my-index LIMIT 1   tan  tan(number T) -> doubleSELECT tan(0.5) FROM my-index LIMIT 1    
Date and time     Function  Specification  Example        adddate  adddate(date, INTERVAL expr unit) -> dateSELECT adddate(date('2020-08-26'), INTERVAL 1 hour) FROM my-index LIMIT 1   curdate  curdate() -> dateSELECT curdate() FROM my-index LIMIT 1   date  date(date) -> dateSELECT date() FROM my-index LIMIT 1   date_format  date_format(date, string) -> string or date_format(date, string, string) -> stringSELECT date_format(date, 'Y') FROM my-index LIMIT 1   date_sub  date_sub(date, INTERVAL expr unit) -> dateSELECT date_sub(date('2008-01-02'), INTERVAL 31 day) FROM my-index LIMIT 1   dayofmonth  dayofmonth(date) -> integerSELECT dayofmonth(date) FROM my-index LIMIT 1   dayname  dayname(date) -> stringSELECT dayname(date('2020-08-26')) FROM my-index LIMIT 1   dayofyear  dayofyear(date) -> integerSELECT dayofyear(date('2020-08-26')) FROM my-index LIMIT 1   dayofweek  dayofweek(date) -> integerSELECT dayofweek(date('2020-08-26')) FROM my-index LIMIT 1   from_days  from_days(N) -> integerSELECT from_days(733687) FROM my-index LIMIT 1   hour  hour(time) -> integerSELECT hour((time '01:02:03')) FROM my-index LIMIT 1   maketime  maketime(integer, integer, integer) -> dateSELECT maketime(1, 2, 3) FROM my-index LIMIT 1   microsecond  microsecond(expr) -> integerSELECT microsecond((time '01:02:03.123456')) FROM my-index LIMIT 1   minute  minute(expr) -> integerSELECT minute((time '01:02:03')) FROM my-index LIMIT 1   month  month(date) -> integerSELECT month(date) FROM my-index   monthname  monthname(date) -> stringSELECT monthname(date) FROM my-index   now  now() -> dateSELECT now() FROM my-index LIMIT 1   quarter  quarter(date) -> integerSELECT quarter(date('2020-08-26')) FROM my-index LIMIT 1   second  second(time) -> integerSELECT second((time '01:02:03')) FROM my-index LIMIT 1   subdate  subdate(date, INTERVAL expr unit) -> date, datetimeSELECT subdate(date('2008-01-02'), INTERVAL 31 day) FROM my-index LIMIT 1   time  time(expr) -> timeSELECT time('13:49:00') FROM my-index LIMIT 1   time_to_sec  time_to_sec(time) -> longSELECT time_to_sec(time '22:23:00') FROM my-index LIMIT 1   timestamp  timestamp(date) -> dateSELECT timestamp(date) FROM my-index LIMIT 1   to_days  to_days(date) -> longSELECT to_days(date '2008-10-07') FROM my-index LIMIT 1   week  week(date[mode]) -> integerSELECT week(date('2008-02-20')) FROM my-index LIMIT 1   year  year(date) -> integerSELECT year(date) FROM my-index LIMIT 1    
String     Function  Specification  Example        ascii  ascii(string T) -> integerSELECT ascii(name.keyword) FROM my-index LIMIT 1   concat  concat(str1, str2) -> stringSELECT concat('hello', 'world') FROM my-index LIMIT 1   concat_ws  concat_ws(separator, string, string…) -> stringSELECT concat_ws("-", "Tutorial", "is", "fun!") FROM my-index LIMIT 1   left  left(string T, integer) -> TSELECT left('hello', 2) FROM my-index LIMIT 1   length  length(string) -> integerSELECT length('hello') FROM my-index LIMIT 1   locate  locate(string, string, integer) -> integer or locate(string, string) -> INTEGERSELECT locate('o', 'hello') FROM my-index LIMIT 1, SELECT locate('l', 'hello', 3) FROM my-index LIMIT 1   replace  replace(string T, string, string) -> TSELECT replace('hello', 'l', 'x') FROM my-index LIMIT 1   right  right(string T, integer) -> TSELECT right('hello', 1) FROM my-index LIMIT 1   rtrim  rtrim(string T) -> TSELECT rtrim(name.keyword) FROM my-index LIMIT 1   substring  substring(string T, integer, integer) -> TSELECT substring(name.keyword, 2,5) FROM my-index LIMIT 1   trim  trim(string T) -> TSELECT trim(' hello') FROM my-index LIMIT 1   upper  upper(string T) -> TSELECT upper('helloworld') FROM my-index LIMIT 1    
Aggregate     Function  Specification  Example        avg  avg(number T) -> TSELECT avg(2, 3) FROM my-index LIMIT 1   count  count(number T) -> TSELECT count(date) FROM my-index LIMIT 1   min  min(number T, number) -> TSELECT min(2, 3) FROM my-index LIMIT 1   show  show(string T) -> TSHOW TABLES LIKE my-index    
Advanced     Function  Specification  Example        if  if(boolean, es_type, es_type) -> es_typeSELECT if(false, 0, 1) FROM my-index LIMIT 1, SELECT if(true, 0, 1) FROM my-index LIMIT 1   ifnull  ifnull(es_type, es_type) -> es_typeSELECT ifnull('hello', 1) FROM my-index LIMIT 1, SELECT ifnull(null, 1) FROM my-index LIMIT 1   isnull  isnull(es_type) -> integerSELECT isnull(null) FROM my-index LIMIT 1, SELECT isnull(1) FROM my-index LIMIT 1    
Relevance-based search (full-text search)  These functions are only available in the WHERE clause. For their descriptions and usage examples in SQL and PPL, see Full-text search .