How to build my Elasticsearch query

Hello,

I have a problem that seems simple, but I can not solve it. If in my index I have as data :

 country | id | n1 | n2 | n3 | other
---------+----+----+----+----+-------
       1 |  1 |  0 |  2 |  0 |     1
       2 |  2 |  1 |  0 |  1 |     1
       2 |  2 |  1 |  0 |  1 |     2
       2 |  2 |  1 |  0 |  1 |     3
       2 |  3 |  1 |  1 |  1 |     1
       1 |  4 |  0 |  3 |  2 |     1
       1 |  4 |  0 |  3 |  2 |     2

How do I run the following query in Elasticsearch?

 select DISTINCT country, id, n1, n2, n3 from MyIndex;
 country | id | n1 | n2 | n3
---------+----+----+----+----
       2 |  3 |  1 |  1 |  1
       1 |  4 |  0 |  3 |  2
       1 |  1 |  0 |  2 |  0
       2 |  2 |  1 |  0 |  1

And especially :

select country, sum(n1), sum(n2), sum(n3) from (select DISTINCT country, id, n1, n2, n3 from MyIndex) as foo group by country;
 country | sum | sum | sum
---------+-----+-----+-----
       1 |   0 |   5 |   2
       2 |   2 |   1 |   2

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.