SQL Where clause equivalent for Elastic Search SQL Where clause equivalent for Elastic Search elasticsearch elasticsearch

SQL Where clause equivalent for Elastic Search


Should be something like this:

{  "query": {    "filtered": {      "query": {        "match_all": {}      },      "filter": {        "term": {          "material": "wood"        }      }    }  },    "aggs" : {        "product" : {            "terms" : {                "field" : "name"            },            "aggs" : {                "material" : {                    "terms" : {                        "field" : "material"                    },                    "aggs" : {                        "sum_price" : {                            "sum" : {                                "field" : "price"                            }                        }                    }                }            }        }    },    "size" : 0}

Use a filter if you know the exact value and do not need a match, else use a match query instead of the filtered query.


You can use match

{  "query": {    "bool": {      "must": [        {                      "match": {            "material": "wood"          }        }      ],      "filter": [        {          "match_all": {}        },      ]    }    },    "aggs" : {        "product" : {            "terms" : {                "field" : "name"            },            "aggs" : {                "material" : {                    "terms" : {                        "field" : "material"                    },                    "aggs" : {                        "sum_price" : {                            "sum" : {                                "field" : "price"                            }                        }                    }                }            }        }    },    "size" : 0}