elasticsearch-sql
elasticsearch-sql copied to clipboard
这样的子查询 es语句能转吗?
select count(DISTINCT deviceId) from uv where deviceId in (select deviceId from uv where userId = 'unknown') and uv.userId != 'unknown';
可以
select count(DISTINCT deviceId) from uv where deviceId in (select deviceId from uv where userId = 'unknown') and uv.userId <> 'unknown'
能帮忙转一下吗 我们服务依赖阿里云的 只能装阿里云的插件 他们的插件我试了一下不能转
这个转换,不是直接转出来的,里面有个子查询,转换的时候,需要执行子查询,拿到结果,然后再转出最终的结果
本地子查询
select deviceId from uv where userId = 'unknown'
只有一条数据:device1
{
"from": 0,
"size": 0,
"query": {
"bool": {
"filter": [
{
"bool": {
"must": [
{
"bool": {
"must": [
{
"bool": {
"should": [
{
"match_phrase": {
"deviceId": {
"query": "device1",
"slop": 0,
"zero_terms_query": "NONE",
"boost": 1
}
}
}
],
"adjust_pure_negative": true,
"boost": 1
}
},
{
"bool": {
"must_not": [
{
"match_phrase": {
"uv.userId": {
"query": "unknown",
"slop": 0,
"zero_terms_query": "NONE",
"boost": 1
}
}
}
],
"adjust_pure_negative": true,
"boost": 1
}
}
],
"adjust_pure_negative": true,
"boost": 1
}
}
],
"adjust_pure_negative": true,
"boost": 1
}
}
],
"adjust_pure_negative": true,
"boost": 1
}
},
"_source": {
"includes": [
"COUNT"
],
"excludes": []
},
"aggregations": {
"COUNT(DISTINCT deviceId)": {
"cardinality": {
"field": "deviceId"
}
}
}
}
sorry 过年了 一直没关注 这个如果分成了两步的话 子查询的集合会非常大 外面的in也会非常大 有啥办法能不取出来 一句话查出来结果吗
我的想法是,要么就现有模型拿到所有的deviceid之后批量去取,要么考虑调整下mapping来满足这种query