es-sql-jdbc官方文件機翻
基本查詢語法是:
SELECT fields from indexName WHERE conditions
要查詢特定型別的索引,請使用:
SELECT fields from indexName/type WHERE conditions
您還可以一次查詢多個型別和索引,如下所示:
SELECT fields from indexName/type1,indexName/type2 WHERE conditions
SQL語句
SQL Select
SQL Delete
SQL Where
SQL Order By
SQL Group By
SQL Limit (預設為200)
條件:
SQL Like
SQL AND & OR
SQL COUNT distinct
SQL In
SQL Between
SQL Aliases
SQL(ES) Date
SQL now()
SQL NOT
基本彙總:
SQL avg()
SQL count()
SQL last()
SQL max()
SQL min()
SQL sum()
SQL欄位
欄位可以按精確欄位名稱列出,也可以與包含/排除語法一起使用以與萬用字元一起使用。
include('d *') - 包括以“d”開頭的所有欄位
exclude('age') - 包括除“age”之外的所有欄位
include('* Name'),exclude('lastName') - 包括以“name”結尾的所有欄位,“lastName”除外
聚合
Elasticsearch-sql聚合
我們支援幾種彈性搜尋聚合
min
max
sum
count
avg
stats
percentiles
extended_stats
在數字欄位上使用這樣的:
SELECT stats(age) FROM account
scripted_metric (read below on how to use)
buckets
術語聚合
使用group by fieldName,您也可以放置多個欄位
例子
SELECT COUNT(*) FROM account GROUP BY gender
SELECT COUNT(*) FROM account GROUP BY gender, age
多個聚合
使用group by(fieldName),(fieldName,fieldName)
括號中的每個欄位都有自己的聚合
括號中的每個欄位列表都是自己的子聚合聚合
例子
SELECT * FROM account GROUP BY (gender),(age)
SELECT * FROM account GROUP BY (gender, state),(age)
SELECT * FROM account GROUP BY (gender, state, age),(state),(age)
範圍聚合
將fieldName後跟您的範圍
例如,如果您想要範圍:年齡與組20-25,25-30,30-35,35-40
SELECT COUNT(age) FROM bank GROUP BY range(age, 20,25,30,35,40)
日期直方圖聚合
put fieldName和interval
別名是可選的
例
SELECT online FROM online GROUP BY date_histogram(field='insert_time','interval'='1d','alias'='yourAlias')
日期範圍聚合
將您的fieldName和特殊間隔放在格式中
別名是可選的
SELECT online FROM online GROUP BY date_range('alias'='yourAlias',field='insert_tim
使用ElasticSearch功能的更多功能
ES TopHits
ES MISSING
ES STATS
ES EXTENDED_STATS
ES PERCENTILES
ES TERMS/TERM
ES IDS syntax: IDS_QUERY(type, ids..)
ES SCRIPTED_METRIC (read about it on Aggregations page)
ES QUERY_STRING
SELECT * FROM account where nickname is not missing
SELECT * FROM account where nickname is missing
SELECT * FROM account where name = IN_TERMS(hattie,alis)
SELECT * FROM account where age = TERM(4)
SELECT * FROM account where _id = IDS_QUERY(account,1,2,5)
SELECT stats(age) FROM account
SELECT extended_stats(age) FROM account
SELECT percentiles(age) FROM accounts
SELECT address FROM bank where q=query('address:880 Holmes Lane')
SELECT * FROM dog where dog_name = REGEXP_QUERY('sn.*', 'INTERSECTION|COMPLEMENT|EMPTY', 10000)