elasticsearch group-by multiple fields

前端 未结 4 1668
孤街浪徒
孤街浪徒 2020-12-14 10:42

I am Looking for the best way to group data in elasticsearch. Elasticsearch doesn\'t support something like \'group by\' in sql.

Lets say I have 1k categories and mi

4条回答
  •  自闭症患者
    2020-12-14 11:07

    sub-aggregations is what you need .. though this is never explicitly stated in the docs it can be found implicitly by structuring aggregations

    It will result the sub-aggregation as if the query was filtered by result of the higher aggregation. It actually looks like as if this is what happens in there.

    {
    "aggregations": {
        "VALUE1AGG": {
          "terms": {
            "field": "VALUE1",
          },
          "aggregations": {
            "VALUE2AGG": {
               "terms": {
                 "field": "VALUE2",
              }
            }
          }
        }
      }
    }
    

提交回复
热议问题