Skip to content

Instantly share code, notes, and snippets.

@TomonoriSoejima
Last active November 6, 2020 12:25
Show Gist options
  • Save TomonoriSoejima/ec20c29e47ad72cef9771ab55700b79a to your computer and use it in GitHub Desktop.
Save TomonoriSoejima/ec20c29e47ad72cef9771ab55700b79a to your computer and use it in GitHub Desktop.
buckets_path test
POST a/3
{"uid": 0, "value": 1} 
POST a/3
{"uid": 1, "value": 1} 
POST a/3
{"uid": 1, "value": 1} 
POST a/3
{"uid": 2, "value": 10} 
POST a/3
{"uid": 3, "value": 100} 
POST a/3
{"uid": 3, "value": 100} 

GET a/_search
{
  "size": 0,
  "aggs": {
    "kore": {
      "terms": {
        "field": "uid",
        "size": 10
      },
      "aggs": {
        "kore2": {
          "avg": {
            "field": "value"
          }
        }
      }
    },
    "unique_sum": {
      "sum_bucket": {
        "buckets_path": "kore>kore2"
      }
    }
  }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment