elasticsearch group-by multiple fields

前端 未结 4 1673
孤街浪徒
孤街浪徒 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:28

    You can use Composite Aggregation query as follows. This type of query also paginates the results if the number of buckets exceeds from the normal value of ES. By using the field 'after' you can access the rest of buckets:

    "aggs": {
        "my_buckets": {
          "composite": {
            "sources": [
              {
                "field1": {
                  "terms": {
                    "field": "field1"
                  }
                }
              },
              {
                "field2": {
                  "terms": {
                    "field": "field2"
                  }
                }
              },
             {
                "field3": {
                  "terms": {
                    "field": "field3"
                  }
                }
              },
            ]
          }
        }
      }
    

    You can find more detail in ES page bucket-composite-aggregation.

提交回复
热议问题