ElasticSearch

时间:2018-06-08 06:46:46

标签: mysql elasticsearch

我有一个SQL表如下:

    pl_id     f_date    g_id x y
 1: 13459 2018-01-01 1560139 0 1
 2: 13459 2018-01-01 1560142 0 0
 3: 13868 2018-01-01 1560010 0 1
 4: 13868 2018-01-01 1560014 0 0
 5: 13459 2018-01-02 1569724 1 1
 6: 13459 2018-01-02 1569731 0 1
 7: 13868 2018-01-02 1560550 0 1
 8: 13868 2018-01-02 1560551 0 1
 9: 13459 2018-01-03 1591564 0 1
10: 13459 2018-01-03 1591566 1 1
11: 13868 2018-01-03 1612024 0 1
12: 13868 2018-01-03 1612031 0 1

我有一个SQL查询,如下所示:

SELECT subtable.f_date, ROUND(sum(subtable.var*subtable.num_g)/sum(subtable.num_g), 1) as points FROM (SELECT pl_id, f_date, sum(x)*100/sum(y) as var, count(g_id) as num_g FROM database WHERE f_date >= '2018-01-01' AND f_date <= '2018-01-03' GROUP BY pl_id, f_date) as subtable GROUP BY f_date;

结果如下:

    f_date points
1 2018-01-01      0
2 2018-01-02     25
3 2018-01-03     25

如您所见,查询基本上执行加权平均。 我试图将此SQL查询转换为ElasticSearch查询。如何在ElasticSearch查询中执行类似的操作?如何简化SQL查询作为替代方案?

0 个答案:

没有答案