一个复杂的SQL如何弹性搜索更多分组

时间:2018-11-06 02:54:07

标签: php mysql json elasticsearch

如何更多地使用elasticsearch分组并求和

<code>
    SELECT val01 ,val02 
    ,sum(val13) val13,sum(val14) val14 ,sum(val41) val41
    ,val05,val18,val19,val20,val21,val22 ,val23
,val24,val25,val26,val27 ,val15,val28,val29 
,val30,val31,val32 ,val10,val11 ,eid 
    FROM `val02` 
    WHERE val08 Between '2018-09-20 12:00:00' AND '2018-09-30 11:59:59' 
    group by val05,val23,val28,val11,val02
</code>
<code>
    "query": {
        "bool": {
            "must": [
                { "range": {
                    "val08": { 
                                "gte": "2018-09-20 12:00:00",
                                "lte": "2018-09-30 11:59:59",
                                "boost" : 2.0
                             }
                    }

                }
            ]
        }
    },
    "aggs": {
      "val05": {
        "terms": {
            "field": "val05",
            "size": 10000
        },
        "aggs": {
          "val02": {
            "terms": {
                "field": "val02",
                "size": 10000
            },
            "aggs": {
              "val11": {
                "terms": {
                    "field": "val11",
                    "size": 10000
                },
                "aggs": {
                  "val23": {
                    "terms": {
                        "field": "val23",
                        "size": 10000
                    },
                    "aggs": {
                      "val28": {
                        "terms": {
                            "field": "val28",
                            "size": 10000
                        },
                        "aggs": {
                            "val01": { 
                                "terms": {"field": "val01" } 
                            },
                            "val41": {
                               "sum": {
                                  "field": "val41s"
                               }
                            },
                            "val14": {
                               "sum": {
                                  "field": "val14s"
                               }
                            },
                            "val13": {
                               "sum": {
                                  "field": "val13s"
                               }
                            }
                        }

                      }

                   }

                  }

               }

              }

           }

          }

       }
      }

   }
</code>

如何使用与elasticsearch group相同的方式 val05,val23,val28,val11,val02 这些字段和val13 sum val14 sum val41

我正在检查嵌套存储桶聚合,但是被卡住了。因此,您能否建议为此需要什么弹性查询。

0 个答案:

没有答案