index=es_sql_test* 502 AND Woodardhtml
index=es_sql_test* "502 Baycliff Terrace"web
index=es_sql_test* state=PA AND age<30 AND gender=Msql
必須大寫, 支持的運算符有:express
AND
state=PA AND age>20OR
state=PA OR state=DENOT
NOT state=DE()
(state=PA OR state=DE) AND age>20IN
state in (PA,DE)null
city is nullNOT-null
city is NOT nullexist
city is NOT null, 與NOT-null相同=
age=20 精確匹配age的字段值!=
age!=20 不匹配age的字段值<
age<20 匹配age小於20的字段值>
age>20 匹配age大於20的字段值<=
age<=20 匹配age小於等於20的字段值>=
age>=20 匹配age大於等於20的字段值*
匹配0個或者多個字符 e.g. firstname=*ri, firstname=Rach?
匹配1個字符 e.g. firstname=Eff?e非數字,大小寫字母, @, _ 字符 或 space
出如今查詢語句中時,須要添加引號數組
e.g. "http://website.com:9000", "hello word", "user@mail.com"elasticsearch
now
, 當前時間'2017-03-15T10:00:00'
, UTC時間字符串, 年(y)必須4位數字, 月(M) 日(d) 周(w) 時(h) 分(m) 秒(s) 必須2位數字-1h
, 減去1小時+1d
, 加1天/d
, 捨棄日期中的小時及如下單位的數值e.g.ide
now-5h
, 即5小時以前, h爲時間單位,now-1d/d
, 即取昨天0點開始的時間,now+1d
, 當前時間加1天now-2w
, 當前時間減去2周now-1M+1d
, 當前時間減去1月再加上1天@'2017-03-15T10:00:00'-5h
@'2017-03-01'-1s
min_match(field_name, ‘text', ‘match’, ‘analyze')函數
field_name
: 字段名稱, 必選text
: string, 搜索的長字符串, 必選match
: string, 匹配度, 必須, 詳細說明(https://www.elastic.co/guide/en/elasticsearch/reference/5.4/query-dsl-minimum-should-match.html)analyze
: string, 分詞器名稱, 可選, 若是text
中包括中文, 建議該參數使用ik_smart
e.g. index=sharplook* min_match(agent,"Intel Mac OS X 10_12_5」,」90%」) index=sharplook* min_match(agent,"歡迎來到搜索平臺」,」80%」,」ik_smart」)ui
命令格式: | sort sort-by-field [desc | asc]spa
index=es_sql_test* | sort by age asc
默認排序爲 @timestamp desc
命令格式: | head/tail INT
| head 3 取前三條記錄
| tail 3 取後三條記錄
命令格式: | top/rare INT field
| top 5 lastname | rare 3 lastname
該命令用來統計field的數量, 並取前N條記錄.
命令格式: | fields field [, field]*
| fields state, city, firstname, age
該命令用來指定輸出列名
命令格式: | table field [, field]*
| table state, age
index=es_sql_test* | table state, age index=bankdata* | stats count by ServiceCode, SystemName | head 1 | table "count"
命令格式: | transaction field [maxopentxn=INT maxopenevents=INT]
index=es_sql_test* | transaction state maxopentxn=5 maxopenevents=1
maxopentxn
最大事務數量, 默認10maxopenevents
最大事務日誌條數, 默認10命令格式: ( search spl_sub_query ;) 子查詢必須以分號
;
結束index = bankdata* ServiceCode=01 AND (search index=bankdata* SystemId=0000 | head 1 | fields TranSeqNo;)
命令格式: | stats metric_function(field) [as field_alias] by field-1, field-2, ...
index=es_sql_test* | stats count(firstname) as people_count by state
metric_function 支持的函數有:
sum
累加和avg
平均值count
出現的次數dc
出如今的次數, 去重min
最小值max
最大值命令格式 | stats metric_function(field[filter expr]) [as field_alias] by field-1, field-2, ...
index=bankdata* | stats max(@timestamp[filter LogType=Res]), min(@timestamp[filter LogType=Req]) by TranSeqNo
命令格式: | stats metric_function(field) [as field_alias] by field [, field]* | filter metric_func_expr [, metric_func_expr]*
index=bankdata* | stats count(LogType) as cc by TranSeqNo | filter cc>30 index=bankdata* | stats count as cc, avg(Duration) aa by TranSeqNo | filter cc>20, aa>12
命令格式: | stats metric_function(field) [as field_alias] by field[ sort by metric_func_field_alias,N] ,field-2, ...
index=bankdata* | stats avg(Duration) as avg_dur by SystemName[sort by avg_dur,3], ServiceType
metric_func_field_alias
指標函數的別名N
限制分桶數據輸出的數量, 不限時請輸入0命令格式: | stats metric_function(field) [as field_alias] by field [, field]* | stats metric_function(metric_func_field_alias)
index=bankdata* LogType=Req | stats sum(Duration) as duration_total by TranSeqNo | stats avg(duration_total) as duration_avg by ServiceCode
命令格式: | stats tops(N,source=[field-1,field-2,...], field = fieldName asc|desc)
index=bankdata* | stats tops(2,source=[ServiceType,SystemName] ,field=TranSeqNo asc) as top_transeq by SystemId
N
返回聚合記錄行數source
非必須, 返回聚合記錄行的列名field
非必須, 排序字段, asc 正序, desc 倒序命令格式: | stats first(field = fieldName asc|desc, field-1,field-2,...)
index=bankdata* | stats count, first(ServiceType,SystemName) by SystemId
field-1,field-2,...
返回聚合記錄的列名field
非必須, 排序字段, asc 正序, desc 倒序命令格式: histogram(field,interval,mincount=n)
index=bankdata* | stats avg(Duration) by histogram(Duration,10,mincount=0)
field
數值列名interval
數值間隔mincount
數值, 分桶最小數量,小於該數量的值將不顯示命令格式: date_histogram(field,interval,format='{format}',time_zone='{tz}',mincount={mincount}})
index=bankdata* | stats count(TranSeqNo) as tran_count by date_histogram(@timestamp,hour,mincount=0)
field
時間列名,interval
時間間隔, 時間單位能夠是 年(year) 季(quarter) 月(month) 周(week) 日(d) 時(h) 分(m) 秒(s) 毫秒(ms), 如: 1d, 2h, (year,month,quarter,week)不支持倍數format
時間格式, 如: yyyy-MM-dd hh:mm:sstime_zone
時區, 默認爲UTC時間, 如: +08:00offset
時間偏移, 如: +2hmintime
string/long 最小時間maxtime
string/long 最大時間mincount
數值, 分桶最小數量,小於該數量的值將不顯示index=bankdata* | stats max(@timestamp[filter LogType=Res]) end, min(@timestamp[filter LogType=Req]) start by TranSeqNo | eval duration=end-start | stats avg(duration) as avgDuration by ServiceCode, date_histogram(@timestamp,hour)
命令格式: range(field,value-1,value-2,value-3...)
index=bankdata* | stats count(TranSeqNo) as tran_count by range(Duration,0,10,50,100,500,2000)
field
數值列名value-1,value-2,value-3...
自定義數值間隔命令格式: date_range(field,datetime-1,datetime-2,datetime-3...)
index=bankdata* | stats count(TranSeqNo) as tran_count by date_range(@timestamp,"2016/10","2016/11","2016/12","2017/01","2017/02", format="yyyy/MM")
field
時間列名datetime-1,datetime-2,datetime-3...
自定義時間間隔命令格式: | eval eval-field=eval-expression
index=es_sql_test* | eval name = firstname +'.'+ lastname | fields name, age, state
支持的函數包括:
isnull(field)
判斷field是否爲空
abs(field)
返回field的絕對值
ceil(field)
向上取整
floor(field)
向下取整
log(field)
計算field的對數
log10(field)
計算field的對數
sqrt(field)
計算平方根
cbrt(field)
計算立方根
exp(field)
計算field的指數
round(field, [scale])
對field作精度計算(四捨五入), scale: int 精度,可選
min(field1, field2)
取兩個field中較小的值
max(field1, field2)
取兩個field中較大的值
concat(separator, field1, field2, ......)
用separator(分隔符)將field1, field2, ...鏈接
split(field,separator,n)
將field用separator分隔成數組並取數組中的第n個值
substr(field, m, n)
從field的第m個位值開始到第n個位值結束, 但不包括n處的字符
trim(field)
去除field的先後空格
date_format(date_field,format_string)
將date_field按照format_string格式化, 如: date_format(@timestam,'yyyy-MM-dd HH:mm:ss')
coalesce(field1, field2, ......)
取第一個不爲null的值
if(bool_operator, result1, result2)
若是bool_operator爲真, 返回result1, 不然返回result2, bool_operator支持的符號有: ==, !=, >, >=, <, <= if(status>200, "error", "ok")
case(bool_operator, result1, bool_operator, result2, ......, [default, default_result])
相似switch case, 根據判斷條件生成返回多個枚舉值中的一個, default 可選, 默認值爲null case(status==200, "c1", status==404, "c2", default, "c3")
eval嵌套 e.g.
eval name=split(firstname+'.'+substr(lastname,0,2),'.')[1] eval xx=round(cbrt(age),1) eval xx=round((age+10)/3,2)
注意:
*
時, 請在先後加空格index=bankdata* | stats max(@timestamp[filter LogType=Res]) end, min(@timestamp[filter LogType=Req]) start by TranSeqNo | eval duration=end-start
index=bankdata* | stats max(@timestamp[filter LogType=Res]) end, min(@timestamp[filter LogType=Req]) start by TranSeqNo | eval duration=end-start | stats avg_dur = avg(duration)
注意:兩個stats中間的eval命令僅限於基本的數學計算'+','-','*','/','%'
命令格式: | search field op_symbol value
index = es_sql* state=DE AND age>20 | stats count cc,avg(age) by city | search avg_age>35 | table city,cc,avg_age
op_symbol 支持的操做符有:
=
等於!=
不等於>
大於>=
大於等於<
小於<=
小於等於注意:
若是須要將過濾後的結果顯示成圖表, 請使用 table
命令
命令格式: | stats metric_function(field) [as field_alias] by field-1, field-2, ...
index = es_sql* state=DE AND age>20 | stats count cc,avg(age) by city | search avg_age>35 | eval x = cc%2 | stats sum(avg_age) by x | table x,sum_avg_age
metric_function 支持的函數有:
sum
累加和avg
平均值count
出現的次數min
最小值max
最大值注意:
若是須要將過濾後的結果展現成圖表, 請使用 table
命令
命令格式: | eval field_alias = moving_avg(field,[,'model'=string,'window'=number,'predict'=number,'type'=string,'alpha'=float,'beta'=float,'gamma'=flat,'pad'=1/0])
index = bankdata* | stats avg(Duration) avg_dur by date_histogram(@timestamp,hour) | eval mov_avg = moving_avg(avg_dur,'model'='holt-winters','window'='6', 'predict'=3,'type'='add','alpha'=0.8,'beta'=0.2,'gamma'=0.5,'pad'=1)
model
string, 移動平均數計算模型,默認: simple, 可用模型: simple, linear, ewma, holt-linear, holt-winters,window
int, 滑動窗口跨越數量, 默認: 5predict
int, 預測數量settings
type
string, add/mult model= holt-winters 有效alpha
float model= ewma,holt-linear, holt-winters 有效beta
float model= holt-linear, holt-winters 有效gamma
float model= holt-winters 有效pad
0/1 model= holt-winters 有效