In elasticsearch, how to achieve the function like this SQL:
SELECT a, sum(b), sum(c), d
FROM TableA
WHERE a IN (1,2,3,4) AND d = 88
GROUP BY a
HAVING sum(b) > 10
ORDER BY sum(b) desc, sum(c) asc
LIMIT 10 OFFSET 5;
So far I have only done this :
{
"size":0,
"query":{
"filtered": {
"filter":{
"terms":{
"a": [1, 2, 3, 4]
}
},
"query":{
"match": {
"d": 8
}
}
}
},
"aggs": {
"group_by_a":{
"terms":{
"field": "a",
"size": 10,
"order" : { "sum(b)" : "desc" }
},
"aggs" : {
"sum(b)": {"sum": {"field": "b"}},
"sum(c)": {"sum": {"field": "c"}}
}
}
}
}
Its is like I have just achieved this:
SELECT a, sum(b), sum(c)
FROM TableA
WHERE a IN (1,2,3,4) AND d = 88
GROUP BY a
HAVING sum(b) > 10
ORDER BY sum(b) desc
LIMIT 10;
And what to do with the extra return field d, the having condition, the extra order by sum(c) asc, and the offset 5 ?
So sad that I found having clause is unsupported currently.