Skip to content

Instantly share code, notes, and snippets.

@benwtrent
Created February 11, 2020 14:43
Show Gist options
  • Save benwtrent/183649369d017e3c50d248c96ca0dcfb to your computer and use it in GitHub Desktop.
Save benwtrent/183649369d017e3c50d248c96ca0dcfb to your computer and use it in GitHub Desktop.
pipeline agg in composite example
GET kibana_sample_data_ecommerce/_search
{
"size": 0,
"aggs": {
"user": {
"composite": {
"sources": [
{
"user": {
"terms": {
"field": "user"
}
}
},
{
"customer_id": {
"terms": {
"field": "customer_id"
}
}
}
]
},
"aggs": {
"users": {
"terms": {
"field": "user",
"size": 10
}
},
"order_count": {
"value_count": {
"field": "order_id"
}
},
"total_order_amt": {
"sum": {
"field": "taxful_total_price"
}
},
"avg_amt_per_order": {
"avg": {
"field": "taxful_total_price"
}
},
"avg_unique_products_per_order": {
"avg": {
"field": "total_unique_products"
}
},
"total_unique_products": {
"cardinality": {
"field": "products.product_id"
}
},
"mah_script": {
"bucket_script": {
"buckets_path": {
"unique": "total_unique_products",
"orders": "order_count"
},
"script": "params.unique/params.orders"
}
}
}
}
}
}
>
"aggregations" : {
"user" : {
"after_key" : {
"user" : "abd",
"customer_id" : "52"
},
"buckets" : [
{
"key" : {
"user" : "abd",
"customer_id" : "52"
},
"doc_count" : 188,
"total_order_amt" : {
"value" : 17830.453125
},
"order_count" : {
"value" : 188
},
"total_unique_products" : {
"value" : 474
},
"avg_unique_products_per_order" : {
"value" : 2.6914893617021276
},
"avg_amt_per_order" : {
"value" : 94.8428357712766
},
"users" : {
"doc_count_error_upper_bound" : 0,
"sum_other_doc_count" : 0,
"buckets" : [
{
"key" : "abd",
"doc_count" : 188
}
]
},
"mah_script" : {
"value" : 2.521276595744681
}
}
]
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment