Comments (2)
支持case when:
select a,case when c='1' then 'haha' when c='2' then 'book' else 'hbhb' end as gg from tbl_a group by a,gg
不过上面语句不支持,可以用script:
select
sum(script("","def df = Integer.parseInt(DateTimeFormatter.ofPattern('HH').withZone(ZoneId.systemDefault()).format(Instant.ofEpochMilli(doc['data_time'].value.getMillis())));if(df>0 && df<9){doc['data_value'].value} else {0}")) freeTime,
sum(script("","def df = Integer.parseInt(DateTimeFormatter.ofPattern('HH').withZone(ZoneId.systemDefault()).format(Instant.ofEpochMilli(doc['data_time'].value.getMillis())));if(df>9 && df<18){doc['data_value'].value} else {0}")) dayTime,
count(DISTINCT script("","DateTimeFormatter.ofPattern('yyyy-MM-dd').withZone(ZoneId.systemDefault()).format(Instant.ofEpochMilli(doc['data_time'].value.getMillis()))")) countDateTime,
sum(data_value) totalCount
from
table_name
{
"from": 0,
"size": 0,
"_source": {
"includes": [
"sum",
"sum",
"count",
"sum"
],
"excludes": []
},
"aggregations": {
"freeTime": {
"sum": {
"script": {
"source": "def df = Integer.parseInt(DateTimeFormatter.ofPattern('HH').withZone(ZoneId.systemDefault()).format(Instant.ofEpochMilli(doc['data_time'].value.getMillis())));if(df>0 && df<9){doc['data_value'].value} else {0}",
"lang": "painless"
}
}
},
"dayTime": {
"sum": {
"script": {
"source": "def df = Integer.parseInt(DateTimeFormatter.ofPattern('HH').withZone(ZoneId.systemDefault()).format(Instant.ofEpochMilli(doc['data_time'].value.getMillis())));if(df>9 && df<18){doc['data_value'].value} else {0}",
"lang": "painless"
}
}
},
"countDateTime": {
"cardinality": {
"script": {
"source": "DateTimeFormatter.ofPattern('yyyy-MM-dd').withZone(ZoneId.systemDefault()).format(Instant.ofEpochMilli(doc['data_time'].value.getMillis()))",
"lang": "painless"
}
}
},
"totalCount": {
"sum": {
"field": "data_value"
}
}
}
}
from elasticsearch-sql.
@shi-yuan 希望能直接支持,这样能兼容更广泛的应用场景。
APIJSON 支持 SQL 及各种 SQL 方言,但不支持这个 script(看起来不是存储过程,而是类似 Java 的自定义脚本)。
目前 APIJSON 就是通过 elasticsearch-sql 来支持 Elasticsearch:
https://github.com/Tencent/APIJSON
from elasticsearch-sql.
Related Issues (20)
- 请问有update语句的案例吗,招了一圈wiki没找到 HOT 3
- nested内层的属性做agg的bucket聚合,sql支持吗请问 HOT 1
- 是否支持查询结果上附带字段的数据类型? HOT 1
- 分页检索似乎有问题,无法按照页码滚动、 HOT 5
- 使用jdbc怎么拿到scrollID
- 是否支持对单个或多个字段的去重?
- TransportClient在7.0版本后面如何配置账户密码才能使用es-sql呢, HOT 1
- 子查询bug HOT 2
- jdk version required list HOT 1
- 运行最新的插件报错 HOT 3
- 查询语句中如果包含单引号如何处理 HOT 1
- 插件运行时报错 HOT 1
- 能分词查询吗 HOT 4
- group by 查询没获取到数据 HOT 2
- 7.2.1 TRACK_TOTAL_HITS(true) 参数无效 HOT 1
- 无法支持常量结果,能看看怎么回事么? HOT 2
- union 两个count查询时报错 HOT 3
- 怎么进行分页 HOT 3
- 网页查询报错 HOT 4
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from elasticsearch-sql.