用SQL语句查询elasticsearch

zjsrg 4年前

来自: http://blog.csdn.net//jiao_fuyou/article/details/50556602


以前我是这样查询elasticsearch的:

POST /cdr*/hj_scpcdr/_search  {    "from" : 0,    "size" : 0,    "_source" : {      "includes" : [ "filedate", "vestss", "permark", "subpp", "SUM" ],      "excludes" : [ ]    },    "fields" : [ "filedate", "vestss", "permark", "subpp" ],    "sort" : [ {      "filedate" : {        "order" : "asc"      }    }, {      "vestss" : {        "order" : "asc"      }    }, {      "permark" : {        "order" : "asc"      }    }, {      "subpp" : {        "order" : "asc"      }    } ],    "aggregations" : {      "filedate" : {        "terms" : {          "field" : "filedate",          "size" : 200,          "order" : {            "_term" : "asc"          }        },        "aggregations" : {          "vestss" : {            "terms" : {              "field" : "vestss",              "size" : 0,              "order" : {                "_term" : "asc"              }            },            "aggregations" : {              "permark" : {                "terms" : {                  "field" : "permark",                  "size" : 0,                  "order" : {                    "_term" : "asc"                  }                },                "aggregations" : {                  "subpp" : {                    "terms" : {                      "field" : "subpp",                      "size" : 0,                      "order" : {                        "_term" : "asc"                      }                    },                    "aggregations" : {                      "SUM(calldura60)" : {                        "sum" : {                          "field" : "calldura60"                        }                      }                    }                  }                }              }            }          }        }      }    }  }

但是我现在可以这样查询ES了:

POST /_sql  select filedate,vestss,permark,subpp,sum(calldura60) from cdr*/hj_scpcdr group by filedate,vestss,permark,subpp order by filedate,vestss,permark,subpp

没错,安装elasticsearch-sql插件就行了
https://github.com/NLPchina/elasticsearch-sql

这里写图片描述